0

I'am developing a Outlook Web Add-In using Microsoft Graph REST API v1.0. After a lot of searches include Microsoft's documentations and finally able to authorize and get 'access_token' using the Add-In, but badly stuck to get user's 'calendar' and also 'calendar events' include recurring events using the bellow code

 //// for all calendar label
 var _token="xyz..123";
 $.ajax({
    url: "https://graph.microsoft.com/v1.0/me/calendars",
    headers: {
        'outlook.body-content-type': 'text/html',
        'Authorization': 'Bearer ' + token
    },
    type: 'GET'
}).done(function (data) {
    //// success
}).fail(function (error) {
    //// error
});


//// for calendar events
var _token="xyz..123";
 $.ajax({
    url: "https://graph.microsoft.com/v1.0/me/calendar/events",
    headers: {
        'outlook.body-content-type': 'text/html',
        'Authorization': 'Bearer ' + token
    },
    type: 'GET'
}).done(function (data) {
    //// success
}).fail(function (error) {
    //// error
});

ref : https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/user_list_events

I'am getting this error in response

{
"error": {
    "code": "InvalidAuthenticationToken",
    "message": "CompactToken parsing failed with error code: 80049217",
    "innerError": {
        "request-id": "55ea48c0-5d10-423b-9f41-d48d5b1d9454",
        "date": "2018-10-01T14:41:05"
      }
   }
}

Please point me out where I'm doing wrong? Thanks

UPDATE

As suggested by @Lina I tried this method and switch to Outlook REST API v2.0

Office.context.mailbox.getCallbackTokenAsync({ isRest: true }, function (result) {
    if (result.status === "succeeded") {
        var accessToken = result.value;
        // Use the access token
    } else {
        // Handle the error
    }
});

got the accessToken = "123..abc"; After that I tried to access calendar and events in this way

// get calendars
$.ajax({
    url: 'https://outlook.office.com/api/v2.0/me/calendars' ,
    dataType: 'json',
    headers: { 'Authorization':'Bearer ' +access_token}
  }).done(function (items) {
    //sucess;
  }).fail(function (error) {
    //error
});

// get events
$.ajax({
    url: 'https://outlook.office.com/api/v2.0/me/events' ,
    dataType: 'json',
    headers: { 'Authorization':'Bearer ' +access_token}
  }).done(function (items) {
    //sucess;
  }).fail(function (error) {
    //error
});

In the above both request I got this error

"{"error":{"code":"ErrorAccessDenied","message":"The api you are trying to access does not support item scoped OAuth."}}"

related:Access to Outlook RestAPI from an Outlook web Add-in

Help me out what I'm missing. Is there any 'permission' or 'parameters'issue? Thanks

  • Which method does your 'access_token' use to get it? – Lina Oct 02 '18 at 02:07
  • @Lina I'm using https://login.microsoftonline.com//oauth2/token – Sourav Kuila Oct 02 '18 at 08:20
  • Where do you sign up for the App? Please refer to the link:[Office Outlook Add-In OAuth Error](https://stackoverflow.com/questions/37521844/office-outlook-add-in-oauth-error) – Lina Oct 05 '18 at 07:22
  • @Lina thanks for your reply. According to your ref. link I've also noticed token using 'getCallbackTokenAsync' and OAuth token are different but I have already mentioned I'am developing a Outlook Web Add-In so users are already logged In with their credential and I'm able to read their mailbox. My concern is that without re-login is their any possible ways to get users 'calendars' and 'calendar events'. – Sourav Kuila Oct 08 '18 at 05:20

1 Answers1

0

If you use the getAccessTokenAsync method to get the 'access_token', you should use the request shown below:

Get a collection of series master and single instance events from the user's primary calendar (../me/events) or from a different calendar. To get expanded event instances, you can get the calendar view or get the instances of an event.

GET https://outlook.office.com/api/v2.0/me/events
GET https://outlook.office.com/api/v2.0/me/calendars/{calendar_id}/events

For more information, please see the link below:

Using the Calendar REST API

Lina
  • 261
  • 1
  • 4