In Microsoft Graph Service SDK 6, how do I retrieve the User's Custom Attribute?

Kevin Guan 25 Reputation points
2024-04-05T17:40:42.15+00:00

As of Microsoft Graph SDK 5, the way I retrieved a User's custom attribute information was the following:

final var attribute = graphClient.users("Some_Azure_ID").buildRequest().select("Some_Custom_Attribute").get();

I have upgraded to Microsoft Graph SDK 6 and the above code no longer works to fetch the User's Custom Attribute.

The closest I see relating to custom attributes is the below code, but all returns null.

// These return null, but expected as I dont expect the Custom Attribute to be there
final var attribute1 = graphClient.users().byUserId("Some_Azure_ID").get().getCustomSecurityAttributes();
final var attribute2 = graphClient.users().byUserId("Some_Azure_ID").get().getOnPremisesExtensionAttributes();


// This returns all the built in values, none of the custom values
// When I replace the * with extension_extensionId_customAttributeName, I get an error message saying value not found
final var data = patientGraphClient.users().byUserId(azureId).get( requestConfiguration -> {
    requestConfiguration.queryParameters.select = new String[] {"*"};
});

What is the correct way to fetch a User's Custom attribute in Microsoft Graph SDK 6?

Here is an example attribute, 'ba', that I created to try to retrieve via Graph Service, image below:

Screenshot 2024-04-05 140730

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,821 questions
{count} vote