Socket
Socket
Sign inDemoInstall

microsoft-graph-typings

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    microsoft-graph-typings

Types for Microsoft Graph objects


Version published
Weekly downloads
2
decreased by-66.67%
Maintainers
1
Install size
736 kB
Created
Weekly downloads
 

Readme

Source

npm version badge

Microsoft Graph TypeScript Typings

The Microsoft Graph TypeScript definitions enable editors to provide intellisense on Microsoft Graph objects.

Installation

We recommend using typings to install the definitions.


# Install typings if you don't have it already
npm install typings --global

# Download the typings and save the dependency to typings.json
typings install common~microsoft-graph --save

GIF showing intellisense and autocompletion for Microsoft Graph entities in Visual Studio Code

Examples

The following examples assume that you have a valid access token. We used superagent to perform the HTTP requests, but you can use our JavaScript SDK or other libraries as well.

import * as MicrosoftGraph from "microsoft-graph"

import * as request from 'superagent';
const accessToken:string = "";

List my recent messages

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;
        for (let msg of messages) { //iterate through the recent messages
            console.log(msg.subject);
            console.log(msg.toRecipients[0].emailAddress.address);
        }

    })

Send an email as the logged in user

// Create the message object

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

let mail:MicrosoftGraph.Message = {
    subject: "Microsoft Graph TypeScript Sample",
    toRecipients: [{
        emailAddress: {
            address: "microsoftgraph@example.com"
        }
    }],
    body: {
        content: "<h1>Microsoft Graph TypeScript Sample</h1>Try modifying the sample",
        contentType: "html"
    }
}
// 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) => {
        if (err) {
            console.error(err)
            return;
        }
        console.log(res)
    })

Note about date values

All DateTimeOffset values are returned as strings from Microsoft Graph and should be wrapped in new Date() at runtime.

let me:MicrosoftGraph.User = {}; // result from graph
let myBirthday = new Date(me.birthday);
console.log(myBirthday.toDateString());

Questions and comments

We'd love to get your feedback about the TypeScript definitions project. You can send your questions and suggestions to us in the Issues section of this repository.

Contributing

Please see the contributing guidelines.

Additional resources

Copyright (c) 2016 Microsoft. All rights reserved.

FAQs

Last updated on 22 Dec 2016

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc