Table of contents
Looking to build cool apps that help people work with their OneNote notebooks? Explore, learn, and understand the OneNote REST APIs by using the OneNote REST API Explorer for Android. This sample lets you view and run the REST APIs that read, add, update, and delete OneNote entities such as notebooks, section groups, sections, and pages. The app lets you authenticate in two ways. You can authenticate using a Microsoft Account (MSA) to connect to OneNote on your personal OneDrive. Or you can authenticate using a work or school account to connect to OneNote on your organization's OneDrive for Business on Office 365.
You can explore the following operations for OneNote:
Notebook
Section group
Sections
Pages
August 2015
July 2015:
To run the REST Explorer project, your device must meet the following requirements:
To use the OneNote REST API Explorer for Android, you need the following:
Sign in to the Azure Management Portal, using your Azure AD credentials.
Click Active Directory on the left menu, then select the directory for your Office 365 developer site.
On the top menu, click Applications.
Click Add from the bottom menu.
On the What do you want to do page, click Add an application my organization is developing.
On the Tell us about your application page, specify OneNote REST API Explorer for the application name and select NATIVE CLIENT APPLICATION for type.
Click the arrow icon on the bottom-right corner of the page.
On the Application information page, specify a Redirect URI, for this example, you can specify http://localhost/OneNoteRESTExplorer, and then select the checkbox in the lower-right hand corner of the page. Remember this value for the below section Getting the ClientID and RedirectUri into the project.
Once the application has been successfully added, you will be taken to the Quick Start page for the application. From here, select Configure in the top menu.
Under permissions to other applications, select Add application. Select OneNote and then the check box to proceed.
For the OneNote application add the following permissions:
For the Windows Azure Active Directory application add or make sure the following permissions are enabled:
Copy the value specified for Client ID on the Configure page. Remember this value for the below section Getting the ClientID and RedirectUri into the project.
Click Save in the bottom menu.
Go to the Windows Live application management site.
Sign in by using your Windows Live ID.
Note: If this is your first visit to this site, you will see several pages that configure your Windows Live ID for use with the site.
Click Create application.
Enter a unique application name. If you agree to the terms, click Accept.
There are many settings for your app, but to make it work with this sample, you need to make the following changes:
Once you are satisfied with your app settings, click Save.
Click App Settings. This will display a page with your client id. You will use this value later when configuring your project.
CLIENT_ID
string and set its value to the client id you registered in Azure.REDIRECT_URI
string and set its value to the redirect URI you registered in Azure.MSA_CLIENT_ID
string and set its value to the client id you registered for your app in your Microsoft Account.Once you've built the REST Explorer project you can run it on an emulator or device.
Run the project.
Click the authentication account that you want to sign in to.
Enter your credentials.
Click a REST operation in the main activity to show operation details.
Note: Some operations require input before they will run. For example, to update a page, you must first select a page to update. On these operations there will be a spinner, or text box, to select or enter required input for an operation.
Click the run button to start the REST operation and wait for the operation to finish.
Click in the Response Headers or Response Body text boxes to copy the box contents to the emulator/device clipboard.
Click the Back button on the REST Explorer toolbar to return to the REST operation list.
(Optional) Click the overflow menu to get the Disconnect menu option.
The REST API Explorer project uses these classes to manage interactions with OneNote for Enterprise and consumer OneNote:
The REST API explorer project is comprised of four modules. The modular design allows you to add authentication and OneNote REST API support to your app by importing modules from REST API Explorer into your app. After you've imported the modules, use the code in the REST API Explorer app module as an example of how to call methods in the other sample modules.
O365-Auth
. This module contains the library calls to authenticate a user with Office 365.onenoteapi
. This module encapsulates the Retrofit REST operations used for the OneNote (enterprise and consumer) endpoints.onenotevos
. This module provides the value objects that wrap deserialized JSON REST response payloads. Use the value objects in your app logic to get the metadata and content of OneDrive notebooks, sections, and pages returned by the API.app
. The REST API explorer UI and business logic module. REST API Explorer consumes the api and vo modules from the logic in the app module. REST operations are started in the snippet classes in this module.A snippet runs a single REST operation and returns the results. Snippets are found in the app module. Snippets set the state required to make the calls on the OneNote service classes described below. Where necessary, a snippet class gets the notebooks, sections, or pages to load the spinner control shown on the snippet detail fragment for a given REST operation.
These classes are found in the onenoteapi module and make the Retrofit library calls that generate the REST queries and handle operation results. These service classes are consumed by the snippets.
These classes are found in the onenotevos module. The value object classes describe JSON payloads as objects.
BaseVO
. The superclass for other value objects. Envelope
. A collection of individual notebook, section, section group, or page objects returned in GET request.Links
. The collection of URLs returned in the body of a notebook, section, or page.Notebook
. A OneNote notebook.Page
. A OneNote page.Section
. A OneNote section.SectionGroup
. A OneNote section group.The authentication classes are found in the O365-Auth module. These classes use the Microsoft Azure Active Directory Library (ADAL) for Android to connect to a business version of Office 365 such as Office 365 Enterprise.
AuthenticationManager
. Encapsulates user connect and disconnect logic in addition to Azure app authorization.AzureADModule
. Authentication helper class. AzureAppCompatActivity
. Dependency injection helper.Authentication for logging in with a Microsoft Account to a personal version of Office 365 such as Office 365 Home is handled by the MSA Auth for Android library. The app uses the LiveAuthClient class to connect and disconnect.
Login | REST Call List |
---|---|
![]() |
![]() |
REST Call Detail | Create Page |
---|---|
![]() |
![]() |
We'd love to get your feedback about the OneNote REST API Explorer for Android sample. You can send your feedback to us in the Issues section of this repository.
General questions about Office 365 development should be posted to Stack Overflow. Make sure that your questions are tagged with [Office365] and [API].
You will need to sign a Contributor License Agreement before submitting your pull request. To complete the Contributor License Agreement (CLA), you will need to submit a request via the form and then electronically sign the CLA when you receive the email containing the link to the document.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
Copyright (c) 2015 Microsoft. All rights reserved.