简体   繁体   中英

Microsoft Exchange REST API write calendar event with POST from Powershell

I tried to access the calendars of my Exchange 2016 CU5 environment via REST-API using Powershell. GET methods are working fine with no errors, but now I tried to write a calendar event with POST method and it won't work. Here's my code:

$cred = Get-Credential

$url = "https://myexchangeserver.de/api/v2.0/me/events"

$content = "application/json"

$body = "{
  ""Event"": {
  ""Subject"": ""Testtermin REST"",
  ""Body"": {
    ""ContentType"": ""HTML"",
    ""Content"":""Testtermin REST""
  },
  ""Start"": {
  ""DateTime"": ""2017-10-10T16:00:00"",
  ""TimeZone"": ""Europe/Berlin""
  },
  ""End"": {
  ""DateTime"": ""2017-10-10T16:30:00"",
  ""TimeZone"": ""Europe/Berlin""
  },
  ""Attendees"": [
{
  ""EmailAddress"": {
    ""Address"": ""otto.outlooktest@hft-stuttgart.de"",
    ""Name"": ""Otto Outlooktest""
  },
  ""Type"": ""Required""
}
  ]
}}"

Invoke-RestMethod -Uri $url -Method Post -Credential $cred -ContentType $content -Body $body

I put this into a .ps1 file and execute it within my Exchange Management Shell.

It opens a popup-windows to let me enter my credentials, but afterwards I always get a error message "400 invalid request".

I already tried several writings, but always the same.

Anyone got a idea what's wrong?

Greetings, Michael

I would suggest you get rid of Event: as that isn't need (eg just check any of the documentation samples or Graph Explorer samples). Also if you use fiddler to capture one of your requests and look at the full response that comes back from the server it will generally tell you what in particular is wrong with the request that is being sent.

I solved it. The REST API doesn't like IANA Timezones. Instead of "Europe/Berlin" I put in "W. Europe Standard Time". Greetings, Michael

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM