MS Graph API 消息移动 - 415 不支持的媒体类型

MS Graph API message move - 415 unsupported media type

我遵循了正确的文档和示例。其他方法也可以正常工作,但消息移动无法正常工作。请看下面并提出我应该更改的内容:

PS C:\> $body = @{
>>   "destinationId" = "$folderid"   
>> }
## Note: I have tried well known folder types also like deleteditems
PS C:\> $body

Name                           Value
----                           -----
destinationId                  AAMkADIzYjU1MDg4LWIzOTAtNDVhYi1iNjczLTdlNjBiMjExMGE3MwAuAAAAAAAMiK_sOzYGRJ9qF2G24SoEA...


$urimove="https://graph.microsoft.com/v1.0/users/mymailbox@xyz.com/messages/$conv/move"

$body = @{
  "destinationId" = "$folderid"
}

$mv = Invoke-WebRequest -Method Post -Uri $urimove -ContentType "application/x-www-form-urlencoded" -Headers $Headers -Body $body

### if I change above -ContentType "application/x-www-form-urlencoded" to "application/json", I start getting 400 bad request error

错误:

Invoke-WebRequest : The remote server returned an error: (415) Unsupported Media Type.
At line:1 char:1
+ Invoke-WebRequest -Method Post -Uri $urimove -ContentType "applicatio ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

终于成功了...下面是解决方案:

$urimove="https://graph.microsoft.com/v1.0/users/mailbox@domain.com/messages/$Id/move"

$body = @{
  "destinationId" = "$folderid"
}

$body_json = $body | ConvertTo-Json

$mv = Invoke-WebRequest -Method Post -Uri $urimove -Headers $Headers -Body $body_json

变化是:

  1. body应该是body_json如上图
  2. 请求调用中没有content-type
  3. content-type 应该在 headers 中并且等于 application/json