// when using the npm module, use the following syntax // var MicrosoftGraph = require("@microsoft/microsoft-graph-client").Client; // for fast development, simply require the generated lib without bundling the npm module const MicrosoftGraph = require("../../lib/src/index.js").Client; const secrets = require("./secrets"); const client = MicrosoftGraph.init({ defaultVersion: 'v1.0', debugLogging: true, authProvider: (done) => { done(null, secrets.accessToken); } }); // Get the name of the authenticated user with callbacks client .api('/me') .select("displayName") .get((err, res) => { if (err) { console.log(err) return; } console.log(res.displayName); }); /* // 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') .update( {"birthday": "1908-12-22T00:00:00Z"}, (err, res) => { if (err) { console.log(err); return; } console.log("Updated my birthday"); } ); // GET /users client .api('/users') .version('beta') .get((err, res) => { if (err) { console.log(err); return; } console.log("Found", res.value.length, "users"); }); // Find my top 5 contacts on the beta endpoint client .api('/me/people') .version('beta') .top(5) .select("displayName") .get((err, res) => { if (err) { console.log(err) return; } const topContacts = res.value.map((u) => {return u.displayName}); console.log("Your top contacts are", topContacts.join(", ")); }); // Use promises instead of callbacks // .get() returns a Promise client .api('/me') .select("displayName") .get() .then((res) => { console.log(res.displayName); }) .catch(console.error); // Find my top 5 contacts on the beta endpoint // .select() can be called multiple times client .api('/me/people') .top(5) .version('beta') .select("displayName") .select("title") // or call with .select(["displayName", "title"]) or .select("displayName", "title") .get((err, res) => { if (err) { console.log(err) return; } console.log(res.value[0].title, res.value[0].displayName); }); // send an email const mail = { subject: "MicrosoftGraph JavaScript SDK Samples", toRecipients: [{ emailAddress: { address: "example@example.com" } }], body: { content: "