Outlook Calendar Event Attachment Post
Posts an attachment to an Outlook Calendar Event (1 file only, up to 2.9MB). You can specify the target by the event ID. The ID of the attachment can be saved.
Configs for this Auto Step
- conf_OAuth2
- A: OAuth 2.0 Setting *
- conf_eventId
- B: Event Id *#{EL}
- conf_attachment
- C: Attachment File (1 file only, up to 2.9MB) *
- conf_attachmentId
- D: Attachment File Id (update)
- conf_log
- X: Access Log (update)
Script (click to open)
// Post Outlook Calendar Event Attachment via Microsoft Graph API v1.0 (ver. 202209)
// (c) 2023, Questetra, Inc. (the MIT License)
//// == 工程コンフィグの参照 / Config Retrieving ==
const oauth2 = configs.get( "conf_OAuth2" ) + "";
const eventId = configs.get( "conf_eventId" ) + "";
const files = engine.findDataByNumber( configs.get( "conf_attachment" ) );
const dataId_attachmentId = configs.get( "conf_attachmentId" );
const dataId_log = configs.get( "conf_log" );
//// == 演算 / Calculating ==
if( eventId == "" ){
throw `Event ID none.`;
}
if( !files ){
throw `File none.`;
}
const file = files.get(0);
//ファイルサイズ確認
// API仕様的には3MBまで、ファイルだけでなくペイロード全体での制限、余裕をみて2.9MBまでとする
// https://learn.microsoft.com/ja-jp/graph/api/event-post-attachments?view=graph-rest-1.0&tabs=javascript
if (file.getLength() > 3040871) {
throw `File size over.`;
}
let fileData = "";
fileRepository.readFile(file, 3145728, function(bytes) {
fileData = base64.encodeToString(bytes);
});
let requestObj = {};
requestObj['@odata.type'] = '#microsoft.graph.fileAttachment';
requestObj.name = file.getName();
requestObj.contentBytes = fileData;
//engine.log("json:" + JSON.stringify( requestObj ));
let accessLog = "";
let uri = "https://graph.microsoft.com/v1.0/me/events/" + eventId + "/attachments";
let response = httpClient.begin()
.authSetting( oauth2 )
.body( JSON.stringify( requestObj ), "application/json" )
.post( uri );
accessLog += "---POST request--- " + response.getStatusCode() + "\n";
accessLog += response.getResponseAsString() + "\n";
//// == ワークフローデータへの代入 / Data Updating ==
const status = response.getStatusCode();
if( status >= 300 ){
engine.log(accessLog);
throw `Failed in POST request. status: ${status}`;
} else {
const jsonObj = JSON.parse( response.getResponseAsString() );
const attachmentId = jsonObj.id + "";
if( dataId_attachmentId !== "" ){
engine.setDataByNumber( dataId_attachmentId, attachmentId );
}
}
if( dataId_log !== "" ){
engine.setDataByNumber( dataId_log, accessLog );
}
Download
- Outlook-Calendar-Event-Attachment-Post-202307.xml
- 2023-07-03 (C) Questetra, Inc. (MIT License)
(Installing Addon Auto-Steps are available only on the Professional edition.)
Notes
- How to register applications on the Microsoft 365 (Azure Active Directory) side
- How to Setup HTTP Authentication on the Questetra side
- “How to Output Files from Cloud-based Workflow Questetra to OneDrive”
- 2.2: OAuth settings on the Questetra side
※ However, the scope is https://graph.microsoft.com/Calendars.ReadWrite offline_access
- 2.2: OAuth settings on the Questetra side
- “How to Output Files from Cloud-based Workflow Questetra to OneDrive”
Capture
