Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read b2c extension attribute using Graph API in C#

We are using the Graph API in C# to read data from AD about users setup in B2C.

We have a number of extension attributes setup in the b2c environment, and we want to be able to read the values of these attributes for users in our C# application.

We can make a successful request to get details on the user using:

graphServiceClient.Users[userId].Request().Select("id,displayName").GetAsync();

Which returns the details on the attributes specified.

However, we can't find an option for getting the extension attribute values back with this request. We have included the name of the attribute using the guid of the application storing the attributes, but the attributes are not returned.

We have also tried the following request, which returns the response of "Extension with given id not found":

var extensionDetails = graphServiceClient.Users[userId].Extensions["extension_{guidWithDashesRemoved}_{attributeName}"].Request().GetAsync();

We are able to do this successfully in Postman with the following get request:

https://graph.microsoft.com/v1.0/users?$select=id,displayName,givenName,postalCode,extension_{guidWithDashesRemoved}_{attributeName}

Has anyone been able to get the extension attribute values back?

like image 200
penguin178 Avatar asked Oct 22 '25 13:10

penguin178


1 Answers

The first code is correct. You need to add the extension property into the select query parameter.

var user = await graphServiceClient.Users[userId]
    .Request()
    .Select("id,extension_{guidWithDashesRemoved}_{attributeName},displayName")
    .GetAsync();
like image 66
Allen Wu Avatar answered Oct 25 '25 02:10

Allen Wu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!