Hello Daniel,
it is possible to get all deployments of a project via Service Broker API call.
The following code contains a preparation and to get the token for the API call. Last but not least the API call /deployment/api/deployments itself. Please note that the call contains a filter with the projectID [filter=projectID eq 'f77f5d6e-ba20-469b-b56a-172c97e2c1f7'. The special characters have been masked, e.g. a space with %20.
var httpRestHost = RESTHostManager.createTransientHostFrom(
RESTHostManager.createHost("dynamicRequest")
);
httpRestHost.url = url; // vCO URL as string input
// Get the token for API call
var login = JSON.stringify({
"username": username, // User name as string input
"password": password // Password as SecureString input
});
var request = httpRestHost.createRequest(
"POST", "/csp/gateway/am/api/login?access_token", login
);
request.contentType = "application/json";
var response = request.execute();
var refreshToken = "{\"refreshToken\":\"" +
JSON.parse(response.contentAsString).refresh_token + "\"}";
request = httpRestHost.createRequest(
"POST", "/iaas/api/login", refreshToken
);
request.contentType = "application/json";
response = request.execute();
var accessToken = JSON.parse(response.contentAsString).token;
// Get all deployments of a project via Service Broker API call
var request = httpRestHost.createRequest(
"GET", "/deployment/api/deployments?size=999&" +
"$filter=projectId%20eq%20%27f77f5d6e-ba20-469b-b56a-172c97e2c1f7%27"
);
request.setHeader("Content-Type", "application/json");
request.setHeader("Accept", "application/json");
request.setHeader("Authorization", "Bearer " + accessToken);
var response = request.execute();
System.log(response.contentAsString);
return JSON.parse(response.contentAsString);
On this was you can get all deployments of a project. If there are too many deployments, here in this example I use a maximum size of 999, you must install paging.
Best regards
Stefan
------------------------------
More interesting information at
https://blog.stschnell.de------------------------------
Original Message:
Sent: Sep 25, 2024 09:49 AM
From: Cashi
Subject: How to get all Deployments of a Project with Javascript
Hi,
i need to get the deployments or at least the number of deployments of a project in javascript.
Cant find a solution.
Thanks, Daniel