Skip to content

Latest commit

 

History

History
182 lines (136 loc) · 3.17 KB

javascript-examples.md

File metadata and controls

182 lines (136 loc) · 3.17 KB
title description author
Javscript examples
Examples Snippets generated by the api
andrueastman

Javascript examples

This shows how snippets requests look like for javascript

Examples

GET Request

Example Get Request

GET /v1.0/me/events/AAMkAGIAAAoZDOFAAA=?$select=subject,body,bodyPreview,organizer,attendees,start,end,location HTTP/1.1
Host: graph.microsoft.com
Prefer: outlook.timezone="Pacific Standard Time"

Snippet generated

const options = {
  authProvider,
};

const client = Client.init(options);

let res = await client.api('/me/events/AAMkAGIAAAoZDOFAAA=')
  .header('Prefer','outlook.timezone="Pacific Standard Time"')
  .select('subject,body,bodyPreview,organizer,attendees,start,end,location')
  .get();

POST Request

Example POST Request

POST /v1.0/users HTTP/1.1
Host: graph.microsoft.com
Content-type: application/json

{
  "accountEnabled": true,
  "displayName": "displayName-value",
  "mailNickname": "mailNickname-value",
  "userPrincipalName": "upn-value@tenant-value.onmicrosoft.com",
  "passwordProfile" : {
    "forceChangePasswordNextSignIn": true,
    "password": "password-value"
  }
}

Example POST Request snippet generated

const options = {
  authProvider,
};

const client = Client.init(options);

const user = {
  accountEnabled: true,
  displayName: "displayName-value",
  mailNickname: "mailNickname-value",
  userPrincipalName: "upn-value@tenant-value.onmicrosoft.com",
  "passwordProfile" : {
    forceChangePasswordNextSignIn: true,
    password: "password-value"
  }
};

let res = await client.api('/users')
  .post(user);

PATCH Request

Example PATCH Request

PATCH /v1.0/me HTTP/1.1
Host: graph.microsoft.com
Content-type: application/json
Content-length: 491

{
  "accountEnabled": true,
  "businessPhones": [
    "businessPhones-value"
  ],
  "city": "city-value"
}

Example PATCH Request snippet generated

const options = {
  authProvider,
};

const client = Client.init(options);

const me = {
  accountEnabled: true,
  businessPhones: [
    "businessPhones-value"
  ],
  city: "city-value"
};

let res = await client.api('/me')
  .update(me);

PUT Request

Example PUT Request

PUT /beta/applications/{id}/synchronization/templates/{templateId} HTTP/1.1
Host: graph.microsoft.com
Authorization: Bearer <token>
Content-type: application/json

{
    "id": "Slack",
    "applicationId": "{id}",
    "factoryTag": "CustomSCIM"
}

Example PUT Request snippet generated

const options = {
  authProvider,
};

const client = Client.init(options);

const templates = {
    id: "Slack",
    applicationId: "{id}",
    factoryTag: "CustomSCIM"
};

let res = await client.api('/applications/{id}/synchronization/templates/{templateId}')
  .version('beta')
  .put(templates);

DELETE Request

Example DELETE Request

DELETE /v1.0/me/messages/{id} HTTP/1.1
Host: graph.microsoft.com

Example DELETE Request snippet generated

const options = {
  authProvider,
};

const client = Client.init(options);

let res = await client.api('/me/messages/{id}')
  .delete();