Microsoft365: Add Group Member
Add the specified user as a member of the Microsoft365 group.
Configs
  • A: OAuth2 Setting *
  • B: destination Group ID *#{EL}
  • C: User ID to add *#{EL}
  • X: Access Log (update)
Script (click to open)


// Add Microsoft365 Group Member via Microsoft Graph API v1.0 (ver. 202209)
// (c) 2022, Questetra, Inc. (the MIT License)

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

const groupId = configs.get( "conf_groupId" ) + "";
const userId  = configs.get( "conf_userId" ) + "";

const dataId_log    = configs.get( "conf_log" );

//// == Calculating ==
let requestObj = {};
  requestObj['@odata.id'] = 'https://graph.microsoft.com/v1.0/directoryObjects/' + userId;

let accessLog = "";
let uri = "https://graph.microsoft.com/v1.0/groups/" + groupId + "/members/$ref";
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}`;
}
if( dataId_log !== "" ){
  engine.setDataByNumber( dataId_log, accessLog );
}

Download

2022-10-15 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/microsoft365-group-member-add/
The Addon-import feature is available with Professional Edition
Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.

Notes

Capture

See also

%d bloggers like this: