/** * ------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. * See License in the project root for license information. * ------------------------------------------------------------------------------------------- */ // First, create an instance of the Microsoft Graph JS SDK Client class const { client } = require("../clientInitialization/ClientWithOptions"); /** * OR * const { client } = require("../clientInitialization/TokenCredentialAuthenticationProvider"); * OR * require or import client created using an custom authentication provider */ // Get the name of the authenticated user with promises client .api("/me") .select("displayName") .get() .then((res) => { console.log(res); }) .catch((err) => { console.log(err); }); /* // Update the authenticated users birthday. client .api('/me') .header("content-type", "application/json") .update({ "birthday": "1908-12-22T00:00:00Z" }) .then((res) => { console.log("Updated my birthday"); }) .catch((err) => { console.log(err); }); // GET /users client .api('/users') .version('beta') .get() .then((res) => { console.log("Found", res.value.length, "users"); }) .catch((err) => { console.log(err); }); // Find my top 5 contacts on the beta endpoint client .api('/me/people') .version('beta') .top(5) .select("displayName") .get() .then((res) => { const topContacts = res.value.map((u) => { return u.displayName }); console.log("Your top contacts are", topContacts.join(", ")); }) .catch((err) => { console.log(err); }); // send an email const mail = { subject: "MicrosoftGraph JavaScript SDK Samples", toRecipients: [{ emailAddress: { address: "" } }], body: { content: "

MicrosoftGraph TypeScript Connect Sample


https://github.com/microsoftgraph/msgraph-sdk-javascript", contentType: "html" } } client .api('/users/me/sendMail') .post({ message: mail }) .then((res) => { console.log(res); }) .catch((err) => { console.log(err); }); // GET 3 of my events client .api('/me/events') .top(3) .get() .then((res) => { let upcomingEventNames = [] for (let i = 0; i < res.value.length; i++) { upcomingEventNames.push(res.value[i].subject); } console.log("My calendar events include", upcomingEventNames.join(", ")) }) .catch((err) => { console.log(err); }); // Download a file from OneDrive client .api('/me/drive/items//content') .getStream() .then((stream) => { let writeStream = fs.createWriteStream(``); stream.pipe(writeStream).on('error', err => { console.log(err); }); writeStream.on('finish', () => { console.log("finish"); }); writeStream.on('error', err => { console.log(err); }); }) .catch((err) => { console.log(err); }); // Upload a file to OneDrive let readStream = fs.createReadStream(""); client .api('/me/drive/root/children//content') .putStream(readStream) .then((res) => { console.log(res); }) .catch((err) => { console.log(err); }); */