You can try something like this, good luck.
var request = myresthostmgmt.createRequest("GET","/subscriptions?api-version=2022-09-01"); //Get subscription.
request.setHeader("Accept","application/json");
request.setHeader("Authorization", "Bearer " + token);
var subscriptionInfo = request.execute();
var jsonlist = JSON.parse(subscriptionInfo.contentAsString);
availableSubscriptions = new Array();
var propnum = 0;
for (var indx in jsonlist.value) {
var subscriptionList = (jsonlist.value[propnum].displayName);
availableSubscriptions.push(subscriptionList);
propnum = propnum + 1;
}
return availableSubscriptions;
Original Message:
Sent: Jul 24, 2024 06:07 AM
From: jeep2004
Subject: rest API to Azure management with VRA
hi
need help to take info about Azure environment
I write a code that workd fine to get token ( you can enjoy the code ) :)
function getAzureADToken() { var url = restHost.url + "/xxxyxyxyxyxyxyxyxyxyxyyxyxyxyxyxyxy/oauth2/token"; System.log("URL: " + url); var headers = { 'Content-Type': 'application/x-www-form-urlencoded' }; // Use a fixed body string if the values are known in advance var body = 'grant_type=' + grant_type + '&client_id=' + client_id + '&client_secret=' + client_secret + '&resource=' + resource; // Create a POST request var req = restHost.createRequest("POST", url, body); req.setHeader("Content-Type", headers['Content-Type']); // Execute the request var res = req.execute(); System.log("Response Status Code: " + res.statusCode); var responseBody = res.contentAsString; // System.log("Response Body: " + responseBody); var parsedResponse = JSON.parse(responseBody); var accessToken = parsedResponse.access_token; // System.log("Access Token: " + accessToken); // Return the access token return accessToken;}var authToken = "Bearer " + getAzureADToken();System.log("Stored Access Token: " + authToken);
now after I have the autoToken
I need to access some of information
from this web site
Subscriptions - List - REST API (Azure Resource Management)
Microsoft | remove preview |
| Subscriptions - List - REST API (Azure Resource Management) | Learn more about Resource Management service - Gets all subscriptions for a tenant. | View this on Microsoft > |
|
|
need help to create a Javascript code
to respond to the body
thank you