Both the Tools for Apache Cordova and the Office 365 API Tools are extensions for Visual Studio 2013. Building a hybrid mobile app that queries data from a REST service can be hard: you’ll need to manage authentication tokens, construct REST URIs dynamically, and handle errors and retries. This code is boilerplate but is often error prone, the Office 365 APIs handle this complexity for you so you can focus on building your app. In addition to handling the complexity of REST calls, the library also provides APIs for authentication and discovery, OneDrive My Files usage, and accessing user and group information.

For example, a hybrid mobile app could easily add calendar appointments directly into a user’s Exchange calendar, send mail on behalf of the user, or directly access their files stored in OneDrive. With few lines of code, users can authenticate and access their Office 365 account.

Below, you can see how to authenticate a user and create a client object that serves as the base for accessing all the APIs from Exchange. The getIdToken method prompts for a username and password to authenticate against outlook.office365.com.

var authContext = newO365Auth.Context();

authContext.getIdToken(‘https://outlook.office365.com/’)

.then(function(token) {

// Promise callback: Authentication succeeded

client = newExchange.Client(

‘https://outlook.office365.com/ews/odata’,

token.getAccessTokenFn(‘https://outlook.office365.com’)

);

});

Using the constructed client object, you can then access all messages from the Inbox:

// Use getFolder to access Inbox folder

client.me.folders.getFolder(“Inbox”).fetch()

.then(function(folder) {

// Retrieve all the messages

folder.messages.getMessages().fetch()

.then(function(mails) {

// mails.currentPage contains all the mails in Inbox

});

});

To get contacts, simply call getContacts:

client.me.contacts.getContacts().fetch()

.then(function(contacts) {

// contacts.currentPage contains the contacts information

});

Similarly, use the getEvents method to retrieve calendar events. Here are few screenshots of our Woodgrove Demo app that uses Office 365 APIs to authenticate, fetch user’s calendar appointments and displays them in the app.