Microsoft Graph extensionAttributes are null

Vika
Tera Contributor

Hi there,

 

We are trying to update Locations, Departments and some other data from the Azure AD in ServiceNow via the Microsoft Graph connection. The connection itself is there and we are successfully getting the "Bearer" token.

But when we try to GET the list of Users with extensionAttributes the response is:

{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users(id,displayName,onPremisesExtensionAttributes)","@odata.nextLink":"https://graph.microsoft.com/v1.0/users?$select=id%2cdisplayName%2conPremisesExtensionAttributes&$ski...","value":[{"id":"9f2d5369-a190-45f0-bbaa-d793be8f4572","displayName":"1019428261","onPremisesExtensionAttributes":{"extensionAttribute1":null,"extensionAttribute2":null,"extensionAttribute3":null,"extensionAttribute4":null,"extensionAttribute5":null,"extensionAttribute6":null,"extensionAttribute7":null,"extensionAttribute8":null,"extensionAttribute9":null,"extensionAttribute10":null,"extensionAttribute11":null,"extensionAttribute12":null,"extensionAttribute13":null,"extensionAttribute14":null,"extensionAttribute15":null}},{"id":"c79d169d-99cc-46ad-ab4d-31b223f50534","displayName":"1050020239","onPremisesExtensionAttributes":{"extensionAttribute1":null,"extensionAttribute2":null,"extensionAttribute3":null,"extensionAttribute4":null,"extensionAttribute5":null,"extensionAttribute6":null,"extensionAttribute7":null,"extensionAttribute8":null,"extensionAttribute9":null,"extensionAttribute10":null,"extensionAttribute11":null,"extensionAttribute12":null,"extensionAttribute13":null,"extensionAttribute14":null,"extensionAttribute15":null}},{"id":"150e7752-cfbf-4ce8-b410-0a7c7303ad13","displayName":"\u9c81\u534e \u5b59","onPremisesExtensionAttributes":{"extensionAttribute1":null,"extensionAttribute2":null,"extensionAttribute3":null,"extensionAttribute4":null,"extensionAttribute5":null,"extensionAttribute6":null,"extensionAttribute7":null,"extensionAttribute8":null,"extensionAttribute9":null,"extensionAttribute10":null,"extensionAttribute11":null,"extensionAttribute12":null,"extensionAttribute13":null,"extensionAttribute14":null,"extensionAttribute15":null}},{"id":"e45c7d5a-b33a-483e-8a2f-b6e96af7cb0d","displayName":"1326kdockx","onPremisesExtensionAttributes":{"extensionAttribute1":null,"extensionAttribute2":null,"extensionAttribute3":null,"extensionAttribute4":null,"extensionAttribute5":null,"extensionAttribute6":null,"extensionAttribute7":null,"extensionAttribute8":null,"extensionAttribute9":null,"extensionAttribute10":null,"extensionAttribute11":null,"extensionAttribute12":null,"extensionAttribute13":null,"extensionAttribute14":null,"extensionAttribute15":null}}, etc.

 

HTTP Status is 200 and Endpoint is https://graph.microsoft.com/v1.0/users?$select=id,displayName,onPremisesExtensionAttributes

 

If we try to read any User, not the list of Users, the extensionAttributes are there.

Permissions given are User.Read.All.

 

Also weird, that we receive back a hundred of Users, not all 17000, but perhaps it's the limitation of the Testing functionality in the REST Message.

 

Any ideas anyone how can we read all Users extensionAttributes ?

3 REPLIES 3

Mark Manders
Mega Patron

Can you check if it will work when you set the permissions to Directory.Read.All?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hello Mark,

 

Thank you for the suggestion. Assigned Directory.Read.All, still the same "null" value.

Vika
Tera Contributor
I assume it was a pagination issue, so created a Flow with a Script Action in it to look for "@odata.nextLink" in the Response Body. Sharing an example below for those who'll face a similar problem:
 
(function execute(inputs, outputs) {

 

var accessToken = inputs.accessToken;
var headers = {
"Authorization": "Bearer " + accessToken,
"Content-Type": "application/json"
};
 
var allUsers = [];
var url = baseUrl;

 

function makeRequest(url) {
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod("GET");
request.setRequestHeader("Authorization", headers["Authorization"]);
request.setRequestHeader("Content-Type", headers["Content-Type"]);
request.setEndpoint(url);

 

try {
var response = request.execute();
return {
status: response.getStatusCode(),
responseBody: response.getBody()
};
} catch (ex) {
gs.error("Error making request: " + ex.message);
return null;
}
}

 

do {
var response = makeRequest(url);
if (response && response.status == '200') {
var responseBody = JSON.parse(response.responseBody);
allUsers = allUsers.concat(responseBody.value.map(function(user) {
return {
userPrincipalName: user.userPrincipalName,
onPremisesExtensionAttributes: user.onPremisesExtensionAttributes
};
}));

 

// Check for @odata.nextLink
if (responseBody['@odata.nextLink']) {
url = responseBody['@odata.nextLink'];
} else {
url = null;
}
} else {
// Handle error
gs.error("Error fetching users: " + response.status + " - " + response.responseBody);
url = null;
}
} while (url);

 

var usersJson = JSON.stringify(allUsers);
var users = JSON.parse(usersJson);
 
users.forEach(function(user) {
 
var extensionAttributes = user.onPremisesExtensionAttributes;
var departmentName = extensionAttributes.extensionAttribute14; //Department
var costCenterName = extensionAttributes.extensionAttribute12; //Cost Center

 

if (departmentName && departmentName !== 'null') {
//could be the same as for Cost Centres below, but I have a huuuuuuge script here due to a special customer setup of the Organisation Data
}
 
if (costCenterName && costCenterName != 'null') {
var grCostCenter = new GlideRecord('cmn_cost_center');
grCostCenter.addQuery('name', costCenterName.toString());
grCostCenter.query();
if (!grCostCenter.next()) {
var costCenterGR = new GlideRecord('cmn_cost_center');
costCenterGR.initialize();
costCenterGR.name = costCenterName;
costCenterGR.insert();
}
}
});

 

})(inputs, outputs);