Before getting into the details of this article, make sure you have already followed my earlier steps on Office 365 Outlook Add-in Development using NAPA:
Outlook Add-In and REST API
After charting, now we would like to have the data coming from third party REST APIs in our Outlook add-in. To do this, we will be referring to Google APIs for books. These are public and can be accessed anonymously. Refer to the below URL for this API.
API URL
JSON Output
From the above JSON output, we will be displaying title and description attributes in our Outlook AddIn.
Now refer to the the following steps to achieve this,
Step 1: Open our earlier Outlook Add-in solution BasicOutlookAddIn in Napa explorer,
Step 2: Now to render our book details within home.html, locate tag <div class="padding"> and remove existing tags within it. Now use the following code lines and copy paste inside tag <div class="padding"> home.html.
- <p><strong>Book Details</strong></p>
- <hr></hr>
- <strong><div id="title"></div></strong>
- <div id="description"></div>
Now your code should look like the following snippet:,
Step 3: Now to call REST API we would be using
$.getJSON() function and data would be assigned to our HTML elements from
home.html. Below code can be added to
home.js.
-
- Office.initialize = function (reason)
- {
- $(document).ready(function ()
- {
- app.initialize();
- displayBookData();
- });
- };
-
- function displayBookData()
- {
- $.getJSON("https://www.googleapis.com/books/v1/volumes?q=isbn:9780670921621", function (data)
- {
- $('#title').text(data.items[0].volumeInfo.title);
- $('#description').text(data.items[0].volumeInfo.description);
- });
- }
Home.js should now look like this,
Step 4: Run the project so as to deploy these changes to Outlook
AddIn.
Step 5: Launch outlook web app and locate
BasicOutlookAddIn for selected email. Click
AddIn link to display book details right into your e-mail pane as below,
The above diagram shows
title and
description coming from REST API upon launching Outlook AddIn.
This way we can integrate the data coming from REST APIs considering the current context of our email.
Read more articles on SharePoint: