Skip to content

Commit b06b54a

Browse files
authored
Update README.md
1 parent 9664c43 commit b06b54a

File tree

1 file changed

+30
-67
lines changed

1 file changed

+30
-67
lines changed

README.md

Lines changed: 30 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -14,49 +14,35 @@ npm install @microsoft/microsoft-graph-types --save-dev
1414

1515
```
1616

17-
1817
![GIF showing intellisense and autocompletion for Microsoft Graph entities in Visual Studio Code ](https://github.com/microsoftgraph/msgraph-typescript-typings/raw/master/typings-demo.gif)
18+
1919
## Examples
20-
The following examples assume that you have a valid access token. We used [isomorphic-fetch](https://www.npmjs.com/package/isomorphic-fetch) to perform requests, but you can use [our JavaScript client library](https://github.com/microsoftgraph/msgraph-sdk-javascript) or other libraries as well.
21-
```typescript
22-
import * as MicrosoftGraph from "@microsoft/microsoft-graph-types"
20+
The following examples assume that you have a valid access token. The following example uses [isomorphic-fetch](https://www.npmjs.com/package/isomorphic-fetch) and [Microsoft Graph JavaScript client library](https://github.com/microsoftgraph/msgraph-sdk-javascript) -
2321

24-
import * from 'isomorphic-fetch';
25-
const accessToken:string = "";
26-
```
27-
### List my recent messages
2822
```typescript
29-
let url = "https://graph.microsoft.com/v1.0/me/messages";
30-
let request = new Request(url, {
31-
method: "GET",
32-
headers: new Headers({
33-
"Authorization": "Bearer " + accessToken
34-
})
35-
});
23+
import { User } from "@microsoft/microsoft-graph-types-beta";
3624

37-
fetch(request)
38-
.then((response) => {
39-
response.json().then((res) => {
40-
let messages:[MicrosoftGraph.Message] = res.value;
41-
for (let msg of messages) { //iterate through the recent messages
42-
console.log(msg.subject);
43-
console.log(msg.toRecipients[0].emailAddress.address);
44-
}
45-
});
25+
import { Client } from "@microsoft/microsoft-graph-client";
26+
27+
import 'isomorphic-fetch';
4628

47-
})
48-
.catch((error) => {
49-
console.error(error);
29+
const client = Client.initWithMiddleware({
30+
defaultVersion: 'beta',
31+
...
5032
});
33+
34+
const response = await client.api("/me").get();
35+
const user = response as User;
5136
```
52-
### Send an email as the logged in user
37+
38+
### Example of creating an object
5339
```typescript
5440
// Create the message object
5541

5642
// Note that all the properties must follow the interface definitions.
57-
// For example, this will not compile if you try to type "xml" instead of "html" for contentType.
43+
// For example, this will not compile if you try to type "xml" instead of "html" for contentType.
5844

59-
let mail:MicrosoftGraph.Message = {
45+
let mail:MicrosoftGraphBeta.Message = {
6046
subject: "Microsoft Graph TypeScript Sample",
6147
toRecipients: [{
6248
emailAddress: {
@@ -68,55 +54,32 @@ let mail:MicrosoftGraph.Message = {
6854
contentType: "html"
6955
}
7056
}
71-
// send the email by sending a POST request to the Microsoft Graph
72-
let url = "https://graph.microsoft.com/v1.0/users/me/sendMail";
73-
let request = new Request(
74-
url, {
75-
method: "POST",
76-
body: JSON.stringify({
77-
message: mail
78-
}),
79-
headers: new Headers({
80-
"Authorization": "Bearer " + accessToken,
81-
'Content-Type': 'application/json'
82-
})
83-
}
84-
);
85-
86-
fetch(request)
87-
.then((response) => {
88-
if(response.ok === true) {
89-
console.log("Mail sent successfully..!!");
90-
}
91-
})
92-
.catch((err) => {
93-
console.error(err);
94-
});
95-
9657
```
97-
## Microsoft Graph beta support
98-
If you want to test the Microsoft Graph beta endpoints, you can use those types simultaneously with the v1.0 types.
99-
100-
Update your package.json file with the following:
10158

102-
```javascript
59+
## Example of using v1 types and beta types together
60+
```json
10361
"devDependencies": {
10462
// import published v1.0 types with a version from NPM
10563
"@microsoft/microsoft-graph-types": "^0.4.0",
106-
107-
// import beta types from the beta branch on the GitHub repo
108-
"@microsoft/microsoft-graph-types-beta": "microsoftgraph/msgraph-typescript-typings#beta"
64+
// import beta types with a version from NPM
65+
"@microsoft/microsoft-graph-types-beta": "^0.1.0-preview"
10966
}
11067
}
11168
```
11269

113-
Import the beta types from `@microsoft/microsoft-graph-types-beta`
11470
```typescript
115-
// import individual entities
116-
import {User as BetaUser} from "@microsoft/microsoft-graph-types-beta"
71+
import * as MicrosoftGraph from "@microsoft/microsoft-graph-types"
11772

118-
// or import everything under MicrosoftGraphBeta
11973
import * as MicrosoftGraphBeta from "@microsoft/microsoft-graph-types-beta"
74+
75+
const v1User: MicrosoftGraph.User = {
76+
givenName: "V1 User"
77+
}
78+
79+
const betaUser: MicrosoftGraphBeta.User = {
80+
givenName: "Beta User"
81+
}
82+
12083
```
12184

12285
## Supported editors

0 commit comments

Comments
 (0)