question

ALEXANDROCRUZRINCON-7021 avatar image
0 Votes"
ALEXANDROCRUZRINCON-7021 asked ·

Create Multiple events in calendar - Microsoft Graph REST API

Hi

I am currently creating events on my clients' calendars using the Microsoft Graph REST API.

Everything has been perfect, however when I want to create 2 different events on the same calendar I have to do the same process 2 times.
Currently to create an event I do this:

POST https://graph.microsoft.com/v1.0/me/calendars/AAMkAGViNDU7zAAAAAGtlAAA=/events
Content-type: application/json

{
"subject": "Let's go for lunch",
"body": {
"contentType": "HTML",
"content": "Does mid month work for you?"
},
"start": {
"dateTime": "2019-03-15T12:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2019-03-15T14:00:00",
"timeZone": "Pacific Standard Time"
},
"location":{
"displayName":"Harry's Bar"
},
"attendees": [
{
"emailAddress": {
"address":"adelev@contoso.onmicrosoft.com",
"name": "Adele Vance"
},
"type": "required"
}
]
}

But when you sent more than one event on the same request it only creates the last event in the array for me.


POST https://graph.microsoft.com/v1.0/me/calendars/AAMkAGViNDU7zAAAAAGtlAAA=/events
Content-type: application/json

{
"subject": "Let's go for lunch",
"body": {
"contentType": "HTML",
"content": "Does mid month work for you?"
},
"start": {
"dateTime": "2019-03-15T12:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2019-03-15T14:00:00",
"timeZone": "Pacific Standard Time"
},
"location":{
"displayName":"Harry's Bar"
},
"attendees": [
{
"emailAddress": {
"address":"adelev@contoso.onmicrosoft.com",
"name": "Adele Vance"
},
"type": "required"
}
]
},
{
"subject": "Let's go for lunch 2",
"body": {
"contentType": "HTML",
"content": "Does mid month work for you?"
},
"start": {
"dateTime": "2019-03-15T12:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2019-03-15T14:00:00",
"timeZone": "Pacific Standard Time"
},
"location":{
"displayName":"Harry's Bar"
},
"attendees": [
{
"emailAddress": {
"address":"adelev@contoso.onmicrosoft.com",
"name": "Adele Vance"
},
"type": "required"
}
]
},
{
"subject": "Let's go for lunch 3",
"body": {
"contentType": "HTML",
"content": "Does mid month work for you?"
},
"start": {
"dateTime": "2019-03-15T12:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2019-03-15T14:00:00",
"timeZone": "Pacific Standard Time"
},
"location":{
"displayName":"Harry's Bar"
},
"attendees": [
{
"emailAddress": {
"address":"adelev@contoso.onmicrosoft.com",
"name": "Adele Vance"
},
"type": "required"
}
]
}


Can someone tell me what I'm doing wrong?
the api allows creating multiple events in the same calendar in a single call?

I hope someone can help me, thanks.

azure-active-directory
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

nfd avatar image
0 Votes"
nfd answered ·

Hi,

You cannot use the Graph REST API to create multiple events at once, for this you need to use batching.
This is explained here: https://docs.microsoft.com/en-us/graph/json-batching

So you should call the following endpoint:
POST https://graph.microsoft.com/v1.0/$batch Content-type: application/json

For your example the body would be as follows:

 {
   "requests": [
     {
       "id": "1",
       "method": "POST",
       "url": "/me/calendars/AAMkAGViNDU7zAAAAAGtlAAA=/events",
       "body": {
         "subject": "Let's go for lunch",
         "body": {
           "contentType": "HTML",
           "content": "Does mid month work for you?"
         },
         "start": {
           "dateTime": "2019-03-15T12:00:00",
           "timeZone": "Pacific Standard Time"
         },
         "end": {
           "dateTime": "2019-03-15T14:00:00",
           "timeZone": "Pacific Standard Time"
         },
         "location": {
           "displayName": "Harry's Bar"
         },
         "attendees": [
           {
             "emailAddress": {
               "address": "adelev@contoso.onmicrosoft.com",
               "name": "Adele Vance"
             },
             "type": "required"
           }
         ]
       },
       "headers": {
         "Content-Type": "application/json"
       }
     },
     {
       "id": "2",
       "method": "POST",
       "url": "/me/calendars/AAMkAGViNDU7zAAAAAGtlAAA=/events",
       "body": {
         "subject": "Let's go for lunch 2",
         "body": {
           "contentType": "HTML",
           "content": "Does mid month work for you?"
         },
         "start": {
           "dateTime": "2019-03-15T12:00:00",
           "timeZone": "Pacific Standard Time"
         },
         "end": {
           "dateTime": "2019-03-15T14:00:00",
           "timeZone": "Pacific Standard Time"
         },
         "location": {
           "displayName": "Harry's Bar"
         },
         "attendees": [
           {
             "emailAddress": {
               "address": "adelev@contoso.onmicrosoft.com",
               "name": "Adele Vance"
             },
             "type": "required"
           }
         ]
       },
       "headers": {
         "Content-Type": "application/json"
       }
     },
     {
       "id": "3",
       "method": "POST",
       "url": "/me/calendars/AAMkAGViNDU7zAAAAAGtlAAA=/events",
       "body": {
         "subject": "Let's go for lunch 3",
         "body": {
           "contentType": "HTML",
           "content": "Does mid month work for you?"
         },
         "start": {
           "dateTime": "2019-03-15T12:00:00",
           "timeZone": "Pacific Standard Time"
         },
         "end": {
           "dateTime": "2019-03-15T14:00:00",
           "timeZone": "Pacific Standard Time"
         },
         "location": {
           "displayName": "Harry's Bar"
         },
         "attendees": [
           {
             "emailAddress": {
               "address": "adelev@contoso.onmicrosoft.com",
               "name": "Adele Vance"
             },
             "type": "required"
           }
         ]
       },
       "headers": {
         "Content-Type": "application/json"
       }
     }
   ]
 }


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.