Skip to content

Latest commit

 

History

History
1153 lines (963 loc) · 49 KB

node-outlook.md

File metadata and controls

1153 lines (963 loc) · 49 KB

Modules

base
mail
calendar
contacts

base

base.makeApiCall(parameters, [callback])

Used to do the actual send of a REST request to the REST endpoint.

Kind: static method of base

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.url string The full URL of the API endpoint
parameters.token string The access token for authentication
[parameters.user.email] string The user's SMTP email address, used to set the X-AnchorMailbox header.
[parameters.user.timezone] string The user's time zone, used to set the outlook.timezone Prefer header.
[parameters.method] string Used to specify the HTTP method. Default is 'GET'.
[parameters.query] object An object containing key/value pairs. The pairs will be serialized into a query string.
[parameters.payload] object A JSON-serializable object representing the request body.
[parameters.headers] object A JSON-serializable object representing custom headers to send with the request.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

base.getUser(parameters, [callback])

Used to get information about a user.

Kind: static method of base

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.odataParams] object An object containing key/value pairs representing OData query parameters. See Use OData query parameters for details.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the v2.0 endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

// Set up oData parameters
var queryParams = {
  '$select': 'DisplayName, EmailAddress',
};

outlook.base.getUser({token: token, odataParams: queryParams},
  function(error, result) {
    if (error) {
      console.log('getUser returned an error: ' + error);
    }
    else if (result) {
      console.log('User name:', result.DisplayName);
      console.log('User email:', result.EmailAddress);
    }
  });

base.setTraceFunc(traceFunc)

Used to provide a tracing function.

Kind: static method of base

Param Type Description
traceFunc function A function that takes a string parameter. The string parameter contains the text to add to the trace.

base.setFiddlerEnabled(enabled)

Used to enable network sniffing with Fiddler.

Kind: static method of base

Param Type Description
enabled boolean true to enable default Fiddler proxy and disable SSL verification. false to disable proxy and enable SSL verification.

base.apiEndpoint() ⇒ string

Gets the API endpoint URL.

Kind: static method of base

base.setApiEndpoint(newEndPoint)

Sets the API endpoint URL. If not called, the default of https://outlook.office.com/api/v1.0 is used.

Kind: static method of base

Param Type Description
newEndPoint string The API endpoint URL to use.

base.anchorMailbox() ⇒ string

Gets the default anchor mailbox address.

Kind: static method of base

base.setAnchorMailbox(newAnchor)

Sets the default anchor mailbox address.

Kind: static method of base

Param Type Description
newAnchor string The SMTP address to send in the X-Anchor-Mailbox header.

base.preferredTimeZone() ⇒ string

Gets the default preferred time zone.

Kind: static method of base

base.setPreferredTimeZone(preferredTimeZone)

Sets the default preferred time zone.

Kind: static method of base

Param Type Description
preferredTimeZone string The time zone in which the server should return date time values.

mail

mail.getMessages(parameters, [callback])

Used to get messages from a folder.

Kind: static method of mail

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.user.timezone] string The timezone of the user.
[parameters.folderId] string The folder id. If absent, the API calls the /User/Messages endpoint. Valid values of this parameter are: - The Id property of a MailFolder entity - Inbox - Drafts - SentItems - DeletedItems
[parameters.odataParams] object An object containing key/value pairs representing OData query parameters. See Use OData query parameters for details.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the v2.0 endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

// Set up oData parameters
var queryParams = {
  '$select': 'Subject,ReceivedDateTime,From',
  '$orderby': 'ReceivedDateTime desc',
  '$top': 20
};

// Pass the user's email address
var userInfo = {
  email: 'sarad@contoso.com'
};

outlook.mail.getMessages({token: token, folderId: 'Inbox', odataParams: queryParams, user: userInfo},
  function(error, result){
    if (error) {
      console.log('getMessages returned an error: ' + error);
    }
    else if (result) {
      console.log('getMessages returned ' + result.value.length + ' messages.');
      result.value.forEach(function(message) {
        console.log('  Subject:', message.Subject);
        console.log('  Received:', message.ReceivedDateTime.toString());
        console.log('  From:', message.From ? message.From.EmailAddress.Name : 'EMPTY');
      });
    }
  });

mail.getMessage(parameters, [callback])

Used to get a specific message.

Kind: static method of mail

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
parameters.messageId string The Id of the message.
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.user.timezone] string The timezone of the user.
[parameters.odataParams] object An object containing key/value pairs representing OData query parameters. See Use OData query parameters for details.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the v2.0 endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

