Integration of Azure AD with ServiceNow for Retrieving User Records via REST Graph API

Naveen Bagula
Tera Contributor

We have successfully integrated Azure Active Directory (Azure AD) with ServiceNow to retrieve user records using the REST Graph API. However, we encountered an issue where the API response is limited to 100 (max 900) records when performing a GET operation with the following endpoint:

Additionally, when we use the $top parameter in the endpoint, it brings a maximum of 999 records:

Our goal is to retrieve all user records from Azure AD and populate them into the ServiceNow user table. Could you please advise on how to obtain the complete set of records in the API response?

 

Just to give more clarity, I have created REST Message and GetUsers method, then using them in the scheduled  script to run everyday get these records into user table

 

 var r = new sn_ws.RESTMessageV2('Graph API', 'GET AllUsers');
 var response = r.execute();
 var responseBody = response.getBody();
 var httpStatus = response.getStatusCode();

 var obj = JSON.parse(responseBody);
 for (var i=0; i<= obj.value.length; i++){
    var azureUser = new GlideRecord('sys_user');
    azureUser.addQuery('email', obj.value[i].mail);
    azureUser.query();
    if(azureUser.next()){
        azureUser.u_nameFromAzure = obj.value[i].userPrincipalName;
        azureUser.update();
    }
1 ACCEPTED SOLUTION

Nishchitha K S
Tera Guru

Hello @Naveen Bagula ,

 

Please check this community link that I found, if it can help you find a solution for your issue : https://www.servicenow.com/community/developer-forum/ms-graph-api-to-pull-records/m-p/1793498#M45042...

 

 

Please mark as helpful/solution accepted if the solution did work for you.

Happy learning 🚀 

 

Regards,

  • Nishchitha K S

View solution in original post

1 REPLY 1

Nishchitha K S
Tera Guru

Hello @Naveen Bagula ,

 

Please check this community link that I found, if it can help you find a solution for your issue : https://www.servicenow.com/community/developer-forum/ms-graph-api-to-pull-records/m-p/1793498#M45042...

 

 

Please mark as helpful/solution accepted if the solution did work for you.

Happy learning 🚀 

 

Regards,

  • Nishchitha K S