I'm trying to figure out how to create a calendar event using the Microsoft Graph JavaScript Client.
I've managed to retrieve the necessary accessToken
and can interact with the API (i.e. retrieve events, calendars, top 10 e-mails), but I'm not sure of how to use the API to create an event.
client
.api('/me/events')
.header('X-AnchorMailbox', emailAddress)
Do I use post to send the event json object?
I suggest reviewing the Read Medocumentation for details on how to use this library.
To answer your question, you need to create a an Event object. For example:
var event = {
"subject": "Let's go for lunch",
"body": {
"contentType": "HTML",
"content": "Does late morning work for you?"
},
"start": {
"dateTime": "2017-04-15T12:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2017-04-15T14:00:00",
"timeZone": "Pacific Standard Time"
},
"location": {
"displayName": "Harry's Bar"
},
"attendees": [{
"emailAddress": {
"address": "samanthab@contoso.onmicrosoft.com",
"name": "Samantha Booth"
},
"type": "required"
}]
}
You then need to .post
this object to the /events
endpoint:
client
.api('/me/events')
.post(event, (err, res) => {
console.log(res)
})