Office 365 APIs and – Outlook and Exchange dev blog

The official Microsoft blog for Outlook, Exchange developers for both On-Premises and Office 365

UPDATE: The node-outlook library that is discussed ter this postbode has bot updated with a fresh interface that does not use the Cordova library and is much simpler to use. It’s recommended that fresh apps use the newer interface. The tutorial linked at the end of the article has bot updated to use the newer interface.

When wij launched the Office 365 APIs, the Visual Studio folks released some very helpful client-side implementations of thesis APIs, making it much lighter to get commenced. One of thesis implementations, the Microsoft Office 365 APIs Client Libraries for Cordova Applications, got a loterijlot of attention from JavaScript developers. However, there wasgoed some confusion about the library and what it wasgoed designed to do. Spil the name suggests, this library wasgoed created to be used ter applications built on the Cordova podium, and more specifically, for Multi-Device Hybrid App projects te Visual Studio. Developers who attempted using it ter a web app soon ran into issues. It just wouldn’t work.

With all of the rente ter using this library from a web app, when I wasgoed asked if wij could modify the library to make it work ter Knot.js, I said “why not?”

Finding the problem

Spil it turns out, the big stumbling block is that the library uses the AJAX XMLHttpRequest object to send API requests. AJAX is all client-side, and not available to server-side platforms like Knot.js. So it makes sense that it doesn’t work ter web apps.

The solution

Fortunately, someone clever already provided a solution for this. The XMLHttpRequest for knot.js module sounds like exactly what wij need! If wij can use this, wij can avoid having to switch the Cordova library much at all.

With that out of the way, the question left is how to explosion this non-Node module. Spil before, someone clever has already found the solution to that. With this trick ter my toolbox, I determined to write a Knot module to wrap the Cordova libraries (to be specific, just the Mail, Calendar, and Contacts APIs).

The node-outlook module

The code for the module wasgoed exceptionally plain. All I needed to do wasgoed create an index.js verkeersopstopping and waterput the following te it:

The exchange.js and utility.js files were copied straight from the Cordova library NuGet package. Pretty plain right? Well, it’s even simpler now! I published node-outlook on the NPM registry, so you can save yourself the hassle and install via NPM. Or if you choose, get the code on GitHub.

Using node-outlook

For a total sample that uses this library, check out node-mail. I’ll voorkant the basic requirements here.

Te order to use the library, you need to implement a callback function that comes back an OAuth2 access token. The OutlookServices.Client class takes this callback spil a parameter to its constructor. Whenever the client class makes a call to the Office 365 service, it calls this function to get the token. How you implement the callback will depend on how you’re storing and managing tokens. Spil an example, let’s look at how node-mail does it.

The node-mail app caches tokens te the session. The getAccessToken function comebacks the cached token if it’s not expired. Otherwise, it refreshes the token and comebacks the fresh token. The getAccessTokenFn function exists to wrap getAccessToken spil a function with no parameters, which is what the OutlookServices.Client class expects.

With authorization taken care of, using the library works just like it does te a Cordova app. For example, you could get messages ter the inbox with the following code:

Spil always, I’d love to hear your terugkoppeling te the comments or on Twitter (@JasonJohMSFT). Feel free to report issues or submit pull requests on GitHub!

Mampara reply

Thanks for the wonderful postbode Jason. I got the setup working for my Office 365 account, but it didn’t work for other users. Below are the steps I did,

1. Created Office 365 Developer account

Two. Thought Azure AD account will be automatically created, but the system said I need to have &quot,Azure Subscription&quot,

Three. I purchased trial version of &quot,Azure Subscription&quot,

Five. App is registered and I am able to access Office 365 Surplus API’s (calendar,events) using my user account

6. Using OAuth2 Auth flow, I attempted accessing spil a different user (who has Office 365 Huis account) , token and refresh token wasgoed returned. But, with this token if I access the Office 365 Surplus API, I am getting &quot,401 Unauthorized Error&quot,.

7. I went to my Active Directory portal, added this user explicitly and talent &quot,User&quot, role

