Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@microsoft/microsoft-graph-client

Package Overview
Dependencies
Maintainers
3
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@microsoft/microsoft-graph-client

Microsoft Graph Client Library

  • 3.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
383K
decreased by-13.91%
Maintainers
3
Weekly downloads
 
Created

What is @microsoft/microsoft-graph-client?

@microsoft/microsoft-graph-client is an npm package that provides a client library for accessing Microsoft Graph, which is a unified API endpoint for accessing data across Microsoft 365 services. This package allows developers to interact with various Microsoft services such as Outlook, OneDrive, and Azure Active Directory, among others.

What are @microsoft/microsoft-graph-client's main functionalities?

Accessing User Information

This feature allows you to access information about the authenticated user. The code sample demonstrates how to initialize the client and make a request to the '/me' endpoint to retrieve user information.

const { Client } = require('@microsoft/microsoft-graph-client');
const client = Client.init({
  authProvider: (done) => {
    done(null, 'YOUR_ACCESS_TOKEN');
  }
});
client.api('/me').get().then((user) => {
  console.log(user);
}).catch((error) => {
  console.error(error);
});

Sending an Email

This feature allows you to send an email using the Microsoft Graph API. The code sample demonstrates how to create an email message and send it using the '/me/sendMail' endpoint.

const { Client } = require('@microsoft/microsoft-graph-client');
const client = Client.init({
  authProvider: (done) => {
    done(null, 'YOUR_ACCESS_TOKEN');
  }
});
const mail = {
  message: {
    subject: 'Hello from Microsoft Graph API',
    body: {
      contentType: 'Text',
      content: 'This is a test email sent using Microsoft Graph API.'
    },
    toRecipients: [
      {
        emailAddress: {
          address: 'recipient@example.com'
        }
      }
    ]
  }
};
client.api('/me/sendMail').post({ message: mail }).then(() => {
  console.log('Email sent successfully');
}).catch((error) => {
  console.error(error);
});

Accessing OneDrive Files

This feature allows you to access files stored in OneDrive. The code sample demonstrates how to list the files in the root directory of the authenticated user's OneDrive using the '/me/drive/root/children' endpoint.

const { Client } = require('@microsoft/microsoft-graph-client');
const client = Client.init({
  authProvider: (done) => {
    done(null, 'YOUR_ACCESS_TOKEN');
  }
});
client.api('/me/drive/root/children').get().then((files) => {
  console.log(files);
}).catch((error) => {
  console.error(error);
});

Other packages similar to @microsoft/microsoft-graph-client

Keywords

FAQs

Package last updated on 19 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc