powershell https://outlook.office365.com/api/v1.0/me/messages

时间:2017-01-05 16:32:52

标签: api powershell outlook office365api

我在下面的Powershell工作完美,直到去年11月1日。

$url = "https://outlook.office365.com/api/v1.0/me/messages" 
$date = Get-Date -Format "yyyy-MM-d"

## Get all messages that have attachments where received date is greater than $date  
$messageQuery = "" + $url + "?`$select=Id&`$filter=HasAttachments eq true and DateTimeReceived ge " + $date 
$messages = Invoke-RestMethod $messageQuery -Credential $cred 

我收到以下错误: Invoke-RestMethod:远程服务器返回错误:(400)错误请求。 在G:\ Powell \ AutoetForO.ps1:23 char:13 + $ messages = Invoke-RestMethod $ messageQuery -Credential $ cred + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo:InvalidOperation:(System.Net.HttpWebRequest:HttpWebRequest)[Invoke-RestMethod],WebException     + FullyQualifiedErrorId:WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

根据我的调查;我知道它不是凭证问题;我认为他们改变了他们的API。

1 个答案:

答案 0 :(得分:1)

使用Fiddler捕获流量运行相同的脚本我发现错误响应的主体是:

92
{"error":{"code":"RequestBroker-ParseUri","message":"Syntax error at position 54 in 'HasAttachments eq true and DateTimeReceived ge 2017-01-5'."}}
0

日期看起来像问题。将第二行更改为以下内容可解决问题:

$date = Get-Date -Format "yyyy-MM-dd"