Microsoft365 ユーザID 取得
メールアドレスを指定して Microsoft365 ユーザのIDを取得します。
Configs for this Auto Step
- conf_OAuth2
- A: OAuth2 設定 *
- conf_email
- B: ユーザのメールアドレス *#{EL}
- conf_userId
- C: ユーザID(更新) *
- conf_log
- X: 通信ログを保存するデータ項目 (更新)
Script (click to open)
// Get Microsoft365 User ID via Microsoft Graph API v1.0 (ver. 202210)
// (c) 2022, Questetra, Inc. (the MIT License)
//// == 工程コンフィグの参照 / Config Retrieving ==
const oauth2 = configs.get( "conf_OAuth2" ) + "";
const email = configs.get( "conf_email" ) + "";
const dataId_userId = configs.get( "conf_userId" );
const dataId_log = configs.get( "conf_log" );
//engine.log("email:"+email);
//// == 演算 / Calculating ==
let accessLog = "";
let uri = "https://graph.microsoft.com/v1.0/users?$filter=startswith(mail,'" + email + "')";
let response = httpClient.begin()
.authSetting( oauth2 )
.get( uri );
accessLog += "---GET request--- " + response.getStatusCode() + "\n";
accessLog += response.getResponseAsString() + "\n";
//// == ワークフローデータへの代入 / Data Updating ==
const status = response.getStatusCode();
let userId = "";
if( status >= 300 ){
engine.log(accessLog);
throw `Failed in GET request. status: ${status}`;
} else {
const jsonObj = JSON.parse( response.getResponseAsString() );
const values = jsonObj.value;
for (let i = 0; i < values.length; i++) {
let value = values[i];
if (value.mail == email) {
userId = value.id;
engine.setDataByNumber( dataId_userId, userId );
}
}
}
if (userId == "") {
throw `specified user None`;
}
if( dataId_log !== "" ){
engine.setDataByNumber( dataId_log, accessLog );
}
Download
- Microsoft365-User-Id-Get-By-Email-202307.xml
- 2023-07-03 (C) Questetra, Inc. (MIT License)
(アドオン自動工程のインストールは Professional editionでのみ可能です)
Notes
- Microsoft365 系のサービスとの連携設定について
- Microsoft365(Azure Active Directory)側のアプリケーション登録の方法
- Questetra 側の HTTP 認証設定の方法
- “OneDrive へクラウドワークフロー Questetra からファイル出力する方法”
- “2.2: Questetra 側の OAuth 設定”
- ※ただし「スコープ」はhttps://graph.microsoft.com/GroupMember.Read.All offline_access もしくはhttps://graph.microsoft.com/Group.Read.All offline_access もしくはhttps://graph.microsoft.com/Directory.Read.All offline_access もしくはhttps://graph.microsoft.com/Group.ReadWrite.All offline_access もしくはhttps://graph.microsoft.com/Directory.ReadWrite.All offline_access
- “OneDrive へクラウドワークフロー Questetra からファイル出力する方法”
Capture