// The Id property of the message to retrieve. This could be 
// from a previous call to getMessages
var msgId = 'AAMkADVhYTYwNzk...';

// Set up oData parameters
var queryParams = {
  '$select': 'Subject,ReceivedDateTime,From'
};

// Pass the user's email address
var userInfo = {
  email: 'sarad@contoso.com'
};

outlook.mail.getMessage({token: token, messageId: msgId, odataParams: queryParams, user: userInfo},
  function(error, result){
    if (error) {
      console.log('getMessage returned an error: ' + error);
    }
    else if (result) {
      console.log('  Subject:', result.Subject);
      console.log('  Received:', result.ReceivedDateTime.toString());
      console.log('  From:', result.From ? result.From.EmailAddress.Name : 'EMPTY');
    }
  });

mail.createMessage(parameters, [callback])

Create a new message

Kind: static method of mail

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
parameters.message object The JSON-serializable message
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.user.timezone] string The timezone of the user.
[parameters.folderId] string The folder id. If absent, the API calls the /User/Messages endpoint.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the v2.0 endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

var newMsg = {
  Subject: 'Did you see last night\'s game?',
  Importance: 'Low',
  Body: {
    ContentType: 'HTML',
    Content: 'They were <b>awesome</b>!'
  },
  ToRecipients: [
    {
      EmailAddress: {
        Address: 'azizh@contoso.com'
      }
    }
  ]
};

// Pass the user's email address
var userInfo = {
  email: 'sarad@contoso.com'
};

outlook.mail.createMessage({token: token, message: newMsg, user: userInfo},
  function(error, result){
    if (error) {
      console.log('createMessage returned an error: ' + error);
    }
    else if (result) {
      console.log(JSON.stringify(result, null, 2));
    }
  });

mail.updateMessage(parameters, [callback])

Update a specific message.

Kind: static method of mail

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
parameters.messageId string The Id of the message.
parameters.update object The JSON-serializable update payload
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.user.timezone] string The timezone of the user.
[parameters.odataParams] object An object containing key/value pairs representing OData query parameters. See Use OData query parameters for details.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the v2.0 endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

// The Id property of the message to update. This could be 
// from a previous call to getMessages
var msgId = 'AAMkADVhYTYwNzk...';

// Mark the message unread
var update = {
  IsRead: false,
};

// Pass the user's email address
var userInfo = {
  email: 'sarad@contoso.com'
};

outlook.mail.updateMessage({token: token, messageId: msgId, update: update, user: userInfo},
  function(error, result){
    if (error) {
      console.log('updateMessage returned an error: ' + error);
    }
    else if (result) {
      console.log(JSON.stringify(result, null, 2));
    }
  });

mail.deleteMessage(parameters, [callback])

Delete a specific message.

Kind: static method of mail

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
parameters.messageId string The Id of the message.
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.user.timezone] string The timezone of the user.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the v2.0 endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

// The Id property of the message to delete. This could be 
// from a previous call to getMessages
var msgId = 'AAMkADVhYTYwNzk...';

// Pass the user's email address
var userInfo = {
  email: 'sarad@contoso.com'
};

outlook.mail.deleteMessage({token: token, messageId: msgId, user: userInfo},
  function(error, result){
    if (error) {
      console.log('deleteMessage returned an error: ' + error);
    }
    else if (result) {
      console.log('SUCCESS');
    }
  });

mail.sendNewMessage(parameters, [callback])

Sends a new message

Kind: static method of mail

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
parameters.message object The JSON-serializable message
[parameters.saveToSentItems] boolean Set to false to bypass saving a copy to the Sent Items folder. Default is true.
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.user.timezone] string The timezone of the user.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the v2.0 endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

var newMsg = {
  Subject: 'Did you see last night\'s game?',
  Importance: 'Low',
  Body: {
    ContentType: 'HTML',
    Content: 'They were <b>awesome</b>!'
  },
  ToRecipients: [
    {
      EmailAddress: {
        Address: 'azizh@contoso.com'
      }
    }
  ]
};

// Pass the user's email address
var userInfo = {
  email: 'sarad@contoso.com'
};

outlook.mail.sendNewMessage({token: token, message: newMsg, user: userInfo},
  function(error, result){
    if (error) {
      console.log('sendNewMessage returned an error: ' + error);
    }
    else if (result) {
      console.log(JSON.stringify(result, null, 2));
    }
  });

mail.sendDraftMessage(parameters, [callback])

Sends a draft message.

Kind: static method of mail

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
parameters.messageId string The Id of the message.
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.user.timezone] string The timezone of the user.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the v2.0 endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

// The Id property of the message to send. This could be 
// from a previous call to getMessages
var msgId = 'AAMkADVhYTYwNzk...';

// Pass the user's email address
var userInfo = {
  email: 'sarad@contoso.com'
};

outlook.mail.sendDraftMessage({token: token, messageId: msgId, user: userInfo},
  function(error, result){
    if (error) {
      console.log('sendDraftMessage returned an error: ' + error);
    }
    else if (result) {
      console.log('SUCCESS');
    }
  });

mail.syncMessages(parameters, [callback])

Syncs messages in a folder.

Kind: static method of mail

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
[parameters.pageSize] Number The maximum number of results to return in each call. Defaults to 50.
[parameters.skipToken] string The value to pass in the skipToken query parameter in the API call.
[parameters.deltaToken] string The value to pass in the deltaToken query parameter in the API call.
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.user.timezone] string The timezone of the user.
[parameters.folderId] string The folder id. If absent, the API calls the /User/Messages endpoint. Valid values of this parameter are: - The Id property of a MailFolder entity - Inbox - Drafts - SentItems - DeletedItems
[parameters.odataParams] object An object containing key/value pairs representing OData query parameters. See Use OData query parameters for details.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the beta endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/beta');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

// Pass the user's email address
var userInfo = {
  email: 'sarad@contoso.com'
};

var syncMsgParams = {
  '$select': 'Subject,ReceivedDateTime,From,BodyPreview,IsRead',
  '$orderby': 'ReceivedDateTime desc'
};

var apiOptions = {
  token: token,
  folderId: 'Inbox',
  odataParams: syncMsgParams,
  user: userinfo,
  pageSize: 20
};

outlook.mail.syncMessages(apiOptions, function(error, messages) {
  if (error) {
    console.log('syncMessages returned an error:', error);
  } else {
    // Do something with the messages.value array
    // Then get the @odata.deltaLink
    var delta = messages['@odata.deltaLink'];

    // Handle deltaLink value appropriately:
    // In general, if the deltaLink has a $skiptoken, that means there are more
    // "pages" in the sync results, you should call syncMessages again, passing
    // the $skiptoken value in the apiOptions.skipToken. If on the other hand,
    // the deltaLink has a $deltatoken, that means the sync is complete, and you should
    // store the $deltatoken value for future syncs.
    //
    // The one exception to this rule is on the intial sync (when you call with no skip or delta tokens).
    // In this case you always get a $deltatoken back, even if there are more results. In this case, you should
    // immediately call syncMessages again, passing the $deltatoken value in apiOptions.deltaToken.
  }
}

calendar

calendar.getEvents(parameters, [callback])

Used to get events from a calendar.

Kind: static method of calendar

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.user.timezone] string The timezone of the user.
[parameters.calendarId] string The calendar id. If absent, the API calls the /User/Events endpoint.
[parameters.odataParams] object An object containing key/value pairs representing OData query parameters. See Use OData query parameters for details.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the v2.0 endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

// Set up oData parameters
var queryParams = {
  '$select': 'Subject,Start,End',
  '$orderby': 'Start/DateTime desc',
  '$top': 20
};

// Pass the user's email address
var userInfo = {
  email: 'sarad@contoso.com'
};

outlook.calendar.getEvents({token: token, folderId: 'Inbox', odataParams: queryParams, user: userInfo},
  function(error, result){
    if (error) {
      console.log('getEvents returned an error: ' + error);
    }
    else if (result) {
      console.log('getEvents returned ' + result.value.length + ' events.');
      result.value.forEach(function(event) {
        console.log('  Subject:', event.Subject);
        console.log('  Start:', event.Start.DateTime.toString());
        console.log('  End:', event.End.DateTime.toString());
      });
    }
  });

calendar.getEvent(parameters, [callback])

Used to get a specific event.

Kind: static method of calendar

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
parameters.eventId string The Id of the event.
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.user.timezone] string The timezone of the user.
[parameters.odataParams] object An object containing key/value pairs representing OData query parameters. See Use OData query parameters for details.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the v2.0 endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

// The Id property of the event to retrieve. This could be 
// from a previous call to getEvents
var eventId = 'AAMkADVhYTYwNzk...';

// Set up oData parameters
var queryParams = {
  '$select': 'Subject,Start,End'
};

// Pass the user's email address
var userInfo = {
  email: 'sarad@contoso.com'
};

