Walkthrough: Enabling and authorizing requests to the Authoring and Management API
You can explore the Authoring and Management API through HTTP requests. Querying the GraphQL Authoring and Management API programmatically requires authorization.
This walkthrough describes how to:
- Enable GraphQL
- Obtain an access token
- Authorize HTTP requests
Enable GraphQL
Before using GraphQL, you must enable it in your settings.
To enable GraphQL:
-
In a Sitecore configuration patch file, add the following setting:
Obtain an access token
To authorize HTTP requests to perform operations against the Authoring and Management API endpoint, you must obtain an access token.
To obtain an access token:
- Configure a controller that retrieves a Bearer type access token from the Sitecore Identity Server.
- Navigate to the controller in a browser. If authentication is successful, the access token is displayed on the page.
- Copy the
Access tokenvalue.
Authorize HTTP requests
All HTTP requests to the Authoring and Management API endpoint must be authorized. Tools like Postman or Insomnia can be used to send and validate these requests
To authorize your HTTP requests:
-
Add the HTTP
Authorizationheader with theBearerauthentication scheme to your request headers. Replace the<access-token>placeholder with the value of the access token. For example: -
To test the authorization for your HTTP request, verify your setup by running a query. For example:
Bearer token for local API discovery
As an alternative for local development and API discovery, you can obtain a bearer token without creating a custom application by configuring a lightweight OAuth client in Sitecore Identity Server and requesting a token directly from the /connect/token endpoint.
This approach is commonly used with tools such as Postman, curl, or PowerShell to enable quick experimentation with the Authoring and Management API or GraphQL Playground.
This approach requires changes to Sitecore Identity Server configuration and may involve grant types intended for development or testing only. It is not recommended for production environments.
For production scenarios, use the application-based authorization flow described earlier in this topic.
At a high level, this approach involves:
-
Adding a client configuration to Sitecore Identity Server with the required API scopes
-
Requesting an access token from:
-
Supplying the returned access token as a bearer token in API requests:
This option is intended to reduce friction for local exploration and troubleshooting only.