How to
Get CMS menu
Retrieve a CMS menu from a specific location using Geins Merchant API
Prerequisites
- Merchant API key
- Menu location ID
Goal
- Fetch the menu tree for a given menu location
Architecture at a glance
- Call
getMenuAtLocationwithmenuLocationId→ Receive a menu with nested items
Example
Use the getMenuAtLocation query to fetch a menu and its nested items.
Try it out in the GraphQL Playground using the query, headers and variables below.
Request example
query getMenuAtLocation(
$menuLocationId: String!
$channelId: String
$languageId: String
$marketId: String
) {
getMenuAtLocation(
menuLocationId: $menuLocationId
channelId: $channelId
languageId: $languageId
marketId: $marketId
) {
id
name
title
menuItems {
id
label
title
canonicalUrl
targetBlank
type
order
hidden
children {
id
label
canonicalUrl
children {
id
label
canonicalUrl
}
}
}
}
}
{
"Accept": "application/json",
"X-ApiKey": "{MERCHANT_API_KEY}"
}
{
"menuLocationId": "{MENU_LOCATION_ID}",
"channelId": "{CHANNEL_ID}",
"languageId": "{LANGUAGE_ID}",
"marketId": "{MARKET_ID}"
}
curl -X POST https://merchantapi.geins.io/graphql \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "X-ApiKey: {MERCHANT_API_KEY}" \
-d '{"query":"query getMenuAtLocation($menuLocationId: String!, $channelId: String, $languageId: String, $marketId: String) { getMenuAtLocation(menuLocationId: $menuLocationId, channelId: $channelId, languageId: $languageId, marketId: $marketId) { id name title menuItems { id label title canonicalUrl targetBlank type order hidden children { id label canonicalUrl children { id label canonicalUrl } } } } }","variables":{"menuLocationId":"{MENU_LOCATION_ID}","channelId":"{CHANNEL_ID}","languageId":"{LANGUAGE_ID}","marketId":"{MARKET_ID}"}}'
The
channelId, languageId, and marketId arguments are optional and can be left out to use default values.Response example
200 OKresponse.json
{
"data": {
"getMenuAtLocation": {
"id": "main-menu",
"name": "Main",
"title": "Main navigation",
"menuItems": [
{
"id": "home",
"label": "Home",
"canonicalUrl": "/",
"children": []
},
{
"id": "news",
"label": "News",
"canonicalUrl": "/new-in",
"children": [
{ "id": "shoes", "label": "Shoes", "canonicalUrl": "/c/shoes" }
...
]
}
...
]
}
}
}
Options
Channel, Language, and Market
The query also supports optional parameters for multi-market support:
Read more about
channelId, languageId, and marketId in the "how to"-article about using multi-market support.Authenticated access
While authentication is not required for this query, including a JWT bearer token in the Authorization header can provide personalized results based on the authenticated user's context, for example personalized or restricted content.
To include authentication, add the JWT bearer token to your request headers:
"Authorization": "Bearer {JWT_TOKEN}"
Read more about obtaining and using JWT tokens in the guide about the authentication flow.
Related
Get CMS areaGet CMS menuGet CMS pageGet list of CMS pagesPreview CMS contentUse CMS area filtersUse multi-market supportGetMenuAtLocation