0
votes

There is a need to capture the outlook calendar events from a SharePoint online site. For that I am using rest API. To capture the events, i have created an application in outlook Dev center. By using this client id, I am able to Authorize the user and get the response authorized code. but I cannot able to get the Access token using that client id,client secret. It throws an "Unauthorized client, The application xxx is not not supported for the API version" error.I also get the same error in Postman API. However i am able to get the calendar events while trying in "oAuth SandBox" (https://oauthplay.azurewebsites.net/) i can able to get the events. I have a content editor in my sharepoint online site to get the Access token. The following is the code i used in content editor,

jQuery.ajax({ url: "//outlook.office365.com/common/oauth2/token", type: "post", headers:{ "Content-Type":"application/x-www-form-urlencoded" }, data: { grant_type: "authorization_code", code: myaccesscode, client_id: myclientID, client_secret: myclientsecret, redirect_uri:"https://myredirecturl" }, success: function(response){ alert(response); } Fail: function(status.err) { alert("Fail"); } });

Thanks in advance.

2

2 Answers

0
votes

I found the solution. To get Outlook Calendar events need to done the following steps: 1. Get Access Code 2. Get Access Token using the access code obtained in above step. 3. Get the events by passing the Access token obtained in step 2 as Authorization header.

0
votes

Once you get a Access Code, you can use the below code.

function GetEvents(token) {            
        var call = $.ajax({
            url: "https://outlook.office.com/api/v2.0/me/events",
            type: "GET",
            dataType: "json",
            headers: {
                Accept: "application/json;odata.metadata=minimal;odata.streaming=true",
                'Authorization': "Bearer " + token
            },
            success: function (data) {                   
               //Success Call back
            },
            error: function (xhr) {
               //error call back
            }
        });
    }