[Solved] Microsoft GraphAPI / Powershell: How do i create multiple PUTS with Graph over Powershell?

ocm Asks: Microsoft GraphAPI / Powershell: How do i create multiple PUTS with Graph over Powershell?
i am basically new with the GraphAPI (and “coding” in general) and i have a task i need to accomplish. I need to add multiple Events on other Users Calendars over Powershell. I have managed to enter one event to one users calendar. But i cant get past the one event and add more of them…i did read about the batching with the GraphAPI, but i dont get it.

Code:
 #Variables
$ClientID = "x*x*x*x"
$ClientSecret = "x*x*x*x"
$tenantID = "x*x*x*x"
$scope = "https://graph.microsoft.com/.default"
$authority = "https://login.microsoftonline.com/$tenantID/oauth2/v2.0/token"

$Body = @{
  "grant_type"    = "client_credentials";
  "client_id"     = "$ClientID";
  "client_secret" = "$ClientSecret";
  "scope"      = "$scope";
}

#Get AccessToken
$result = Invoke-RestMethod -Method POST -uri $authority -Body $body
$AccessToken = $result.access_token

#Create Event
$mailbox = "user@domain.com"
$headers = @{
 "Authorization" = "Bearer "+ $AccessToken;
 "Prefer" = 'outlook.timezone="W. Europe Standard Time"';
 "Content-type"  = "application/json"
}

#Create JSON Object
$json = @"
{
  "subject":"Event over Graph API",
  "body": {
    "contentType" : "HTML",
    "content" : "Write Graph API Powershell Script"
  },
  "start": {
      "dateTime" : "2021-07-23T00:00:00",
      "timeZone" : "W. Europe Standard Time"
  },
  "end": {
      "dateTime" : "2021-07-24T00:00:00",
      "timeZone" : "W. Europe Standard Time"
  },
  "location":{
      "displayName" : "HomeOffice"
  }
}
"@

$uri = "https://graph.microsoft.com/v1.0/users/$Mailbox/calendar/events"
Invoke-RestMethod -Method POST -Uri $uri -Headers $headers -Body $json

I just found this online and tested it so, S/O to the creator.

Thank you in Advance for any help or input.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.