Can I move or copy messages (Office 365) using the REST API v1.0 using Powershell

China☆狼群 提交于 2019-12-25 07:19:13

问题


So far, thanks kindly to Fei Xue, I have been able to send emails using the REST API. What I would like to know is can I move emails between folders. The following reference (using V1.0) suggests I can..https://msdn.microsoft.com/en-us/office/office365/api/mail-rest-operations#Moveorcopymessages

I have put something together but its not working. The IDs represent the message ID and the destination folder ID

$contentType = "application/json"
$uri = "https://outlook.office365.com/api/v1.0/me/messages/AAMkADRjZmU1Njg3LWU1MTgtNDRlYS1hM2JjLThjYzVlYTNiYjI2NQBGAAAAAACnOSYQcbEERIZTVx5HtMm9BwDzVgO1bziCQLdugqQvOwrTAEVv8cxtAACxp0cQeSQxTYONMj3glZFxAAIF_5u4AAA=?/move"

$body = @{
DestinationID = "AAMkADRjZmU1Njg3LWU1MTgtNDRlYS1hM2JjLThjYzVlYTNiYjI2NQAuAAAAAACnOSYQcbEERIZTVx5HtMm9AQCxp0cQeSQxTYONMj3glZFxAAGmgyRMAAA="
}
$json = $body | ConvertTo-Json
Invoke-RestMethod -Uri $uri -Method Post -Credential $cred -Body $json -ContentType $contentType

Since I can send emails, I would have thought I can move them..?


回答1:


What's the error message you got? Based on the request, it seems that the $uri is not correct. The message id shouldn't contain the ?.

Here is an request works welll for your reference:

$body="{""DestinationId"":""AQMkADQyZjE2NzY3LWEyNjEtNGI3NwAtOWJhOS1jN2I5NTdkYmY4NmEALgAAA6N9fgB38JpAkbQ1i6fbzV8BAL3QnQZrC1lNpUx8h1pAnzAAAAIBCgAAAA==""}

Invoke-RestMethod -Method post -uri "https://outlook.office365.com/api/v1.0/me/messages/AAMkADQyZjE2NzY3LWEyNjEtNGI3Ny05YmE5LWM3Yjk1N2RiZjg2YQBGAAAAAACjfX4Ad-CaQJG0NYun281fBwC90J0GawtZTaVMfIdaQJ8wAAAAAAEMAAC90J0GawtZTaVMfIdaQJ8wAAFYk-FGAAA=/move" -Credential $cred -Body $body -ContentType "application/json"


来源:https://stackoverflow.com/questions/38214292/can-i-move-or-copy-messages-office-365-using-the-rest-api-v1-0-using-powershel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!