# Microsoft Graph JavaScript Client Library [](https://www.npmjs.com/package/@microsoft/microsoft-graph-client) [](https://snyk.io/test/github/microsoftgraph/msgraph-sdk-javascript) [](https://github.com/microsoftgraph/msgraph-sdk-javascript) [](https://github.com/microsoftgraph/msgraph-sdk-javascript) [](https://www.npmjs.com/package/@microsoft/microsoft-graph-client) The Microsoft Graph JavaScript client library is a lightweight wrapper around the Microsoft Graph API that can be used server-side and in the browser. - [Microsoft Graph JavaScript Client Library](#microsoft-graph-javascript-client-library) - [Installation](#installation) - [Via npm](#via-npm) - [Via Script Tag](#via-script-tag) - [Getting started](#getting-started) - [1. Register your application](#1-register-your-application) - [2. Create a Client Instance](#2-create-a-client-instance) - [3. Make requests to the graph](#3-make-requests-to-the-graph) - Documentation - [HTTP Actions](docs/Actions.md) - [Chained APIs to call Microsoft Graph](docs/CallingPattern.md) - [OData system query options - Query Parameters](docs/QueryParameters.md) - [Batch multiple requests into single HTTP request](docs/content/Batching.md) - [Cancel a HTTP request](docs/CancellingAHTTPRequest.md) - [Configurations to your request](docs/OtherAPIs.md) - [Query](docs/OtherAPIs.md#QUERY) - [Version](docs/OtherAPIs.md#VERSION) - [Headers](docs/OtherAPIs.md#HEADER-AND-HEADERS) - [Options](docs/OtherAPIs.md#OPTION-AND-OPTIONS) - [MiddlewareOptions](docs/OtherAPIs.md#MIDDLEWAREOPTIONS) - [ResponseType](docs/OtherAPIs.md#RESPONSETYPE) - [Upload large files to OneDrive, Outlook, Print API](docs/tasks/LargeFileUploadTask.md) - [Page Iteration](docs/tasks/PageIterator.md) - [Getting Raw Response](docs/GettingRawResponse.md) - [Creating an instance of TokenCredentialAuthenticationProvider](docs/TokenCredentialAuthenticationProvider.md) - [Samples and tutorials](#samples-and-tutorials) - Step-by-step training exercises on creating a basic application using the Microsoft Graph JavaScript SDK: - [Build Angular single-page apps with Microsoft Graph](https://docs.microsoft.com/graph/tutorials/angular) - [Build Node.js Express apps with Microsoft Graph](https://docs.microsoft.com/graph/tutorials/node) - [Build React Native apps with Microsoft Graph](https://docs.microsoft.com/graph/tutorials/react-native) - [Build React single-page apps with Microsoft Graph](https://docs.microsoft.com/graph/tutorials/react) - [Build JavaScript single-page apps with Microsoft Graph](https://docs.microsoft.com/graph/tutorials/javascript) - [Explore Microsoft Graph scenarios for JavaScript development](https://docs.microsoft.com/learn/paths/m365-msgraph-scenarios/) - Samples using `TokenCredentialAuthenticationProvider` with the `@azure/identity` library: - [TokenCredentialAuthenticationProvider Samples](samples/) - Samples using `LargeFileUploadTask` and `OneDriveLargeFileTask`: - [LargeFileUploadTask Samples](samples/) - Samples to learn more about authentication using `MSAL`libraries: - [Azure-Sample Vanilla JS SPA using MSAL Browser and Microsoft Graph JavaScript SDK](https://github.com/Azure-Samples/ms-identity-javascript-tutorial/tree/main/2-Authorization-I/1-call-graph) - [ Azure-Sample Angular SPA using MSAL Angular and Microsoft Graph JavaScript SDK](https://github.com/Azure-Samples/ms-identity-javascript-angular-tutorial/tree/main/2-Authorization-I/1-call-graph) - [ Azure-Sample React SPA using MSAL React and Microsoft Graph JavaScript SDK](https://github.com/Azure-Samples/ms-identity-javascript-react-tutorial/tree/main/2-Authorization-I/1-call-graph) - [Questions and comments](#questions-and-comments) - [Contributing](#contributing) - [Additional resources](#additional-resources) - [Third Party Notices](#third-party-notices) - [Security Reporting](#security-reporting) - [License](#license) - [We Value and Adhere to the Microsoft Open Source Code of Conduct](#we-value-and-adhere-to-the-microsoft-open-source-code-of-conduct) **Looking for IntelliSense on models (Users, Groups, etc.)? Check out the Microsoft Graph Types [v1.0](https://github.com/microsoftgraph/msgraph-typescript-typings) and [beta](https://github.com/microsoftgraph/msgraph-beta-typescript-typings)!!** [](https://github.com/microsoftgraph/msgraph-typescript-typings) ## Node version requirement Node.js 12 LTS or higher. The active Long Term Service (LTS) version of Node.js is used for on-going testing of existing and upcoming product features. ## Installation ### Via npm ```cmd npm install @microsoft/microsoft-graph-client ``` import `@microsoft/microsoft-graph-client` into your module. Also, you will need to import any fetch polyfill which suits your requirements. Following are some fetch polyfills - - [isomorphic-fetch](https://www.npmjs.com/package/isomorphic-fetch). - [cross-fetch](https://www.npmjs.com/package/cross-fetch) - [whatwg-fetch](https://www.npmjs.com/package/whatwg-fetch) ```typescript import "isomorphic-fetch"; // or import the fetch polyfill you installed import { Client } from "@microsoft/microsoft-graph-client"; ``` ### Via Script Tag Include [graph-js-sdk.js](https://cdn.jsdelivr.net/npm/@microsoft/microsoft-graph-client/lib/graph-js-sdk.js) in your HTML page. ```HTML ``` In case your browser doesn't have support for [Fetch](https://developer.mozilla.org/docs/Web/API/Fetch_API) [[support](https://developer.mozilla.org/docs/Web/API/Fetch_API#Browser_compatibility)] or [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) [[support](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise#Browser_compatibility)], you need to use polyfills like [github/fetch](https://github.com/github/fetch) for fetch and [es6-promise](https://github.com/stefanpenner/es6-promise) for promise. ```HTML ``` ## Getting started ### 1. Register your application To call Microsoft Graph, your app must acquire an access token from the Microsoft identity platform. Learn more about this - - [Authentication and authorization basics for Microsoft Graph](https://docs.microsoft.com/graph/auth/auth-concepts) - [Register your app with the Microsoft identity platform](https://docs.microsoft.com/graph/auth/auth-concepts) ### 2. Create a Client Instance The Microsoft Graph client is designed to make it simple to make calls to Microsoft Graph. You can use a single client instance for the lifetime of the application. For information on how to create a client instance, see [Creating Client Instance](./docs/CreatingClientInstance.md) ### 3. Make requests to the graph Once you have authentication setup and an instance of Client, you can begin to make calls to the service. All requests should start with `client.api(path)` and end with an [action](./docs/Actions.md). Example of getting user details: ```typescript try { let userDetails = await client.api("/me").get(); console.log(userDetails); } catch (error) { throw error; } ``` Example of sending an email to the recipients: ```typescript // Construct email object const mail = { subject: "Microsoft Graph JavaScript Sample", toRecipients: [ { emailAddress: { address: "example@example.com", }, }, ], body: { content: "