Created
February 6, 2018 18:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
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