How to connect and use the Microsoft Graph API?

microsoft_graphIn this article, I would like to give you some examples of how to connect and use the Microsoft Graph API. My task was to extract contacts from the Global Address List, and unfortunately, this particular method is still not implemented, and only accessible in beta mode. We will go through a technique which will help you to use Microsoft Graph API beta from the stable SDK library and extract the information you might need.

First of all, lets set up the connection. To extract data, I will use the standard console application together with azure application registration. So First of all, open your Azure portal, then go to Azure active directory, then app registrations and create a new app. I’ve created a single-tenant app. Now on the app page, you already have your tenant id and client id, which you will need to connect. One more thing which you also need to generate is client secret, so go to the appropriate section and create the secret. Once all steps are done, the last step in the portal is to give proper permissions. I gave the following permissions to my application.

graphapipermissions

Usually, you can find all the credentials you might need on the page of the corresponding API call. As an example to list organizational contacts, you need the following credentials.

listorgcontacts

More information you can find on the API call page: List orgContacts.

The next step is to connect all needed NuGet packages. Most probably, you will need the following packages.

nugetpacks

Now we ready to write some code and access Graph APIs.

Replace placeholders with the values which you can find in your app registration. In the code above, you can also find some examples of how to call different methods from the standard library as well as from the beta library.

Leave a Reply