Pages

22 September, 2023

Using the Deploy (REST) API to Manage XM Cloud Projects and Environments

There are three ways you can interact with XM Cloud. Deploy app, CLI and REST API. In this article, we can see how we can interact with XM Cloud projects, environments and deployments. This article is just to give a glimpse of how you can use the deploy API to interact with XM Cloud. There are various API methods by which you can automate the XM cloud related tasks for your projects. 

First of all, various methods of deploy API can be viewed here. https://xmclouddeploy-api.sitecorecloud.io/swagger/index.html. You can import it in your Postman or any other API tools using the swagger json. https://xmclouddeploy-api.sitecorecloud.io/swagger/v1/swagger.json. Please note that this API has all the methods which are being used in the Deploy App. 

Import in Postman

Open Postman, click import and paste the Swagger json and it will help you to get started. 




Obtain Organization Credentials from Deploy Portal

In order to use most of the deploy API methods, we need authorization token. To get token, we need to create/get organization credentials from deploy portal. Please make sure to save the client secret otherwise we cannot retrieve it or we can create it again. 



Even, these credentials can be created using the deploy API but you will need the authorization token which is being used to login to the Sitecore Cloud portal. In case if your organization is using your own SSO for Sitecore Cloud portal, you can leverage the Client ID and Client Secret and generate the auth token and pass it to /api/clients/vi/deploy API and you can generate the credential. 

Used cloud portal auth token and created the XM Cloud Organization credential

We can see the same credential in the Deploy portal. 


Generate JWT token from XM Cloud Organization Credential

In order to generate JWT token, send a POST request to https://auth.sitecorecloud.io/oauth/token with client_id and client_secret and you will receive the access token. You can use this as bearer token for further API requests. 



Create a new XM Cloud Project

Send a POST request to /api/projects/v1 with the bearer token and it will create the project. Project Id can be seen in the response. 


Project created from API can be seen in Deploy portal.

Create Environment in XM Cloud Project

With the project Id from the previous response (or you can get the list of all the project and its properties using /api/projects/v1), you can create a new environment. Send a POST request to /api/projects/v1/:projectId/environments with the name of the environment.


Newly created environment can be seen in the portal


Creating a deployment 

For an environment, a deployment request can be created using /api/environments/v1/:environmentId/deployments. Pass the environment Id from the previous response or retrieve it using /api/projects/v1/:projectId/environments API. 


Deployment request can be seen in the portal. 


This article is just to give a glimpse of how you can use the deploy API to interact with XM Cloud. There are various APIs by which you can automate the XM cloud related tasks for your projects. 

No comments:

Post a Comment

blockquote { margin: 0; } blockquote p { padding: 15px; background: #eee; border-radius: 5px; } blockquote p::before { content: '\201C'; } blockquote p::after { content: '\201D'; }