Skip to content

Instantly share code, notes, and snippets.

@nbellocam
Created February 6, 2018 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbellocam/640552babdf6b3d0fd1c786b80c911aa to your computer and use it in GitHub Desktop.
Save nbellocam/640552babdf6b3d0fd1c786b80c911aa to your computer and use it in GitHub Desktop.
Calling Microsoft Graph API from an Azure Function using JavaScript - Azure Function code
// ...
module.exports = function (context, req) {
context.log('Starting function');
if (req.query.name) {
const name = req.query.name;
context.log('Parameters OK. Next: get token');
getToken().then(token => {
context.log('Token OK. Next: create the group');
createGroup(token, name)
.then(result => {
context.log('Everything OK.');
context.res = {
status: 200,
body: JSON.stringify(result),
headers: {
'Content-Type': 'application/json'
}
};
context.done();
}).catch(() => {
context.log('An error occurred while creating the group');
context.done();
});
});
} else {
context.res = {
status: 400,
body: "Please pass a name on the query string"
};
context.done();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment