@microsoft/microsoft-graph-types
Advanced tools
Comparing version 1.4.0 to 1.5.0
{ | ||
"name": "@microsoft/microsoft-graph-types", | ||
"description": "Types for Microsoft Graph objects", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"types": "microsoft-graph.d.ts", | ||
@@ -23,2 +23,2 @@ "scripts": { | ||
} | ||
} | ||
} |
@@ -20,7 +20,7 @@ [](https://www.npmjs.com/package/@microsoft/microsoft-graph-types) | ||
## Examples | ||
The following examples assume that you have a valid access token. We used [superagent](https://github.com/visionmedia/superagent) to perform the HTTP requests, but you can use [our JavaScript client library](https://github.com/microsoftgraph/msgraph-sdk-javascript) or other libraries as well. | ||
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. | ||
```typescript | ||
import * as MicrosoftGraph from "@microsoft/microsoft-graph-types" | ||
import * as request from 'superagent'; | ||
import * from 'isomorphic-fetch'; | ||
const accessToken:string = ""; | ||
@@ -30,11 +30,14 @@ ``` | ||
```typescript | ||
request | ||
.get("https://graph.microsoft.com/v1.0/me/messages") | ||
.set('Authorization', 'Bearer ' + accessToken) | ||
.end((err, res) => { | ||
if (err) { | ||
console.error(err) | ||
return; | ||
} | ||
let messages:[MicrosoftGraph.Message] = res.body.value; | ||
let url = "https://graph.microsoft.com/v1.0/me/messages"; | ||
let request = new Request(url, { | ||
method: "GET", | ||
headers: new Headers({ | ||
"Authorization": "Bearer " + accessToken | ||
}) | ||
}); | ||
fetch(request) | ||
.then((response) => { | ||
response.json().then((res) => { | ||
let messages:[MicrosoftGraph.Message] = res.value; | ||
for (let msg of messages) { //iterate through the recent messages | ||
@@ -44,4 +47,8 @@ console.log(msg.subject); | ||
} | ||
}); | ||
}) | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
}); | ||
``` | ||
@@ -68,9 +75,25 @@ ### Send an email as the logged in user | ||
// send the email by sending a POST request to the Microsoft Graph | ||
request | ||
.post('https://graph.microsoft.com/v1.0/users/me/sendMail') | ||
.send({message: mail}) | ||
.set('Authorization', 'Bearer ' + accessToken) | ||
.end((err, res) => { | ||
console.log(res) | ||
}) | ||
let url = "https://graph.microsoft.com/v1.0/users/me/sendMail"; | ||
let request = new Request( | ||
url, { | ||
method: "POST", | ||
body: JSON.stringify({ | ||
message: mail | ||
}), | ||
headers: new Headers({ | ||
"Authorization": "Bearer " + accessToken, | ||
'Content-Type': 'application/json' | ||
}) | ||
} | ||
); | ||
fetch(request) | ||
.then((response) => { | ||
if(response.ok === true) { | ||
console.log("Mail sent successfully..!!"); | ||
} | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
}); | ||
@@ -77,0 +100,0 @@ ``` |
Sorry, the diff of this file is too big to display
7513
146
1141909