I had the below Powershell working perfectly until last November the 1st.
$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
I get the below error: Invoke-RestMethod : The remote server returned an error: (400) Bad Request. At 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
Per my investigation; I know its not credential issues; I think they changed their API.
Running the same script with Fiddler capturing traffic I found the body of the error response was:
The date looked like the problem. Changing your second line to the following fixed the problem: