Context IDs in Sitecore XM Cloud: A Practical Approach for Developers

Context IDs in Sitecore XM Cloud: A Practical Approach for Developers

In Sitecore XM Cloud, the Context ID is a pivotal environment variable that streamlines the setup and configuration of your solutions. Serving as a unified identifier, it maps to all your configured resources—including content, sites, files, forms, and integration settings—thereby simplifying the development process.


Understanding Context IDs

When you create an environment in XM Cloud, two context identifiers are generated automatically:

? Live Context ID: Provides access to content published to Experience Edge using the Delivery API. This is intended for production sites.

? Preview Context ID: Grants access to all content, including drafts and unapproved items in your XM Cloud environment, via the Preview API.

These identifiers are essential for connecting your applications to the appropriate content sources, ensuring that your development and production environments function seamlessly.


Experience Edge Data Flow


Retrieving Your Context IDs

To obtain your Context IDs:

1. Navigate to the XM Cloud Deploy app.

2. In the Projects tab, locate the Environments table for your project.

3. Copy the desired Context ID—either Context ID (Preview) or Context ID (Live).

Alternatively, you can find these IDs in the Environment details or Developer settings tabs of the XM Cloud Deploy app.


Testing Your Endpoint

When it comes to testing the content retrieved from your endpoint, using tools like Postman or similar API clients is the most straightforward approach. While GraphQL Playground is a powerful tool for interacting with GraphQL APIs, it may not always support specific use cases or configurations relevant to your setup. Here’s a clear guide to effectively test your endpoint:

  1. Select POST as the request type. Enter the URL of Experience Edge endpoint in the request URL field: https://edge-platform.sitecorecloud.io/v1/content/api/graphql/v1
  2. In URL field add sitecoreContextId query string parameter with corresponding Context ID value.
  3. Compose the GraphQL Query: In the request body, choose the GraphQL option and enter your GraphQL query.
  4. Send the request

Finally, you should have something similar as the following:

Sitecore Experience Edge GraphQL request


Regenerating a Context ID

If you need to regenerate a Context ID—perhaps due to unauthorized access—you can do so through the XM Cloud Deploy app:

1. In the Environment details tab, click Regenerate.

2. In the dialog box, copy and save your current Context IDs.

3. Click Regenerate to obtain new Context IDs.


Implementing Context IDs in your NEXT.JS rendering app:

Incorporating the Context ID into your environment is straightforward and requires setting up the environment variables only:

In your application’s environment configuration file (commonly .env.local), assign the Context ID to the SITECORE_EDGE_CONTEXT_ID variable. Define the SITECORE_SITE_NAME variable with the name of your site or keep it empty in case of using Multisite Add-on.

By effectively utilizing Context IDs, developers can ensure a streamlined and efficient workflow within the Sitecore XM Cloud ecosystem.



要查看或添加评论,请登录

Artsem Prashkovich的更多文章

社区洞察

其他会员也浏览了