Access Layout Service Data Of Published Content on Sitecore Edge in XM Cloud

How to access Layout Service data of published content on Sitecore Edge in Sitecore XM Cloud


Please read below for more information on Layout service or

Directly Navigate to Edge


The Sitecore Layout Service is a Sitecore Headless Services endpoint that exposes Sitecore layout information as structured JavaScript Object Notation (JSON) data.


If you have worked with headless implementation before, you know that layout service data can be accessed at (also known as Rest Endpoint)


/sitecore/api/layout/render/[config]?item=[path]&sc_lang=[language]&sc_apikey=[key]&tracking=[true|false]&sc_site=[your-site-name]


e.g.,


https://yoursitecoreurl/sitecore/api/layout/render/jss?item=/&sc_apikey=yourapikey&sc_lang=en&sc_site=yoursite



But, we do not have such url for published content when we switch to XM Cloud.


We do not have a Content Delivery environment in XM Cloud(Web Database), instead we have something called Experience Edge.


Experience Edge is a GraphQL API-based service endpoint that allows you to retrieve layout and content, distributed through a CDN, and hosted by Sitecore.

 

Hence we don't have a layout service url for published content, as mentioned above, instead Edge provides us a Delivery API that allows you to access your approved and published content. 


Edge URL


https://edge.sitecorecloud.io/api/graphql


You would need an Edge Token to get data from above endpoint.

There are various ways to obtain Edge Token. Please follow -https://doc.sitecore.com/xmc/en/developers/xm-cloud/generate-an-edge-token.html


In short - navigate to XMDeployApp > Your Project > Your Environment > Details Tab > Live GraphQL IDE (Experience Edge) > Generate Delivery API Token   


Navigate to below url: 

https://edge.sitecorecloud.io/api/graphql/ide


Enter below url in Server URL textbox:

https://edge.sitecorecloud.io/api/graphql/v1


Now run the below Query to get layout data of published content:

query {
  layout(language: "en", routePath: "pathofitem", site: "yoursite") {
    item {
      rendered
    }
  }  
}



I'll be posting more about Sitecore XM Cloud and GraphQL in future posts.

Stay tuned and Keep Learning :)

ArreyNitesh
Email - arreynitesh@gmail.com
Post a Comment (0)
Previous Post Next Post