GraphQL examples
The following are examples of GraphQL queries.
Query recipes title contains Fruitful
Query when content has a recipe title contains Fruitful using recipe_Title_contains: "Fruitful"
:
Request body
query RecipeFruitful {
allM_Content(where: { recipe_Title_contains: "Fruitful" }) {
total
results {
content_Name
__typename
}
}
}
Response
{
"data": {
"allM_Content": {
"total": 3,
"results": [
{
"content_Name": "Fruitful refreshing ginger lemonade",
"__typename": "M_Content_Recipe"
},
{
"content_Name": "Sparkling Punch using Fruitful Orange",
"__typename": "M_Content_Recipe"
},
{
"content_Name": "Fruitful Mocktails",
"__typename": "M_Content_Recipe"
}
]
}
}
}
Query content items for certain taxonomies
Query content items for specific taxonomies showing the total number of blogs, with the title and quote from all blogs.
Request body
query getAllBlogs {
allM_Content_Blog {
total
results {
blog_Title
blog_Quote
}
}
}
Response
{
"data": {
"allM_Content_Blog": {
"total": 6,
"results": [
{
"blog_Title": "Who wants a mimosa!",
"blog_Quote": "<p>Sometimes I put a splash of orange juice in my champagne.</p>"
},
{
"blog_Title": "Nutrition tips blog post",
"blog_Quote": null
},
{
"blog_Title": "Kracht komt van binnenuit",
"blog_Quote": null
},
{
"blog_Title": "Power comes from within",
"blog_Quote": null
},
{
"blog_Title": "Healthful nutrition helps you develop your diet",
"blog_Quote": null
},
{
"blog_Title": "Health Is Happiness",
"blog_Quote": null
}
]
}
}
}
Query content items within a certain content collection
Query content item using id_eq
.
Request body
query getContentInContentCollection {
allM_ContentCollection(where: { id_eq: "Ai-JNhneM024pMItfBeYJQ" }) {
total
results {
id
contentCollectionName
contentCollectionToContent {
__typename
total
results {
content_Name
__typename
}
}
}
}
}
Response
{
"data": {
"allM_ContentCollection": {
"total": 1,
"results": [
{
"id": "Ai-JNhneM024pMItfBeYJQ",
"contentCollectionName": "Fruitful",
"contentCollectionToContent": {
"__typename": "M_ContentList",
"total": 4,
"results": [
{
"content_Name": "Healthy Mimosa blog",
"__typename": "M_Content_Blog"
},
{
"content_Name": "Healthful is the latest Flavorful Brand",
"__typename": "M_Content_Email"
},
{
"content_Name": "Sparkling Punch using Fruitful Orange",
"__typename": "M_Content_Recipe"
},
{
"content_Name": "Power comes from within",
"__typename": "M_Content_Blog"
}
]
}
}
]
}
}
}
Query all variants that have localization of en-US
Query all content, which are variants of original content (m_Content_IsVariant_eq: true
) and have the localization of en-US (m_Localization_ids: "M.Localization.en-US"
).
Request body
query variantIsEnUS {
allM_Content(
where: {
m_Content_IsVariant_eq: true
localizationToContent: { m_Localization_ids: "M.Localization.en-US" }
}
) {
total
results {
id
content_Name
m_Content_IsVariant
localizationToContent {
valueName
}
}
}
}
Response
{
"data": {
"allM_Content": {
"total": 1,
"results": [
{
"id": "iAzTTLtsoEmuGKqBxPuAVg",
"content_Name": "Fruitful Summer 2021 (en-US)",
"m_Content_IsVariant": true,
"localizationToContent": {
"valueName": "en-US"
}
}
]
}
}
}
Query all variants from entities in a campaign
Query all variants from entities in a campaign using the campaign id and the Boolean m_Content_IsVariant_eq: true
to display the variants.
Request body
query campaignVariant {
allM_Content(
where: {
campaignToContent: { m_CMP_Campaign_ids: "M.CMP.Campaign.Summer2018" }
m_Content_IsVariant_eq: true
}
) {
total
results {
id
content_Name
m_Content_IsVariant
}
}
}
Response
{
"data": {
"allM_Content": {
"total": 2,
"results": [
{
"id": "wT5RNeIcQ0SHTORNT1faug",
"content_Name": "Fruitful Summer (it-IT)",
"m_Content_IsVariant": true
},
{
"id": "BDolxU3bGkWMwFJk-s8Idg",
"content_Name": "Fruitful Summer (es-ES)",
"m_Content_IsVariant": true
}
]
}
}
}
Query all variants of a content entity
Query all variants of a content entity using the parent content id and the contentToContentVariant_Children
field to show the variants.
Request body
query allVariantsOfContent {
m_Content(id: "pBxKLsZaQU21-CTu9y0bWw") {
contentToContentVariant_Children {
results {
id
content_Name
__typename
localizationToContent {
valueName
}
}
}
}
}
Response
{
"data": {
"m_Content": {
"contentToContentVariant_Children": {
"results": [
{
"id": "bb_RjQxMS0O9ziQG7EWuog",
"content_Name": "Fruitful Summer (de-DE)",
"__typename": "M_Content_Email",
"localizationToContent": {
"valueName": "de-DE"
}
},
{
"id": "ah1bserorU-CIcDjFb5p-g",
"content_Name": "Fruitful Summer 2021 (en-GB)",
"__typename": "M_Content_Email",
"localizationToContent": {
"valueName": "en-GB"
}
},
{
"id": "iAzTTLtsoEmuGKqBxPuAVg",
"content_Name": "Fruitful Summer 2021 (en-US)",
"__typename": "M_Content_Email",
"localizationToContent": {
"valueName": "en-US"
}
}
]
}
}
}
}
Query draft content items in preview
Query draft content items in preview using m_Content_IsDraft_eq: true
.
Request body
query draftContentPreview {
allM_Content(where: { m_Content_IsDraft_eq: true }) {
total
results {
id
content_Name
m_Content_IsDraft
}
}
}
Response
{
"data": {
"allM_Content": {
"total": 2,
"results": [
{
"id": "Content.WakeUp",
"content_Name": "Everyone Wake Up",
"m_Content_IsDraft": true
},
{
"id": "Content.DevelopingADiet",
"content_Name": "Developing a diet",
"m_Content_IsDraft": true
}
]
}
}
}
Query where there is more than one content version
Query where there is more than one content version using content_NumberOfCreatedVersions_gt: 1
.
Request body
query moreThanOneVersionContent {
allM_Content(where: { content_NumberOfCreatedVersions_gt: 1 }) {
total
results {
id
content_Name
m_Content_IsDraft
content_NumberOfCreatedVersions
content_ApprovedForCreation
}
}
}
Response
{
"data": {
"allM_Content": {
"total": 1,
"results": [
{
"id": "Content.FruitfulGinger",
"content_Name": "Fruitful refreshing ginger lemonade",
"m_Content_IsDraft": false,
"content_NumberOfCreatedVersions": 3,
"content_ApprovedForCreation": null
}
]
}
}
}
Query conditional metadata based on the content type
Query conditional metadata based on content type using interfaces to create a sub-query.
Request body
query draftConteintInPreview {
allM_Content(where: { m_Content_IsDraft_eq: true }) {
total
results {
id
content_Name
...on M_Content_Blog {
blog_Title
blog_Body
}
...on M_Content_Recipe {
recipe_Title
recipe_Ingredients
}
}
}
}
Response
{
"data": {
"allM_Content": {
"total": 2,
"results": [
{
"id": "t0uouuAwqkCYDo6Cfrub3w",
"content_Name": "Summer Mimosa",
"blog_Title": "Who wants a mimosa?!",
"blog_Body": "<p>I do, always! Mimosas are supremely simple bubbly cocktails made with sparkling wine and orange juice. They’re light, fizzy and easy to sip.</p><figure class=\"image\"><img srcset=\"https://stylelabsdemo.com/api/public/content/17d2484d681844c29780547185d53ffd?v=2d1e5a46&t=w320 320w, https://stylelabsdemo.com/api/public/content/17d2484d681844c29780547185d53ffd?v=2d1e5a46&t=w480 480w\" width=\"664\" src=\"https://stylelabsdemo.com/api/public/content/17d2484d681844c29780547185d53ffd?v=2d1e5a46\" alt=\"Mimosa cocktails\"></figure><p>I love ordering mimosas at weekend brunch, and serving them to family and friends on holidays—Easter, Mother’s Day, July 4th, Christmas, you name it. Mimosas liven up wedding showers and baby showers. I bring mimosa supplies to football watch parties, and no one complains. I’ve shared a few variations on mimosas over the years. Today, I’m going to share everything you’ve ever wanted to know about mimosas, plus a basic mimosa recipe and variations. If you haven’t poured your first mimosa yet, you’ll be a mimosa expert by the end of this post! If you’re a seasoned mimosa drinker, I think you’ll find some new tips here, too.</p><p> </p><p><strong>Mimosa Ingredients:</strong></p><p>Classic mimosas require just two ingredients: dry sparkling wine, and orange juice. Some recipes will tell you to add some other alcohol or orange liqueur. Don’t listen to them!</p><p><strong>Sparkling Wine</strong></p><p>The best Champagne for mimosas isn’t actually Champagne. For mimosas, opt for less-expensive Cava or Prosecco. Cava is from Spain and Prosecco is from Italy, but they’re both delicious dry sparkling wines that mix well with juice. Bonus? They’re affordable. A good bottle of Cava or Prosecco will run about $12 to $16. Avoid super cheap sparkling wine, unless you want a headache with your mimosas. Don’t waste your pricy bottle of Champagne on mimosas, since we’re diluting those delicate notes with orange juice.</p><p><strong>Orange Juice</strong></p><p>Cold, fresh orange juice is best for mimosas. If you’re buying orange juice at the store, opt for high-quality such as the Fruitful Orange Juice!</p>"
},
{
"id": "-CVRo6Z7Y02yXEH_rS6y7w",
"content_Name": "Fruitful refreshing ginger lemonade",
"recipe_Title": "Fruitful refreshing ginger lemonade as an alternative to soda",
"recipe_Ingredients": "<p>Ingredients</p><p>3 cups white sugar<br>4 quarts water<br>14 slices fresh ginger root<br>4 cups fresh lemon juice<br>2 lemons, sliced</p>"
}
]
}
}
}
Query urls and relative urls for a certain asset
Query urls
, which output a map of the public links, and relative urls using relativeUrl
.
Request body
query AssetPublicLinks {
m_Asset(id: "asset.toa-heftiba-271805") {
fileName
id
urls
assetToPublicLink {
results {
id
status
relativeUrl
resource
expirationDate
}
}
}{
"data": {
"m_Asset": {
"fileName": "toa-heftiba-271805.jpg",
"id": "asset.toa-heftiba-271805",
"urls": {
"41af2ea3af5c492696fa8f1767ee35de": {
"url": "https://sitecore-test-staging.cloud/api/public/content/41af2ea3af5c492696fa8f1767ee35de?v=9746edf0",
"expiredOn": null,
"resource": "downloadOriginal",
"metadata": {
"filesize": 1.1,
"filesizebytes": "1101428",
"filename": "toa-heftiba-271805.jpg",
"width": "3936",
"height": "2624",
"group": "Images",
"extension": "jpg",
"content_type": "image/jpeg",
"resolution": "3936 2624",
"colorspace": "RGB ",
"megapixels": "10.328064"
}
},
"1ed0813750e348bb82636585d3769fe1": {
"url": "https://sitecore-test-staging.cloud/api/public/content/1ed0813750e348bb82636585d3769fe1?v=4b3ceca5",
"expiredOn": null,
"resource": "preview",
"metadata": {
"width": "1100",
"height": "733",
"content_type": "image/jpeg",
"filesizebytes": "68885"
}
}
},
"assetToPublicLink": {
"results": [
{
"id": "3TErg0azPESlGSMa8tVLKg",
"status": "Completed",
"relativeUrl": "41af2ea3af5c492696fa8f1767ee35de",
"resource": "downloadOriginal",
"expirationDate": null
},
{
"id": "or9hi1PLn0aXqnxQ8npr3w",
"status": "Completed",
"relativeUrl": "1ed0813750e348bb82636585d3769fe1",
"resource": "preview",
"expirationDate": null
}
]
}
}
}
}
Response
{
"data": {
"m_Asset": {
"fileName": "toa-heftiba-271805.jpg",
"id": "asset.toa-heftiba-271805",
"urls": {
"4f4e0ccfab8642009fe9ef321bdaa970": {
"url": "https://sitecore-test-staging.cloud/api/public/content/4f4e0ccfab8642009fe9ef321bdaa970?v=df2e3a60",
"expiredOn": null,
"resource": "downloadOriginal",
"metadata": {
"filesize": 1.1,
"filesizebytes": "1101428",
"filename": "toa-heftiba-271805.jpg",
"width": "3936",
"height": "2624",
"group": "Images",
"extension": "jpg",
"content_type": "image/jpeg",
"resolution": "3936 2624",
"colorspace": "RGB ",
"megapixels": "10.328064"
}
},
"3a497bc29c5741d985839e26cb198422": {
"url": "https://sitecore-test-staging.cloud/api/public/content/3a497bc29c5741d985839e26cb198422?v=0f28452c",
"expiredOn": null,
"resource": "preview",
"metadata": {
"width": "1100",
"height": "733",
"content_type": "image/jpeg",
"filesizebytes": "68885"
}
}
},
"assetToPublicLink": {
"results": [
{
"id": "AKxo6TjtQkKHCjQwNvKlSA",
"status": "Completed",
"relativeUrl": "3a497bc29c5741d985839e26cb198422",
"resource": "preview",
"expirationDate": null
},
{
"id": "nzxMRalDaUeDN0ZThInemg",
"status": "Completed",
"relativeUrl": "4f4e0ccfab8642009fe9ef321bdaa970",
"resource": "downloadOriginal",
"expirationDate": null
}
]
}
}
}
}
Query all assets and display the associated public links
Query all assets using allM_Asset
and display the public links for each asset using urls
.
Request body
{
allM_Asset {
results {
id
urls
}
}
}
Response
{
"data": {
"allM_Asset": {
"results": [
{
"id": "asset.oatmeal.jpg",
"urls": {
"oatmeal": {
"url": "https://sitecore-test-staging.cloud/api/public/content/oatmeal?v=c498d245",
"expiredOn": null,
"resource": "downloadOriginal",
"metadata": {
"filesize": 0.18,
"filesizebytes": "180019",
"filename": "oatmeal.jpg",
"width": "1500",
"height": "575",
"group": "Images",
"extension": "jpg",
"content_type": "image/jpeg",
"resolution": "1500 575",
"colorspace": "sRGB",
"megapixels": "0.8625"
}
}
}
},
{
"id": "asset.fruitful-product-line",
"urls": {}
},
{
"id": "asset.fruitful-hero2",
"urls": {}
},
{
"id": "asset.sara-dubler-769470",
"urls": {
"summersalad": {
"url": "https://sitecore-test-staging.cloud/api/public/content/summersalad?v=78f938b8",
"expiredOn": null,
"resource": "downloadOriginal",
"metadata": {
"filesize": 2.03,
"filesizebytes": "2033543",
"filename": "sara-dubler-769470.jpg",
"width": "3456",
"height": "2304",
"group": "Images",
"extension": "jpg",
"content_type": "image/jpeg",
"resolution": "3456 2304",
"colorspace": "RGB ",
"megapixels": "7.962624"
}
}
}
},
{
"id": "asset.logo-healthful.ai",
"urls": {}
},
{
"id": "asset.fruitful-presentation",
"urls": {
"cf17f452bab44781bd2648f3b08c4083": {
"url": "https://sitecore-test-staging.cloud/api/public/content/cf17f452bab44781bd2648f3b08c4083?v=22521590",
"expiredOn": null,
"resource": "downloadOriginal",
"metadata": {
"filesize": 0.78,
"filesizebytes": "776473",
"filename": "fruitful-presentation-v1.png",
"width": "1920",
"height": "1080",
"group": "Vectors",
"extension": "png",
"content_type": "image/png",
"resolution": "1920 1080",
"colorspace": "RGB ",
"megapixels": "2.0736",
"creator": "Adobe Photoshop CC 2018 (Macintosh)"
}
},
"39d8dd7ae68b4197a501179c8496eae6": {
"url": "https://sitecore-test-staging.cloud/api/public/content/39d8dd7ae68b4197a501179c8496eae6?v=dd800038",
"expiredOn": null,
"resource": "preview",
"metadata": {
"width": "1100",
"height": "619",
"content_type": "image/png",
"filesizebytes": "285321"
}
}
}
}
]
}
}
}
Can we improve this article ? Provide feedback