1
votes

I downloaded the NodeJS code available at https://github.com/microsoftgraph/nodejs-apponlytoken-rest-sample and granted all permissions as required (Read and write calendars in all mailboxes and Read directory data application permissions in Microsoft Graph Application permissions).

I can successfully acquire all users that were added to Azure AD, but I'm not able to get any of their calendar information or create an event (which is the original code in the sample). All calls that I make return the following error:

'{\r\n "error": {\r\n "code": "UnknownError",\r\n "message": "",\r\n "innerError": {\r\n "request-id": "1fd8568b-b4a3-4168-a835-c389eb783890",\r\n "date": "2016-07-14T18:08:41"\r\n }\r\n }\r\n}' }

It may be important to note that my office 365 domain is not the same as the domain in the Azure AD account, although my office 365 administrator is the administrator of the Azure AD account. I don't know if that is the normal behavior and I should manually add my office 365 users to Azure AD with their Microsoft accounts (which I also created) or it may be the cause for this error.

My goal is to check if the users are free (no meeting in their calendars) in a specific period of time, which it seems to be possible according to Microsoft Graph API: can't list recurring events of a meeting room using the calendarView call.

I appreciate any help. Thanks.

1

1 Answers

0
votes

It may be important to note that my office 365 domain is not the same as the domain in the Azure AD account, although my office 365 administrator is the administrator of the Azure AD account. I don't know if that is the normal behavior and I should manually add my office 365 users to Azure AD with their Microsoft accounts (which I also created) or it may be the cause for this error.

When we use the client credential flow to authenticate for the app, it used the client Id and Client Secret. It is normal that we associate the Office 365 account with Azure AD account and it will not affect us to authenticate the app. But you need to make sure you registered the app on the Office 365 directory instead of Azure AD directory so that the users on the directory have the licences to use the Exchange online.

To get the detail error message, we can use the Fiddler to track the Http request. And to enable the Fiddler to capture the Http request from Node.js, we need to use the proxy. You can add the code to Graph.js:

var requestO = require('request');
var Q = require('q');

var request = requestO.defaults({ "proxy": "http://127.0.0.1:8888"});

You can also get the Access token in app.js using code below:

// Get an access token for the app.
auth.getAccessToken().then(function (token) {
    var users = [{"id":"userId","displayName":"displayName"}];
    console.log(token);
    graph.createEvent(token, users)
    console.log("create event finished...")

}, function (error) {
    console.error('>>> Error getting access token: ' + error);
});

Then you can use this token to test the Microsoft Graph REST API to find the root reason for this issue.