Nicholas J. Markkula
Nicholas J. Markkula

Reputation: 1562

Cross-Origin Request Blocked when accessing O365 Rest API

I'm attempting to creating a partial mail client in an asp.net mvc application. I'm not using the .net API's as I'm required to get the messages on the client side via javascript.

Unfortunately, I get the following error when attempting to get messages via an ajax request.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://outlook.office365.com/api/v1.0/me/messages. This can be fixed by moving the resource to the same domain or enabling CORS.

this is my ajax request

    jQuery.ajax({
        url: "https://outlook.office365.com/api/v1.0/me/messages",
        type: "GET",
        headers: { "Authorization": authToken },
        success: function (response) {
            debugger;
            // response
        },
        error: function (request, errorType, error) {
            debugger;
        }
    });

Any idea what i'm doing wrong here? I don't know much about CORS.

Upvotes: 2

Views: 5109

Answers (2)

Marc Charmois
Marc Charmois

Reputation: 129

Since August 2015, developers now have the option to use CORS to send requests to the Office 365 APIs to access, modify, and create data reliably.

Here is the official Microsoft documentation:

https://msdn.microsoft.com/en-us/office/office365/howto/create-web-apps-using-CORS-to-access-files-in-Office-365

And a post of mine illustrating this case with a step by step tutorial:

http://mosshowto.blogspot.fr/2015/11/embed-office-group-sharepoint-online.html

Upvotes: 0

Jason Johnston
Jason Johnston

Reputation: 17692

The Office 365 APIs explicitly don't support cross-origin resource sharing, or CORS. That's basically when a script that executes in the browser (like your AJAX request) in your web page tries to access something outside of the domain of your web page. We have it on our roadmap to support this, but I don't have a specific timeframe to share at this time.

Upvotes: 4

Related Questions