I have followed proper documentation and examples. Also other methods are working fine, but message move is not working properly. Please look at below and suggest what I should change:
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/[email protected]/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
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
Finally it worked... below is the solution:
$urimove="https://graph.microsoft.com/v1.0/users/[email protected]/messages/$Id/move"
$body = @{
"destinationId" = "$folderid"
}
$body_json = $body | ConvertTo-Json
$mv = Invoke-WebRequest -Method Post -Uri $urimove -Headers $Headers -Body $body_json
Changes are: