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.
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.
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.
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.
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.
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