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:
-
On the navigation pane of the Deploy app, click Projects.
-
On the Projects page, click the project that contains the environment where you want to generate an API token.
-
On the project page, click the environment you want.
-
On the environment page, click the Details tab > Generate Delivery API token.
TipOn the Details tab, you can also generate an API token for the Preview GraphQL API.
-
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:
-
Create an organization automation client or an automation client for your environment. This generates a client ID and client secret.
-
Create a JSON web token for the Deploy REST API. In the response, the
access_tokenvalue is your access token. -
In SitecoreAI Deploy, on the Details tab of the environment where you want to create a Delivery GraphQL API token, get the environment ID.
-
Run the following cURL command, replacing the placeholder values with your environment ID and access token:
curlXM Cloud is now SitecoreAISome code examples, images, and UI labels may still use XM Cloud while engineering assets are being updated.
In the response, the
apiKeyvalue is your Delivery GraphQL API token. -
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:
- Create an Edge administration client for your environment in SitecoreAI Deploy. This generates a client ID and client secret.
- 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.
- Using the JWT in the Token REST API Create endpoint, generate a Delivery GraphQL API token.
- Review when and how to use the API token.