Skip to content

Commit deafb6d

Browse files
Merge pull request SharePoint#8402 from rob-windsor/rw-spfx1152-use-msgraph
Update article Use the MSGraphClient to connect to Microsoft Graph to use MSGraphClientV3 instead of MSGraphClient
2 parents 200e454 + e168085 commit deafb6d

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

docs/spfx/use-msgraph.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
---
2-
title: Use the MSGraphClient to connect to Microsoft Graph
3-
description: Use the MSGraphClient class to make calls to the Microsoft Graph REST API.
4-
ms.date: 6/21/2022
2+
title: Use the MSGraphClientV3 to connect to Microsoft Graph
3+
description: Use the MSGraphClientV3 class to make calls to the Microsoft Graph REST API.
4+
ms.date: 08/29/2022
55
ms.localizationpriority: high
66
---
77

8-
# Use the MSGraphClient to connect to Microsoft Graph
8+
# Use the MSGraphClientV3 to connect to Microsoft Graph
99

10-
When building SharePoint Framework solutions, you can easily connect to the Microsoft Graph by using the **MSGraphClient**.
10+
When building SharePoint Framework solutions, you can easily connect to the Microsoft Graph by using the **MSGraphClientV3**.
1111

1212
## MSGraphClient overview
1313

14-
**MSGraphClient** is a new HTTP client introduced in SharePoint Framework v1.6.0 that simplifies connecting to the Microsoft Graph inside SharePoint Framework solutions. **MSGraphClient** wraps the existing [Microsoft Graph JavaScript Client Library](https://www.npmjs.com/package/@microsoft/microsoft-graph-client), offering developers the same capabilities as when using the client library in other client-side solutions.
14+
**MSGraphClientV3** is a new HTTP client introduced in SharePoint Framework v1.15.0 that simplifies connecting to the Microsoft Graph inside SharePoint Framework solutions. **MSGraphClientV3** wraps the [Microsoft Graph JavaScript Client Library v3](https://www.npmjs.com/package/@microsoft/microsoft-graph-client), offering developers the same capabilities as when using the client library in other client-side solutions.
1515

16-
While you could use the Microsoft Graph JavaScript Client Library in your solution directly, **MSGraphClient** handles authenticating against the Microsoft Graph for you, which allows you to focus on building your solution.
16+
**MSGraphClientV3** replaces **MSGraphClient** which was introduced in SharePoint Framework v1.6.0. **MSGraphClient** wrapped the Microsoft Graph JavaScript Client Library v1.
17+
18+
While you could use the Microsoft Graph JavaScript Client Library in your solution directly, **MSGraphClientV3** handles authenticating against the Microsoft Graph for you, which allows you to focus on building your solution.
1719

1820
## Use the MSGraphClient in your solution
1921

2022
> [!NOTE]
21-
> The **MSGraphClient** is available only in projects built using SharePoint Framework v1.6.0 and later. While the **MSGraphClient** is explained in this article by using a client-side web part, you can also use it in SharePoint Framework Extensions.
23+
> The **MSGraphClientV3** is available only in projects built using SharePoint Framework v1.15.0 and later. While the **MSGraphClientV3** is explained in this article by using a client-side web part, you can also use it in SharePoint Framework Extensions.
2224

2325
> [!NOTE]
24-
> The single sign-on for the **MSGraphClient** is only available in SharePoint Online today. You can leverage the client for on premises developments but your users will be requested to sign in again within the webpart.
26+
> The single sign-on for the **MSGraphClientV3** is only available in SharePoint Online today. You can leverage the client for on premises developments but your users will be requested to sign in again within the webpart.
2527

26-
1. To use the **MSGraphClient** in your SharePoint Framework solution, add the following `import` clause in your main web part file:
28+
1. To use the **MSGraphClientV3** in your SharePoint Framework solution, add the following `import` clause in your main web part file:
2729

2830
```typescript
29-
import { MSGraphClient } from '@microsoft/sp-http';
31+
import { MSGraphClientV3 } from '@microsoft/sp-http';
3032
```
3133

32-
1. **MSGraphClient** is exposed through the **MSGraphClientFactory** available on the web part context. To get a reference to MSGraphClient, in your code add:
34+
1. **MSGraphClientV3** is exposed through the **MSGraphClientFactory** available on the web part context. To get a reference to MSGraphClient, in your code add:
3335

3436
```typescript
3537
export default class HelloWorldWebPart extends BaseClientSideWebPart<IHelloWorldWebPartProps> {
@@ -38,7 +40,7 @@ While you could use the Microsoft Graph JavaScript Client Library in your soluti
3840

3941
this.context.msGraphClientFactory
4042
.getClient('3')
41-
.then((client: MSGraphClient): void => {
43+
.then((client: MSGraphClientV3): void => {
4244
// use MSGraphClient here
4345
});
4446
}
@@ -47,7 +49,7 @@ While you could use the Microsoft Graph JavaScript Client Library in your soluti
4749
}
4850
```
4951

50-
1. After you have the reference to the **MSGraphClient** instance, start communicating with the Microsoft Graph by using its JavaScript Client Library syntax:
52+
1. After you have the reference to the **MSGraphClientV3** instance, start communicating with the Microsoft Graph by using its JavaScript Client Library syntax:
5153

5254
```typescript
5355
export default class HelloWorldWebPart extends BaseClientSideWebPart<IHelloWorldWebPartProps> {
@@ -56,7 +58,7 @@ While you could use the Microsoft Graph JavaScript Client Library in your soluti
5658

5759
this.context.msGraphClientFactory
5860
.getClient('3')
59-
.then((client: MSGraphClient): void => {
61+
.then((client: MSGraphClientV3): void => {
6062
// get information about the current user from the Microsoft Graph
6163
client
6264
.api('/me')
@@ -95,11 +97,11 @@ When working with the Microsoft Graph and TypeScript, you can use the [Microsoft
9597

9698
this.context.msGraphClientFactory
9799
.getClient('3')
98-
.then((client: MSGraphClient): void => {
100+
.then((client: MSGraphClientV3): void => {
99101
// get information about the current user from the Microsoft Graph
100102
client
101103
.api('/me')
102-
.get((error, user: MicrosoftGraph.User, rawResponse?: any) => {
104+
.get((error: any, user: MicrosoftGraph.User, rawResponse?: any) => {
103105
// handle the response
104106
});
105107
});

0 commit comments

Comments
 (0)