outlook.calendar.getEvent({token: token, eventId: eventId, odataParams: queryParams, user: userInfo},
  function(error, result){
    if (error) {
      console.log('getEvent returned an error: ' + error);
    }
    else if (result) {
      console.log('  Subject:', result.Subject);
      console.log('  Start:', result.Start.DateTime.toString());
      console.log('  End:', result.End.DateTime.toString());
    }
  });

calendar.createEvent(parameters, [callback])

Create a new event

Kind: static method of calendar

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
parameters.event object The JSON-serializable event
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.user.timezone] string The timezone of the user.
[parameters.calendarId] string The calendar id. If absent, the API calls the /User/Events endpoint.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the v2.0 endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

var newEvent = {
  "Subject": "Discuss the Calendar REST API",
  "Body": {
    "ContentType": "HTML",
    "Content": "I think it will meet our requirements!"
  },
  "Start": {
    "DateTime": "2016-02-03T18:00:00",
    "TimeZone": "Eastern Standard Time"
  },
  "End": {
    "DateTime": "2016-02-03T19:00:00",
    "TimeZone": "Eastern Standard Time"
  },
  "Attendees": [
    {
      "EmailAddress": {
        "Address": "allieb@contoso.com",
        "Name": "Allie Bellew"
      },
      "Type": "Required"
    }
  ]
};

// Pass the user's email address
var userInfo = {
  email: 'sarad@contoso.com'
};

outlook.calendar.createEvent({token: token, event: newEvent, user: userInfo},
  function(error, result){
    if (error) {
      console.log('createEvent returned an error: ' + error);
    }
    else if (result) {
      console.log(JSON.stringify(result, null, 2));
    }
  });

calendar.updateEvent(parameters, [callback])

Update a specific event.

Kind: static method of calendar

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
parameters.eventId string The Id of the event.
parameters.update object The JSON-serializable update payload
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.user.timezone] string The timezone of the user.
[parameters.odataParams] object An object containing key/value pairs representing OData query parameters. See Use OData query parameters for details.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the v2.0 endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

// The Id property of the event to update. This could be 
// from a previous call to getEvents
var eventId = 'AAMkADVhYTYwNzk...';

// Update the location
var update = {
  Location: {
    DisplayName: 'Conference Room 2'
  }
};

// Pass the user's email address
var userInfo = {
  email: 'sarad@contoso.com'
};

outlook.calendar.updateEvent({token: token, eventId: eventId, update: update, user: userInfo},
  function(error, result){
    if (error) {
      console.log('updateEvent returned an error: ' + error);
    }
    else if (result) {
      console.log(JSON.stringify(result, null, 2));
    }
  });

calendar.deleteEvent(parameters, [callback])

Delete a specific event.

Kind: static method of calendar

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
parameters.eventId string The Id of the event.
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.user.timezone] string The timezone of the user.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the v2.0 endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

// The Id property of the event to delete. This could be 
// from a previous call to getEvents
var eventId = 'AAMkADVhYTYwNzk...';

// Pass the user's email address
var userInfo = {
  email: 'sarad@contoso.com'
};

outlook.calendar.deleteEvent({token: token, eventId: eventId, user: userInfo},
  function(error, result){
    if (error) {
      console.log('deleteEvent returned an error: ' + error);
    }
    else if (result) {
      console.log('SUCCESS');
    }
  });

contacts

contacts.getContacts(parameters, [callback])

Used to get contacts from a contact folder.

Kind: static method of contacts

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.user.timezone] string The timezone of the user.
[parameters.contactFolderId] string The contact folder id. If absent, the API calls the /User/Contacts endpoint.
[parameters.odataParams] object An object containing key/value pairs representing OData query parameters. See Use OData query parameters for details.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the v2.0 endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

// Set up oData parameters
var queryParams = {
  '$select': 'GivenName,Surname,EmailAddresses',
  '$orderby': 'CreatedDateTime desc',
  '$top': 20
};

// Pass the user's email address
var userInfo = {
  email: 'sarad@contoso.com'
};

outlook.contacts.getContacts({token: token, odataParams: queryParams, user: userInfo},
  function(error, result){
    if (error) {
      console.log('getContacts returned an error: ' + error);
    }
    else if (result) {
      console.log('getContacts returned ' + result.value.length + ' contacts.');
      result.value.forEach(function(contact) {
        console.log('  GivenName:', contact.GivenName);
        console.log('  Surname:', contact.Surname);
        console.log('  Email Address:', contact.EmailAddresses[0] ? contact.EmailAddresses[0].Address : "NONE");
      });
    }
  });

