I have following PowerShell script which add event on the Office 365 group calendar. When I run the following script, it will only add the first event but not the second one. And there is no error. Have I missed anything on the script? Any help on this would be much appreciated, thank you.
$json = @"
{
"subject": "Event1",
"start": {
"timeZone": "UTC",
"dateTime": "2023-06-10T08:00"
},
"end": {
"timeZone": "UTC",
"dateTime": "2023-06-10T09:00"
}
},
{
"subject": "Event2",
"start": {
"timeZone": "UTC",
"dateTime": "2023-06-11T08:00"
},
"end": {
"timeZone": "UTC",
"dateTime": "2023-06-11T09:00"
}
}
"@
$apiUrl = "https://graph.microsoft.com/v1.0/groups/xxxx-xxxx-xxxx-xxx/events"
Invoke-RestMethod -Headers @{Authorization = "Bearer $($Tokenresponse.access_token)"} -Uri $apiUrl -Method Post -ContentType "application/json" -Body $json
3
Answers
I am getting following error
Same json works fine from https://developer.microsoft.com/en-us/graph/graph-explorer
You cannot use the Graph API to create multiple events at once, to create multiple events you have to use batching, see this link for more information:
See an example here:
The endpoint
https://graph.microsoft.com/v1.0/groups/xxxx-xxxx-xxxx-xxx/events
allows to add only one event. So the second event is ignored.Use batch endpoint