Outlook 予定表のイベントにファイルを添付
Outlook Calendar Event Attachment Post
Outlook 予定表のイベントにファイルを添付します(1ファイルのみ、2.9MBまで)。
Configs for this Auto Step
- conf_OAuth2
- A: OAuth2 設定 *
- conf_eventId
- B: イベントID *#{EL}
- conf_attachment
- C: 添付ファイル(1ファイルのみ、2.9MBまで) *
- conf_attachmentId
- D: 添付ファイルID (更新)
- conf_log
- X: 通信ログを保存するデータ項目 (更新)
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)
(アドオン自動工程のインストールは Professional editionでのみ可能です)
Notes
- Microsoft365(Azure Active Directory)側のアプリケーション登録の方法
- Questetra 側の HTTP 認証設定の方法
- “OneDrive へクラウドワークフロー Questetra からファイル出力する方法”
- “2.2: Questetra 側の OAuth 設定”
※ただし「スコープ」はhttps://graph.microsoft.com/Calendars.ReadWrite offline_access
- “2.2: Questetra 側の OAuth 設定”
- “OneDrive へクラウドワークフロー Questetra からファイル出力する方法”
Capture
