how to create scripted Rest API for get groups Azure AD to servicenow?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2023 11:53 PM
Hi All,
I'm new to scripted rest API please tell me the how to get all group from Azure AD to ServiceNow group table. Need to schedule this Rest API daily. this is my code
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var groupName = request.queryParams.groupName;
var accessToken = "2TV8Q~ebRev4seDvIbF_um2MPy4rA1SaPC02edu~";
var url = "https://graph.windows.net/5d6940d8-b4e9-4e29-a17a-73efc56effba/groups/" + groupName + "?api-version=1.6";
var headers = {
"Authorization": "Bearer " + accessToken
};
var response1 = null;
// Make a GET request to the Azure AD Graph API to retrieve the group information
try {
var gr = new sn_ws.RESTMessageV2();
gr.setHttpMethod('GET');
gr.setEndpoint(url);
gr.setRequestHeader("Authorization", "Bearer " + accessToken);
var response2 = gr.execute();
var responseBody = response.getBody();
var parsedResponse = JSON.parse(responseBody);
// Store the group information in ServiceNow
/* var groupRecord = new GlideRecord('<your ServiceNow table name>');
groupRecord.initialize();
groupRecord.setValue('name', parsedResponse.displayName);
groupRecord.setValue('description', parsedResponse.description);
groupRecord.setValue('email', parsedResponse.mail);
groupRecord.setValue('azure_id', parsedResponse.objectId);
groupRecord.setValue('members', parsedResponse.members);
groupRecord.insert(); */
gs.log("HIIIIIIIIIIIIIIIIIIIIIIIIiiiiiii");
// Return the response to the client
return responseBody;
} catch (ex) {
// Handle any errors that occur
gs.log(ex.message);
return response;
}
})(request, response);