Office 365创建草稿回复邮件rest API

时间:2016-11-28 14:13:04

标签: office365

对于Office 365,根据Office 365文档创建草稿回复邮件rest API'/ messages / {message_id} / createreply'所需的请求正文参数为'comment'。

Office 365 create draft reply message

我尝试使用'POST / messages / {message_id} / createreply'API创建草稿回复,其中有效负载为:

{   “评论”:“范妮,兰迪,如果项目获得批准,你会给小组起名吗?” }

API提供以下错误:

{   “错误”:{     “code”:“RequestBodyRead”,     “message”:“请求有效负载中的参数'Comment'不是'CreateReply'操作的有效参数。”   } }

我正在做什么,或者这是Office 365创建草稿回复API的已知问题?

1 个答案:

答案 0 :(得分:0)

我认为创建草稿回复API不存在任何问题。 我能够使用我在租户中注册的Native Client(已注册mail.readwrite作用域)和使用ADAL执行身份验证和REST调用的PowerShell脚本来测试此API调用。

以下是该脚本:

Add-Type -Path "..\ADAL\Microsoft.IdentityModel.Clients.ActiveDirectory.dll";

$output = ".\Output.txt"
$accessToken = ".\Token.txt"

$clientId = "<AppID>";
$tenantId = "<Tenant or Common>";
$resourceId = "https://outlook.office.com"
$redirectUri = new-object System.Uri("<Reply URL>")
$login = "https://login.microsoftonline.com"

$authContext = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext @(("{0}/{1}" -f $login,$tenantId), $false);

$authenticationResult = $authContext.AcquireToken($resourceId,$clientID,$redirectUri);

($token = $authenticationResult.AccessToken) | Out-File $accessToken


$headers = @{ 
    "Authorization" = ("Bearer {0}" -f $token);
    "Content-Type" = "application/json";
}

$body = @{
    Comment= 'This is my comment'
}

$bodyJSON = $body | ConvertTo-Json

Invoke-RestMethod -Method Post -Uri ("{0}/api/beta/me/messages/<message id>/createreply" -f $resourceId) -Headers $headers -Body $bodyJSON -OutFile $output

我能够通过此代码从API获得有效的响应。我有点犹豫要分享我的输出,我真的不知道什么是敏感的,什么不是,但我相信错误来自你的代码正在制定你的POST请求的方式。你能分享你的代码吗?

我希望这有帮助!