Exchange Online REST API

Copper Contributor

Hello,

 

I want to use the REST-API from my Exchange Online account to edit the calendar entries.

When I try to connect with "invoke-webrequest" I get an error 403.

 

Where can I enable the API for my account in Exchange Online settings?

 

Regards,
Martin

5 Replies

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

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

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 Get

 

The 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

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.