Forum Discussion
Exchange Online REST API
REST is enabled by default. Are you providing an access token as part of the request? Do you have the necessary permissions to access the endpoint you are trying to (assuming you are using /user@domain.com/contacts)?
Hello,
I tried it with:
iwr "https://outlook.office.com/api/v2.0/me/calendarview?startDateTime=2018-05-01T01:00:00&endDateTime=2018-10-31T23:00:00" -Credential $(Get-Credential)
And the result is:
iwr : The remote server returned an error: (403) Forbidden.
At line:1 char:1
+ iwr "https://outlook.office.com/api/v2.0/me/calendarview?startDateTim ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Regards,
Martin
- VasilMichevMay 16, 2018MVP
You cannot pass credentials directly. You need to get a token and pass that token via an auth header. The documentation on that is here: https://docs.microsoft.com/en-us/outlook/rest/get-started
- KrisVJan 15, 2019Copper Contributor
Hi i am trying to access a functional email box messages using the outlook API 2.0 using my credentials using the below line. i get a Forbidden 403 error. my intention is to search for a certain subject in the functional email box and download the attachment. Pls let me know what should i check from my side.
$mail =
Invoke-RestMethod -Headers @{Authorization =("Bearer "+ $Authorization.access_token)}`
-Uri https://outlook.office.com/api/v2.0/users/retailoperations@domain.com/messages `
-Method GetThe below one works for accessing my email inbox.
$mail =
Invoke-RestMethod -Headers @{Authorization =("Bearer "+ $Authorization.access_token)}`
-Uri https://outlook.office.com/api/v2.0/me/messages `
-Method Get- VasilMichevJan 15, 2019MVP
Since you are accessing other people's messages, you need the relevant permissions - either Full Access permissions on their mailbox, or a corresponding API-level permissions via the app you are getting the token for.