microsoftgraph / aspnet-snippets-sample

A repository of code snippets that use Microsoft Graph to perform common tasks such as sending email, managing groups, and other activities from an ASP.NET Core MVC app. This sample uses the Microsoft Graph .NET Client Library to work with data, and the Microsoft Identity Web Library for authentication on the Microsoft identity platform v2.0 endpoint.
MIT License
189 stars 101 forks source link

How to obtain a directory extension #32

Closed jbartolome closed 4 years ago

jbartolome commented 7 years ago

Hello, I'm trying to query a custom directory extension that was added to our user object. The extension is named extension_EXTENSION-ID_extensionName. I am able to use the Graph Explorer to obtain the directory extension: https://graph.microsoft.com/beta/users('{user@email.com}')?select=extension_EXTENSION-ID_extensionName

I realize the the Graph User object has a fixed model for which I can query and get Intellisense to return a list of properties for the user, however, my extension is not within this list. Is there a way to obtain this extension? And it is supported using the solution provided here?

hiraldesai commented 6 years ago

Make sure your extension property is part of your query first. e.g.

var user = await client.Me.Request().Select("id,displayName,extension_EXTENSION-ID_extensionName").GetAsync();

The properties that are not part of the standard User object will be inside AdditionalData property for the object, you can obtain it by doing this:

var extension = user.AdditionalData["extension_EXTENSION-ID_extensionName"];