Steps to Generate Access Token for Authoring API Endpoint in XM Cloud
Hello everyone, In this blog we will understand, how to get access token which is must for interacting with Authoring API endpoint. As we all know, to work with preview endpoint in XM Cloud, we required sc_apikey which we can get from Sitecore. But we cannot use the same when working with Authoring API endpoint. We will require an access token for the same. So follow below steps to implement the same.
Step 1: Login to you XM Cloud Instance and click on XM Cloud Deploy APP.
Step 2: Click on Credentials in left side panel.
Step 3: Click on Create Credentials.A popup will come up. Fill the details as shown in below figure.
Step 4: Another popup will come up which will show you generated client id and client secret.Copy you client secret as will not be accessible once popup us closed.
Step 5: Now we are ready with client id and client secret. It's time to get the access token.Open Powershell in administrator mode and run below command.The placeholder {0} represent the client id and {1} represent client secret.The command will give you the access token which will be used to access edge endpoint.
cmd /c curl --request POST --url "https://auth.sitecorecloud.io/oauth/token" --header "content-type: application/x-www-form-urlencoded" --data audience=https://api.sitecorecloud.io --data grant_type=client_credentials --data client_id={0} --data client_secret={1}
Step 6: Now we are ready access token. Let's open the Authoring API graphql endpoint (https://{3}/sitecore/api/authoring/graphql/playground). Placeholer 3 represent your XM Cloud Domain. See below screenshot.Now you are ready to play with XM Cloud Authoring API.
Errors: GraphQL IDE giving 404 error.
Solution:Navigate to environment variable of your environment and check the current variable value Sitecore_GraphQL_ExposePlayground which should be set to true. Click on ... elipse --> edit variable --> make the value true.Now deploy your environment again.
Thanks for reading. Continue learning. In next part we will see how we can perform mutation query using GraphQL
You can check my other blogs too if interested. Blog Website
References:
- https://doc.sitecore.com/xmc/en/developers/xm-cloud/managing-xm-cloud-client-credentials.html
- https://doc.sitecore.com/xmc/en/developers/xm-cloud/walkthrough--enabling-and-authorizing-requests-to-the-authoring-and-management-api.html
Comments
Post a Comment