Microsoft 365 Outlook: Calendar Event Insert
Insert an event in the Outlook Calendar. A maximum of three participants can be specified.
Configs
  • A: Set OAuth2 Config Name (at [OAuth 2.0 Setting]) *
  • B: Select STRING DATA for Event subject *
  • C: Select STRING DATA for description *
  • D: Select STRING DATA for Event location *
  • E: Select DATETIME DATA for Event Start Date *
  • F: Select DATETIME DATA for Event End Date *
  • G: Set TimeZone for Event Date (ex. Tokyo Standard Time) *
  • H: Select STRING DATA for Event Attendees1 email address *
  • I: Select STRING DATA for Event Attendees2 email address
  • J: Select STRING DATA for Event Attendees3 email address
  • X: Select STRING DATA for Access Log (update)
Script (click to open)
// Insert Outlook Calendar Event via Microsoft Graph API v1.0 (ver. 20201028)
// (c) 2020, Questetra, Inc. (the MIT License)

//// == Config Retrieving ==
const oauth2  = configs.get( "conf_OAuth2" ) + "";

const subject   = engine.findDataByNumber( configs.get( "SelectConfB" ) ) + "";
const content   = engine.findDataByNumber( configs.get( "SelectConfC" ) ) + "";
const location  = engine.findDataByNumber( configs.get( "SelectConfD" ) ) + "";
const startDate = engine.findDataByNumber( configs.get( "SelectConfE" ) ) + "";
const endDate   = engine.findDataByNumber( configs.get( "SelectConfF" ) ) + "";
const timeZone  = configs.get( "StrConfG" ) + "";

const atendee1  = engine.findDataByNumber( configs.get( "SelectConfH" ) ) + "";
//Consideration of unspecified cases
let atendee2 = "";
if (configs.get( "SelectConfI" )) {
  atendee2 = engine.findDataByNumber( configs.get( "SelectConfI" ) ) + "";
}
let atendee3 = "";
if (configs.get( "SelectConfJ" )) {
  atendee3 = engine.findDataByNumber( configs.get( "SelectConfJ" ) ) + "";
}

const dataIdX = configs.get( "conf_DataIdX" );


//// == Calculating ==
var requestObj = {};
  requestObj.subject = subject;
//Consideration of unspecified cases
  if ( content !== "null" ) {
    requestObj.body = {};
    requestObj.body.content = content;
  }
  requestObj.start = {};
  requestObj.start.dateTime = startDate;
  requestObj.start.timeZone = timeZone;
  requestObj.end = {};
  requestObj.end.dateTime = endDate;
  requestObj.end.timeZone = timeZone;
//Consideration of unspecified cases
  if ( location !== "null" ) {
    requestObj.location = {};
    requestObj.location.displayName = location;
  }
  requestObj.attendees = [];
  requestObj.attendees[0] = {};
  requestObj.attendees[0].emailAddress = {};
  requestObj.attendees[0].emailAddress.address = atendee1;
//Consideration of unspecified cases
  if ( atendee2 !== "null" ) {
    requestObj.attendees[1] = {};
    requestObj.attendees[1].emailAddress = {};
    requestObj.attendees[1].emailAddress.address = atendee2;
  }
  if ( atendee3 !== "null" ) {
    requestObj.attendees[2] = {};
    requestObj.attendees[2].emailAddress = {};
    requestObj.attendees[2].emailAddress.address = atendee3;
  }

var accessLog = "";
var token = httpClient.getOAuth2Token( oauth2 );
var uri = "https://graph.microsoft.com/v1.0/me/events";
var response = httpClient.begin()
  .bearer( token )
  .body( JSON.stringify( requestObj ), "application/json" )
  .post( uri );
accessLog += "---POST request--- " + response.getStatusCode() + "\n";
accessLog += response.getResponseAsString() + "\n";

//var statusCode = response.getStatusCode() + "";
//if( statusCode == "200" ){
//}

//// == Data Updating ==
if( dataIdX !== "" ){
  engine.setDataByNumber( dataIdX, accessLog );
}

Download



Importing add-on files is only available in Professional or Enterprise

Notes

  • Specify “https://graph.microsoft.com/calendars.readwrite offline_access” for the scope in the OAuth2 settings

Capture

See also

%d bloggers like this: