---
title: "Authorization and API access"
slug: "authorization-and-api-access"
abstract: "Overview of authorization methods and access options for the Preview GraphQL API, Delivery GraphQL API, Token REST API, and Admin REST API."
---
# Authorization and API access

This topic describes the various authorization and access options for Experience Edge APIs.

## Authorize requests to the GraphQL APIs

There are three ways to access the Preview GraphQL API and the Delivery GraphQL API:

- *GraphQL IDE* - the GraphQL IDE (GraphQL Playground) is the recommended tool for exploring and testing queries during development. Using it helps you understand the response structure and efficiently debug your front-end code. You authorize requests in the IDE using an API token generated directly in SitecoreAI Deploy. For step-by-step instructions, see [Set up the GraphQL IDEs](https://doc.sitecore.com/sai/en/developers/sitecoreai/experience-edge/experience-edge-apis/set-up-the-graphql-ides.html "Set up the GraphQL IDEs").
- *Front-end app* - in your front-end app, we recommend you use the same endpoint for both the Preview GraphQL API and the Delivery GraphQL API, and use [Context IDs](https://doc.sitecore.com/sai/en/developers/sitecoreai/deploying-sitecoreai/deploy-app/manage-an-environment/context-id-environment-variables.html) rather than an API token to authorize requests. You use the Preview Context ID for the Preview GraphQL API, and the Live Context ID for the Delivery GraphQL API.

    There are two main reasons we recommend using this approach for modern development: first, it's simpler to set up and maintain than the *direct API access* approach. Second, following this approach, you switch between the Preview GraphQL API and the Delivery GraphQL API by switching Context IDs. You don't need to modify the endpoint or any other part of the request.

    > [!important]
    > [Avoid](https://doc.sitecore.com/sai/en/developers/sitecoreai/experience-edge/experience-edge-best-practices.html#avoid-exposing-your-context-id-to-the-browser) exposing your Context IDs to the browser.

- *Direct API access* - as an alternative to the approach recommended for front-end development, you could make direct API requests using the native API endpoints and authorization methods. In this scenario, you authorize requests using the same API tokens used in the GraphQL IDEs.

### Preview GraphQL API

Here's an overview of the URLs and authorization requirements for the three ways to access the [Preview GraphQL API](https://doc.sitecore.com/sai/en/developers/sitecoreai/experience-edge/experience-edge-apis/preview-graphql-api.html "Preview GraphQL API"). The environment host name, API token, and Context ID are accessible in SitecoreAI Deploy.

::::tabs
:::tab{title="GraphQL IDE"}
Access the IDE for the Preview GraphQL API at the following URL:

`https://<YOUR_ENVIRONMENT_HOST_NAME>/sitecore/api/graph/edge/ide/`

To authorize requests, include the Preview API token in the header of every API request:

`{ "sc_apikey": "<PREVIEW_API_TOKEN>" }`

:::
:::tab{title="Front-end app"}

Here's an example cURL call that shows how to make requests to the Preview GraphQL API from your front-end app:

```curl
curl -X POST 'https://edge-platform.sitecorecloud.io/v1/content/api/graphql/v1' \
--header 'x-sitecore-contextid: <PREVIEW_CONTEXT_ID>' \
--header 'Content-Type: application/json' \
--data-raw '{<GRAPHQL_QUERY>}'
```

Note the following:

- In your front-end app, make requests to both the Preview GraphQL and the Delivery GraphQL API using the same endpoint:

    `https://edge-platform.sitecorecloud.io/v1/content/api/graphql/v1`

- To authorize requests, include the Preview Context ID in the header of every API request:

    `x-sitecore-contextid: <PREVIEW_CONTEXT_ID>`

:::
:::tab{title="Direct API access"}

Here's an example cURL call for accessing the Preview GraphQL API directly:

```curl
curl -X POST 'https://<YOUR_ENVIRONMENT_HOST_NAME>/sitecore/api/graph/edge' \
--header 'sc_apikey: <PREVIEW_API_TOKEN>' \
--header 'Content-Type: application/json' \
--header 'Cookie: shell#lang=en' \
--data-raw '{<GRAPHQL_QUERY>}'
```

Note the following:

- The base URL for accessing the Preview GraphQL API directly:

    `https://<YOUR_ENVIRONMENT_HOST_NAME>/sitecore/api/graph/edge`

- The endpoint for querying the Preview GraphQL API:

    `POST https://<YOUR_ENVIRONMENT_HOST_NAME>/sitecore/api/graph/edge`

- To authorize requests, include the Preview API token in the header of every API request:

    `{ "sc_apikey": "<PREVIEW_API_TOKEN>" }`

:::
::::

### Delivery GraphQL API

Here's an overview of the URLs and authorization requirements for the three ways to access the [Delivery GraphQL API](https://doc.sitecore.com/sai/en/developers/sitecoreai/experience-edge/experience-edge-apis/delivery-graphql-api.html "Delivery GraphQL API"). The API token and Context ID are accessible in SitecoreAI Deploy.

::::tabs
:::tab{title="GraphQL IDE"}

Access the IDE for the Delivery GraphQL API at the following URL:

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

To authorize requests, include the Delivery API token in the header of every API request:

`{ "sc_apikey": "<DELIVERY_API_TOKEN>" }`

:::
:::tab{title="Front-end app"}

Here's an example cURL call that shows how to make requests to the Delivery GraphQL API from your front-end app:

```curl
curl -X POST 'https://edge-platform.sitecorecloud.io/v1/content/api/graphql/v1' \
--header 'x-sitecore-contextid: <LIVE_CONTEXT_ID>' \
--header 'Content-Type: application/json' \
--data-raw '{<GRAPHQL_QUERY>}'
```

Note the following:

- In your front-end app, make requests to both the Preview GraphQL and the Delivery GraphQL API using the same endpoint:

    `https://edge-platform.sitecorecloud.io/v1/content/api/graphql/v1`

- To authorize requests, include the Delivery Context ID in the header of every API request:

    `x-sitecore-contextid: <LIVE_CONTEXT_ID>`

:::
:::tab{title="Direct API access"}

Here's an example cURL call for accessing the Delivery GraphQL API directly:

```curl
curl -X POST 'https://edge.sitecorecloud.io/api/graphql/v1' \
--header 'sc_apikey: <DELIVERY_API_TOKEN>' \
--header 'Content-Type: application/json' \
--header 'Cookie: shell#lang=en' \
--data-raw '{<GRAPHQL_QUERY>}'
```

Note the following:

- The base URL for accessing the Delivery GraphQL API directly:

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

- The endpoint for querying the Delivery GraphQL API is `/v1`:

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

- To authorize requests, include the Delivery API token in the header of every API request:

    `{ "sc_apikey": "<DELIVERY_API_TOKEN>" }`

:::
::::

## Authorize requests to the Admin REST API and the Token REST API

Here's an example cURL call for accessing the [Admin REST API](https://doc.sitecore.com/sai/en/developers/sitecoreai/experience-edge/experience-edge-apis/admin-rest-api.html "Admin REST API"):

```curl
curl -X GET 'https://edge.sitecorecloud.io/api/admin/v1/<ENDPOINT>' \
--header 'Authorization: Bearer <JSON_WEB_TOKEN>'
```

Here's an example cURL call for accessing the [Token REST API](https://doc.sitecore.com/sai/en/developers/sitecoreai/experience-edge/experience-edge-apis/token-rest-api.html "Token REST API"):

```curl
curl -X GET 'https://edge.sitecorecloud.io/api/apikey/v1' \
--header 'Authorization: Bearer <JSON_WEB_TOKEN>'
```

Note the following:

- The base URL for the Admin REST API:

    `https://edge.sitecorecloud.io/api/admin/v1`

- The base URL for the Token REST API:

    `https://edge.sitecorecloud.io/api/apikey/v1`

- The Admin REST API and the Token REST API both use bearer authorization with a JSON web token (JWT). To authorize API requests:
    1. [Create an Edge administration client for your environment](https://doc.sitecore.com/sai/en/developers/sitecoreai/deploying-sitecoreai/deploy-app/managing-sitecoreai-client-credentials/manage-client-credentials-for-a-sitecoreai-organization-or-environment.html) in SitecoreAI Deploy. This generates a client ID and client secret.
    2. [Create a JSON web token](https://doc.sitecore.com/sai/en/developers/sitecoreai/experience-edge/experience-edge-apis/authorization-and-api-access/create-a-json-web-token-for-experience-edge-apis.html "Create a JSON web token for Experience Edge APIs") 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. Include the JWT in the header of every API request you make:

        `Authorization: Bearer <JSON_WEB_TOKEN>`

## Programmatically create Delivery GraphQL API tokens

The recommended way to authorize requests to the Delivery GraphQL API is by using a Context ID in your front-end app or an API token in the GraphQL IDE. The simplest way to get an API token is to generate it in SitecoreAI Deploy, on the **Details** tab of your environment.

Alternatively, you can [create Delivery GraphQL API tokens programmatically](https://doc.sitecore.com/sai/en/developers/sitecoreai/experience-edge/experience-edge-apis/authorization-and-api-access/generate-a-delivery-graphql-api-token.html), using either the Deploy REST API or the Token REST API. These methods are not available for the Preview GraphQL API.

The API tokens you programmatically generate can be used the same way as the ones you create in SitecoreAI Deploy.
