Create Multiple events in calendar - Microsoft Graph REST API

ALEXANDRO CRUZ RINCON 1 Reputation point
2020-04-09T19:57:05.477+00:00

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@Company portal .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@Company portal .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@Company portal .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@Company portal .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.

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,582 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Nick F 1 Reputation point
    2020-04-13T00:26:55.217+00:00

    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://learn.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"  
          }  
        }  
      ]  
    }  
    
    0 comments No comments