You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can use Microsoft Graph to build powerful solutions that access data from Office 365 services. Connecting SharePoint Framework (SPFx) solutions to Microsoft Graph requires you to register an Azure Active Directory (Azure AD) application and complete the authorization flow. To make this easier, you can use the SPFx **GraphHttpClient** class to call Microsoft Graph directly, without any additional setup.
3
+
You can use Microsoft Graph to build powerful solutions that access data from Office 365 and other Microsoft services. To connect SharePoint Framework (SPFx) solutions to Microsoft Graph, you have to register an Azure Active Directory (Azure AD) application and complete the authorization flow. To make this easier, you can use the SPFx **GraphHttpClient** class to call Microsoft Graph directly, without any additional setup.
4
4
5
5
> **Important:** The **GraphHttpClient** class is currently in developer preview and is subject to change. We don't recommend that you use it in your production environment.
6
6
7
-
## What is GraphHttpClient?
7
+
## What is the GraphHttpClient class?
8
8
9
-
GraphHttpClientis a specialized HTTP client provided as a part of the SharePoint Framework. It works similarly to the HttpClient that you can use to communicate with thirdparty APIs. On top of the HttpClient, the GraphHttpClientautomatically ensures that your request to the Microsoft Graph has a valid bearer access token and required headers. Whenever you issue a GET or a POST request, the GraphHttpClient verifies that it has a valid access token, and if it doesn't, it automatically retrieves one from an internal API and stores it for subsequent requests.
9
+
The **GraphHttpClient** class is included as part of the SharePoint Framework. It works in a similar way to the HttpClient that you can use to communicate with third-party APIs. The **GraphHttpClient** class automatically ensures that your request to Microsoft Graph has a valid bearer access token and the required headers. When you issue a GET or a POST request, **GraphHttpClient** verifies that it has a valid access token, and if it doesn't, it automatically retrieves one from an internal API and stores it for subsequent requests.
10
10
11
-
A sample request to the Microsoft Graph using the GraphHttpClient looks as follows:
11
+
The following example shows a request to Microsoft Graph that uses the **GraphHttpClient** class.
12
12
13
13
```ts
14
14
// ...
@@ -31,34 +31,36 @@ export default class MyApplicationCustomizer
31
31
}
32
32
}
33
33
```
34
+
To make a request to Microsoft Graph:
34
35
35
-
You start with importing the **GraphHttpClient** and **GraphClientResponse** modules from the **@microsoft/sp-http** package. Next, using the instance of the GraphHttpClient available on the `this.context.graphHttpClient` property, you issue a GET or a POST request to the Microsoft Graph. As the parameters, you specify the Microsoft Graph API that you want to call (starting with the API version without a leading `/` - slash), followed by the GraphHttpClient configuration. Optionally, you can specify additional request headers that will be merged with the default headers set by the GraphHttpClient (`'Accept': 'application/json'`, `'Authorization': 'Bearer [token]'` and `'Content-Type': 'application/json; charset=utf-8'`).
36
+
- Import the **GraphHttpClient** and **GraphClientResponse** modules from the **@microsoft/sp-http** package.
37
+
- Use the instance of **GraphHttpClient** that's available on the `this.context.graphHttpClient` property to issue a GET or POST request to Microsoft Graph.
38
+
- As parameters, specify the Microsoft Graph API that you want to call (start with the API version without a leading `/` - slash), followed by the **GraphHttpClient** configuration.
39
+
- Optionally, you can specify additional request headers that will be merged with the default headers set by **GraphHttpClient** (`'Accept': 'application/json'`, `'Authorization': 'Bearer [token]'` and `'Content-Type': 'application/json; charset=utf-8'`).
36
40
37
-
## GraphHttpClient considerations
41
+
## Considerations for using the **GraphHttpClient** class
38
42
39
-
Using the GraphHttpClient is a very convenient way of communicating with the Microsoft Graph as it abstracts away the authorization flow and management of access tokens. The GraphHttpClient is currently in developer preview and there are some considerations that you should take into account before using it.
43
+
The **GraphHttpClient** class provides a convenient way to communicate with Microsoft Graph because it abstracts the authorization flow and management of access tokens. Because **GraphHttpClient** is currently in developer preview, there are some considerations that you should take into account before using it.
40
44
41
45
### Use for Microsoft Graph access only
42
46
43
-
The GraphHttpClient is meant to be used only to access Microsoft Graph. The URL specified in the request must begin with the version of the Microsoft Graph API (either **v1.0** or **beta**), followed by the API operation. Any other URL will return an error.
47
+
Use the **GraphHttpClient** class only to access Microsoft Graph. The URL specified in the request must begin with the version of the Microsoft Graph API (either **v1.0** or **beta**), followed by the API operation. Any other URL will return an error.
44
48
45
49
### Permissions
46
50
47
-
The GraphHttpClient uses the **Office 365 SharePoint Online** Azure AD application to retrieve a valid access token to Microsoft Graph on behalf of the current user. The retrieved access token contains two permissionss:
51
+
The GraphHttpClient uses the Office 365 SharePoint Online Azure AD application to retrieve a valid access token to Microsoft Graph on behalf of the current user. The retrieved access token contains two permissions:
48
52
49
-
***Read and write all groups (preview)** (`Group.ReadWrite.All`)
50
-
***Read all usage reports** (`Reports.Read.All`)
53
+
* Read and write all groups (preview) (`Group.ReadWrite.All`)
54
+
* Read all usage reports (`Reports.Read.All`)
51
55
52
-
At this moment these are the only two permissions available when using the GraphHttpClient. If you need other permission scopes in your solution, you can use [ADAL JS with implicit OAuth flow](web-parts/guidance/call-microsoft-graph-from-your-web-part.md) instead.
56
+
These are the only permissions that are available when you use **GraphHttpClient**. If you need other permissions for your solution, you can use [ADAL JS with implicit OAuth flow](web-parts/guidance/call-microsoft-graph-from-your-web-part.md) instead.
53
57
54
58
### Tokens are retrieved using an internal API
55
59
56
-
To acquire a valid access token, the GraphHttpClient issues a web request to the `/_api/SP.OAuth.Token/Acquire` endpoint. This API is intended for internal use and you should not communicate with it directly in your solutions.
60
+
To acquire a valid access token, **GraphHttpClient** issues a web request to the `/_api/SP.OAuth.Token/Acquire` endpoint. This API is intended for internal use. You should not communicate with it directly in your solutions.
57
61
58
-
## More information
62
+
## See also
59
63
60
-
To see how the GraphHttpClient can be used in practice, see a sample solution on GitHub at [https://github.com/SharePoint/sp-dev-fx-extensions/tree/master/samples/js-application-graph-client](https://github.com/SharePoint/sp-dev-fx-extensions/tree/master/samples/js-application-graph-client).
61
-
62
-
To learn how to build a web part that can GET and POST REST calls to Microsoft Graph, see [Call the Microsoft Graph using GraphHttpClient](call-microsoft-graph-using-graphhttpclient.md)
63
-
64
-
For more information about the Microsoft Graph visit [https://developer.microsoft.com/en-us/graph/](https://developer.microsoft.com/en-us/graph/).
64
+
-[Application Customizer GraphClient from Modern Teamsite sample](https://github.com/SharePoint/sp-dev-fx-extensions/tree/master/samples/js-application-graph-client).
65
+
-[Use GraphHttpClient to call Microsoft Graph](call-microsoft-graph-using-graphhttpclient.md)
66
+
-[Microsoft Graph Dev Center](https://developer.microsoft.com/en-us/graph/)
0 commit comments