8. Now when I accessed Office 365 Surplus API, 401 error is gone. But, getting &quot,ErrorMissingEmailAddress&quot, error

Do I need to explicitly add all the users who wants to access their Office 365 gegevens via &quot,App&quot, that I registered te &quot,Active Directory&quot,?

I am accessing &quot,Office 365 Surplus API&quot, via OAuth2 ter my NodeJS application. My NodeJS application is not multi-tenant application and so I cannot have user organization Active Directory synced to my AD portal.

Any users registered with our NodeJS application, needs &quot,Sign-In with Azure/Office&quot, option, so they can view their Office 365 gegevens.

Please let mij know if I am missing any configuration.

Ah. Office 365 Huis Accounts are presently not supported by the APIs. This is on the roadmap, but wij don’t have a hard date to share yet.

Thanks for the update Jason. Is Office 365 Business Account (Business/Business Essentials/Business Premium) supported by the APIs?

It should be. You can always attempt an account by going to and clicking on &quot,My Office 365&quot,. It will let you sign ter and attempt elementary GETs against your account.

Hey, Jason your update wasgoed truly helpful & informative. Thanks for this amazing update & looking forward for your next postbode.

The script you described here works, but it doesn’t match my requirements for an application. I am talking about Daemon type of application. The one without user interaction. Have you everzwijn built those using NodeJS/node-outlook?

No, I toevluchthaven’t done it personally with Knot. It should work, you will just have a slightly different auth flow, and you would use the .users accessor instead of .mij.

Appreciate your effort.

I am attempting to send mail using the outlookClientObject.

My code never sends off an email.

I am still able to do the follwoing things,

Create a Calendar Event

I am not able to send an email to someone from the code.

Any assistance would be greatly Appreciated!!

Ravi: Sorry to hear that. Make sure you have the &quot,Send mail&quot, permission specified ter your app registration. If you do and you still have trouble, postbode details on Stack Overflow and tag your postbode with the &quot,outlook-restapi&quot, tag so my colleagues and I will see it.

Thanks for the postbode, appreciate your effort. Are you aware of any official JS client for EWS Managed APIs and not just Office365

Not an official one, but I am author of ews-javascript-api at working on posting ews-managed-api from GitHub/officedev

Do I need to submit my app for approval others to access?

Jason, I wasgoed super-pumped to find your blog article. I want to attempt automating some regular calendar tasks, and this looks like the volmaakt place to get began!

One problem – the linksom at the bottom of your article (‘Common calendar tasks using an Office 365 client library’ te particular) don’t work. Where can I find this content now?

@Tim: Oh yeah, sorry about that. The innovador version of the Knot library used an old Cordova Exchange library that got retired. That verbinding wasgoed pointing at the old docs for that library, but they pulled that when they retired it. So I basically redesigned a v2 interface for the Knot library (node-outlook:…/node-outlook) that doesn’t use the Cordova stuff and is a little more straightforward to use. Check this tutorial:…/knot

I’m creating fresh NodeJs project. Customer wants to use Office365 mail service.

All works fine but I have a question.

Wij can login with Office 365 or account and grant access to our app.

Can I get token (authorize) automatically without redirecting?

Have a look at the different OAuth flows supported by Azure. Implicit works without a redirect, but you should consider if it is the right gezond for your screenplay.

3 thoughts on “Office 365 APIs and – Outlook and Exchange dev blog

  1. Did you have money on Binance? Were you alarmed or certain? I had a few grand on there, far more than usual… Super glad it turned out ok, but still let this be a reminder to mij and everyone else, storing coins on an exchange is more scary than on a secure private wallet.

  2. Yes its good to see binance is back and also good news for traders spil well because now a days binance is most popular and effortless to use exchange. Also binance registration is effortless , no need to wait for long time for account approval. Te other exchanges like bittex, poloniex needs to very your account very first for embark trading. And binance service is swift. Good to see again binance resume its trading.

  3. I’m not sure about binance I mostly trade on bittrex. I may not have enough practice and will switch my mind te the future.

Leave a Reply

Your email address will not be published. Required fields are marked *