contacts.getContact(parameters, [callback])

Used to get a specific contact.

Kind: static method of contacts

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
parameters.contactId string The Id of the contact.
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.user.timezone] string The timezone of the user.
[parameters.odataParams] object An object containing key/value pairs representing OData query parameters. See Use OData query parameters for details.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the v2.0 endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

// The Id property of the contact to retrieve. This could be 
// from a previous call to getContacts
var contactId = 'AAMkADVhYTYwNzk...';

// Set up oData parameters
var queryParams = {
  '$select': 'GivenName,Surname,EmailAddresses'
};

// Pass the user's email address
var userInfo = {
  email: 'sarad@contoso.com'
};

outlook.contacts.getContact({token: token, contactId: contactId, odataParams: queryParams, user: userInfo},
  function(error, result){
    if (error) {
      console.log('getContact returned an error: ' + error);
    }
    else if (result) {
      console.log('  GivenName:', result.GivenName);
      console.log('  Surname:', result.Surname);
      console.log('  Email Address:', result.EmailAddresses[0] ? result.EmailAddresses[0].Address : "NONE");
    }
  });

contacts.createContact(parameters, [callback])

Create a new contact

Kind: static method of contacts

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
parameters.contact object The JSON-serializable contact
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.user.timezone] string The timezone of the user.
[parameters.contactFolderId] string The contact folder id. If absent, the API calls the /User/Contacts endpoint.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the v2.0 endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

var newContact = {
  "GivenName": "Pavel",
  "Surname": "Bansky",
  "EmailAddresses": [
    {
      "Address": "pavelb@contoso.com",
      "Name": "Pavel Bansky"
    }
  ],
  "BusinessPhones": [
    "+1 732 555 0102"
  ]
};

// Pass the user's email address
var userInfo = {
  email: 'sarad@contoso.com'
};

outlook.contacts.createContact({token: token, contact: newContact, user: userInfo},
  function(error, result){
    if (error) {
      console.log('createContact returned an error: ' + error);
    }
    else if (result) {
      console.log(JSON.stringify(result, null, 2));
    }
  });

contacts.updateContact(parameters, [callback])

Update a specific contact.

Kind: static method of contacts

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
parameters.contactId string The Id of the contact.
parameters.update object The JSON-serializable update payload
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.user.timezone] string The timezone of the user.
[parameters.odataParams] object An object containing key/value pairs representing OData query parameters. See Use OData query parameters for details.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the v2.0 endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

// The Id property of the contact to update. This could be 
// from a previous call to getContacts
var contactId = 'AAMkADVhYTYwNzk...';

// Change the mobile number
var update = {
  MobilePhone1: '425-555-1212',
};

// Pass the user's email address
var userInfo = {
  email: 'sarad@contoso.com'
};

outlook.contacts.updateContact({token: token, contactId: contactId, update: update, user: userInfo},
  function(error, result){
    if (error) {
      console.log('updateContact returned an error: ' + error);
    }
    else if (result) {
      console.log(JSON.stringify(result, null, 2));
    }
  });

contacts.deleteContact(parameters, [callback])

Delete a specific contact.

Kind: static method of contacts

Param Type Description
parameters object An object containing all of the relevant parameters. Possible values:
parameters.token string The access token.
parameters.contactId string The Id of the contact.
[parameters.useMe] boolean If true, use the /Me segment instead of the /Users/<email> segment. This parameter defaults to false and is ignored if the parameters.user.email parameter isn't provided (the /Me segment is always used in this case).
[parameters.user.email] string The SMTP address of the user. If absent, the /Me segment is used in the API URL.
[parameters.user.timezone] string The timezone of the user.
[callback] function A callback function that is called when the function completes. It should have the signature function (error, result).

Example

var outlook = require('node-outlook');

// Set the API endpoint to use the v2.0 endpoint
outlook.base.setApiEndpoint('https://outlook.office.com/api/v2.0');

// This is the oAuth token 
var token = 'eyJ0eXAiOiJKV1Q...';

// The Id property of the contact to delete. This could be 
// from a previous call to getContacts
var contactId = 'AAMkADVhYTYwNzk...';

// Pass the user's email address
var userInfo = {
  email: 'sarad@contoso.com'
};

outlook.contacts.deleteContact({token: token, contactId: contactId, user: userInfo},
  function(error, result){
    if (error) {
      console.log('deleteContact returned an error: ' + error);
    }
    else if (result) {
      console.log('SUCCESS');
    }
  });