In this article we will go through the real life use case (based on my experience while working on the XM Cloud project) to see how we can use the Admin API for the Experience Edge for XM or XM Cloud.
Problem
In the XM Cloud project, we have two websites with dedicated content but common look and feel with different color for each website. During initial setup we created the partial designs and pages designs in the Shared site by following the SXA guidelines.
During the course of development work, we needed to move the partial designs and pages designs from Shared site to the dedicated websites. We restructured the presentation items and did all necessary changes on the local system, which looked promising during the unit testing.
However, once we deployed it to our QA environment, we found some weird behavior for our websites. After publishing the changes and content for several times, we were not able to get the changes applied as expected.
Then we started to look for the ways to clear the cache for the Experience Edge and using the Experience Edge for XM APIs we were able to fix the issue.
In this article, I’m going to explain how we did setup the APIs, authentication and how we used them to fix our issue.
Solution
First let us get some basic idea about the Experience Edge for XM APIs before moving ahead.
The Experience Edge for XM provides the following APIs which can be used for different purposes.
- Delivery API – Using the delivery API we can access the published content for our use on different channels.
- Token API – Using the token API we can generate the API keys to execute the delivery API.
- Admin API – The admin API allows us to manage and administer the Edge tenant.
We are going to discuss and learn the admin API in detail for using them.
The admin APIs are the REST API endpoints which allow us to administer the Experience Edge for XM tenants.
We used the clear cache for tenant endpoint (/cache) to clear the Experience Edge cached content for the given tenant.
However, when we checked for the issue, it was still there. Then we used the delete content endpoint (/content) to clear the tenant data from the data store.
Refer the below video for hands on demo of the Admin APIs.
After clearing the tenant data from the data store, we published all the Sitecore items. After publishing the content, we found that our issue fixed with appropriate content visible on the website.
Now, let us go step-by-step for setting up the admin API through the postman.
Open the postman application. You can download the postman application from here.
First we need to generate the authentication token before accessing the administration API.
To generate the token we need the client id and client secret which we can generate from the XM Cloud Deploy app.
You can go to the XM Cloud Deploy app of your organization and then navigate to the Credentials page.
On the Credentials page you can see two tabs, one for Organization and another for Environment.
The organization level client credentials can do anything across the organization and hence I do not recommend to use them for the purpose of clearing the Experience Edge tenant data and cache.
So, we will create the Environment credentials which are specific to the particular environment.
So, if you want to clear the Experience Edge tenant data for the Dev environment, you must create credentials for that environment only.
On the Environment tab, click on the Create Credentials button and choose Edge administration.
In the dialog, fill the necessary fields Label and Description.
The select the project you are working on and then select the environment for which you want to generate the credentials.
Once all the fields are filled, click Create button.
Make a note of the Client ID and Client secret before closing the dialog, otherwise you have to generate a new credential as client secret original value will not be available once the dialog is closed.
Now, go back to the postman and prepare your request as shown in the below screenshot.
Execute the request to generate the access token.
If you have performed all the steps correctly, then you will get the access token in the response.
Now open a new tab to create the new request for clearing the cache as shown in the below screenshots. Use the generated access token to pass in the request headers with Authorization key and value as Bearer token.
Execute the request to clear the cache.
Now use the same process to call the clear content from the tenant data store so you can republish everything for that environment. The following is the request example to clear the tenant data from the store.
When you clear the content from the tenant data store, it will NOT remove any content from the CMS.
So, that’s it! I hope this guide will help you to fix your content caching issue with the Experience Edge for XM Cloud.