Microsoft Graph Client Library allows you to call Office 365, Azure AD and other Microsoft services through a single unified developer experience.
$ dotnet add package Microsoft.GraphIntegrate the Microsoft Graph API into your .NET project!
The Microsoft Graph .NET Client Library targets .NetStandard 2.0.
To install the client library via NuGet:
Microsoft.Graph in the NuGet Library, orInstall-Package Microsoft.Graph into the Package Manager Console.Register your application to use Microsoft Graph API using the Microsoft Application Registration Portal.
The Microsoft Graph .NET Client Library supports the use of TokenCredential classes in the Azure.Identity library.
You can read more about available Credential classes here and examples on how to quickly setup TokenCredential instances can be found here.
The recommended library for authenticating against Microsoft Identity (Azure AD) is MSAL.
For an example of authenticating a UWP app using the V2 Authentication Endpoint, see the Microsoft Graph UWP Connect Library.
An instance of the GraphServiceClient class handles building requests,
sending them to Microsoft Graph API, and processing the responses. To create a
new instance of this class, you need to provide an instance of
IAuthenticationProvider which can authenticate requests to Microsoft Graph.
For more information on initializing a client instance, see the library overview
Once you have completed authentication and have a GraphServiceClient, you can begin to make calls to the service. The requests in the SDK follow the format of the Microsoft Graph API's RESTful syntax.
For example, to retrieve a user's default drive:
var drive = await graphClient.Me.Drive.GetAsync();
GetAsync will return a Drive object on success and throw a
ApiException on error.
To get the current user's root folder of their default drive:
// Get the user's driveId
var drive = await graphClient.Me.Drive.GetAsync();
var userDriveId = drive.Id;
// use the driveId to get the root drive
var rootItem = await graphClient.Drives[userDriveId].Root.GetAsync();
GetAsync will return a DriveItem object on success and throw a
ApiException on error.
For a general overview of how the SDK is designed, see overview.
The following sample applications are also available:
The Microsoft Graph .NET Client Library is scheduled to be updated during the second and fourth week of each month
Between 1.x and 3.x there were some minor possibly breaking changes:
netStandard1.3 to netstandard2.0net45 to net461GiphyRatingTypeParticipantInfo became InvitationParticipantInfoCallRecordRequestBody became CallRecordResponseRequestBodyBetween 3.x and 4.x there were some major breaking changes:
netStandard1.3 to netstandard2.0net45 to net462View the upgrade guide here.
Between 4.x and 5.x there were several major breaking changes as the SDK now uses Kiota for code generation.
View the upgrade guide here.
To view or log issues, see issues.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
If you are looking to build the library locally for the purposes of contributing code or running tests, you will need to:
dotnet restore from the command line in your package directorynuget restore and msbuild from CLI or run Build from Visual Studio to restore Nuget packages and build the projectDue to long file names you may need to run
git config --system core.longpaths truebefore cloning the repo to your system.
Additionally for Windows OS, set the value of the parameter
HKLM\SYSTEM\CurrentControlSet\Control\FileSystemLongPathsEnabledto1, before opening the solution in VS
Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT license. See Third Party Notices for information on the packages referenced via NuGet.