Skip to content

Instantly share code, notes, and snippets.

@nbellocam
Last active February 6, 2018 17:45
Show Gist options
  • Save nbellocam/e79f0c858610912733292e546df11317 to your computer and use it in GitHub Desktop.
Save nbellocam/e79f0c858610912733292e546df11317 to your computer and use it in GitHub Desktop.
Calling Microsoft Graph API from an Azure Function using JavaScript - createGroup Function
var request = require('request');
function createGroup(token, name) {
return new Promise((resolve, reject) => {
const options = {
method: 'POST',
url: 'https://graph.microsoft.com/v1.0/groups/',
headers: {
'Authorization': 'Bearer ' + token,
'content-type': 'application/json'
},
body: JSON.stringify({
"displayName": name,
"mailEnabled": false,
"securityEnabled": true
})
};
request(options, (error, response, body) => {
const result = JSON.parse(body);
if (!error && response.statusCode == 204) {
resolve(result.value);
} else {
reject(result);
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment