1. Authorization and API access

Generate a Delivery GraphQL API token

Generating an API token for the Delivery GraphQL API is required for authorizing requests when using the GraphQL IDE. This topic describes all the methods to generate a Delivery GraphQL API token.

Note that the recommended way to authorize requests to the Delivery GraphQL API in your front-end app is to use a Context ID rather than an API token. See Authorization and API access for all options.

Generate an API token in SitecoreAI Deploy

The simplest way to get a Delivery GraphQL API token is to generate it in SitecoreAI Deploy, on the Details tab of your environment.

To generate a Delivery GraphQL API token in SitecoreAI Deploy:

  1. On the navigation pane of the Deploy app, click Projects.

  2. On the Projects page, click the project that contains the environment where you want to generate an API token.

  3. On the project page, click the environment you want.

  4. On the environment page, click the Details tab > Generate Delivery API token.

    Tip

    On the Details tab, you can also generate an API token for the Preview GraphQL API.

  5. Review when and how to use the API token.

Generate an API token using the Deploy REST API

As an alternative to SitecoreAI Deploy, you can use the Deploy REST API to programmatically generate tokens for the Delivery GraphQL API.

To generate a Delivery GraphQL API token using the Deploy REST API:

  1. Create an organization automation client or an automation client for your environment. This generates a client ID and client secret.

  2. Create a JSON web token for the Deploy REST API. In the response, the access_token value is your access token.

  3. In SitecoreAI Deploy, on the Details tab of the environment where you want to create a Delivery GraphQL API token, get the environment ID.

  4. Run the following cURL command, replacing the placeholder values with your environment ID and access token:

    curl
    curl -X GET 'https://xmclouddeploy-api.sitecorecloud.io/api/environments/v1/<YOUR_ENVIRONMENT_ID>/obtain-edge-token' \
    -H 'Accept: text/plain' \
    -H 'Authorization: Bearer <YOUR_ACCESS_TOKEN>'
    XM Cloud is now SitecoreAI

    Some code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.

    In the response, the apiKey value is your Delivery GraphQL API token.

  5. Review when and how to use the API token.

Generate an API token using the Token REST API

As an alternative to SitecoreAI Deploy, you can use the Token REST API to programmatically generate tokens for the Delivery GraphQL API.

To generate a Delivery GraphQL API token using the Token REST API:

  1. Create an Edge administration client for your environment in SitecoreAI Deploy. This generates a client ID and client secret.
  2. Create a JSON web token using the client ID and client secret. This generates a JWT. JSON web tokens expire after 24 hours. After expiry, request a new one.
  3. Using the JWT in the Token REST API Create endpoint, generate a Delivery GraphQL API token.
  4. Review when and how to use the API token.
If you have suggestions for improving this article, let us know!