Get OneNote content and structure with the OneNote API
Learn how to retrieve the content and structure of OneNote pages, sections, section groups, and notebooks, and how to use OData query string options to search and query for pages and improve performance.
Last modified: January 22, 2016
Applies to: OneNote service
In this article
Resource paths for GET requests
Example GET requests
Supported OData query string options
Page, section, section group, and notebook properties
Permission scopes
Note
|
|---|
|
See this topic on our new documentation site for consumer and enterprise OneNote APIs. |
You can use the OneNote API to get page content and metadata for pages, sections, section groups, and notebooks. By using query string options, you can search and query for pages and other OneNote content and structure. See Example GET requests.
All GET requests start with the service root URL, for example:
https://www.onenote.com/api/v1.0/me/notes
When you retrieve OneNote objects, the API returns JSON objects that conform to the OData version 4.0 specification.
The following table shows resource paths for pages, sections, section groups, and notebooks that you can use for GET requests to the OneNote API.
|
Resource |
Resource path |
|---|---|
|
Page |
Page collection ../pages[?filter,orderby,select,top,skip,expand,count,search] ../sections/{section-id}/pages[?filter,orderby,select,top,skip,expand,count,search] Page object ../pages/{page-id}[?select,expand] Page HTML content ../pages/{page-id}/content[?includeIDs=true] |
|
Section |
Section collection ../sections[?filter,orderby,select,top,skip,expand,count] ../sectiongroups/{sectiongroup-id}/sections[?filter,orderby,select,top,skip,expand,count] ../notebooks/{notebook-id}/sections[?filter,orderby,select,top,skip,expand,count] Section object ../sections/{section-id}[?select,expand] |
|
SectionGroup |
SectionGroup collection ../sectiongroups[?filter,orderby,select,top,skip,expand,count] ../notebooks/{notebook-id}/sectiongroups[?filter,orderby,select,top,skip,expand,count] SectionGroup object ../sectiongroups/{sectiongroup-id}[?select,expand] |
|
Notebook |
Notebook collection ../notebooks[?filter,orderby,select,top,skip,expand,count] Notebook object ../notebooks/{notebook-id}[?select,expand] |
|
Resources |
Image resource ../resources/{image-id}/$value File resource ../resources/{file-id}/$value The endpoints that link to resources are returned in the page's output HTML. An img tag includes endpoints for original and optimized image resources in the data-fullres-src and src attributes. An object tag includes the endpoint for the file resource in the data attribute. |
For more information about GET requests, see GET Pages, GET Sections, GET SectionGroups, and GET Notebooks in the OneNote API interactive reference.
The following examples show some ways you can use supported query string options in GET requests to the OneNote API. You can search and query for pages and other OneNote objects to get just the information you need.
Remember:
-
All GET requests start with the service root URL. Example: https://www.onenote.com/api/v1.0/me/notes
-
Spaces in the URL query string must be replaced with the %20 encoding. Example: filter=title%20eq%20'biology'
-
Property names and OData string comparisons are case sensitive. We recommend using the OData tolower function for string comparisons. Example: filter=tolower(name) eq 'spring'
search & filter
Get all pages that contain the term recipe that were created by a specific app.
[GET] ../pages?search=recipe&filter=createdByAppId eq 'WLID-000000004C12821A'
search & select
Get the title, OneNote client links, and contentUrl link for all pages that contain the term golgi app.
[GET] ../pages?search=golgi app&select=title,links,contentUrl
expand
Get all notebooks and expand their sections and section groups.
[GET] ../notebooks?expand=sections,sectionGroups
Get a specific section group and expand its sections and section groups.
[GET] ../sectiongroups/{sectiongroup-id}?expand=sections,sectionGroups
Get a page and expand its parent section and parent notebook.
[GET] ../pages/{page-id}?expand=parentSection,parentNotebook
expand (multiple levels)
Get all notebooks and expand their sections and section groups, and expand all sections in each section group.
[GET] ../notebooks?expand=sections,sectionGroups(expand=sections)
Note |
|---|
Expanding parents of child entities or expanding children of parent entities creates a circular reference and is not supported. |
expand & select (multiple levels)
Get the name and self link for a specific section group, and get the name and self links for all its sections.
[GET] ../sectiongroups/{sectiongroup-id}?expand=sections(select=name,self)&select=name,self
Get the name and self link for all sections, and get the name and created time of its parent notebook.
[GET] ../sections?expand=parentNotebook(select=name,createdTime)&select=name,self
Get the title and ID for all pages, and get the name of the parent section and parent notebook.
[GET] ../pages?select=id,title&expand=parentSection(select=name),parentNotebook(select=name)
expand & levels (multiple levels)
Get all notebooks, sections, and section groups.
[GET] ../notebooks?expand=sections,sectionGroups(expand=sections,sectionGroups(levels=max;expand=sections))
filter
Get all sections that were created in October 2014.
[GET] ../sections?filter=createdTime ge 2014-10-01 and createdTime le 2014-10-31
Get the pages that were created by a specific app since January 1, 2015.
[GET] ../pages?filter=createdByAppId eq 'WLID-0000000048118631' and createdTime ge 2015-01-01
filter & expand
Get the name and pagesUrl link for all sections from the School notebook. OData string comparisons are case sensitive, so use the tolower function as a best practice.
[GET] ../notebooks?filter=tolower(name) eq 'school'&expand=sections(select=name,pagesUrl)
filter & select & orderby
Get the name and pagesUrl link for all sections that contain the term spring in the section name. Order sections by last modified date.
[GET] ../sections?filter=contains(tolower(name),'spring')&select=name,pagesUrl&orderby=lastModifiedTime desc
orderby
Get the first 20 pages ordered by createdByAppId property and then by most recent created time. The API returns 20 pages by default.
[GET] ../pages?orderby=createdByAppId,createdTime desc
search & filter & top
Get the five newest pages created since January 1, 2015 that contain the phrase cell division. The API returns 20 pages by default with a maximum of 100. The default sort order for pages lastModifiedTime desc.
[GET] ../pages?search="cell division"&filter=createdTime ge 2015-01-01&top=5
search & filter & top & skip
Get the next five pages in the result set.
[GET] ../pages?search=biology&filter=createdTime ge 2015-01-01&top=5&skip=5
And the next five.
[GET] ../pages?search=biology&filter=createdTime ge 2015-01-01&top=5&skip=10
Note |
|---|
If both search and filter are applied to the same request, the results include only those entities that match both criteria. |
select
Get the name, created time, and self link for all sections in the user's notebooks.
[GET] ../sections?select=name,createdTime,self
Get the title, created time, and OneNote client links for a specific page.
[GET] ../pages/{page-id}?select=title,createdTime,links
select & expand & filter (multiple levels)
Get the name and pagesUrl link for all sections in the user's default notebook.
[GET] ../notebooks?select=name&expand=sections(select=name,pagesUrl)&filter=isDefault eq true
top & select & orderby
Get the title and self link for the first 50 pages, ordered alphabetically by title. The API returns 20 entries by default with a maximum of 100. The default sort order for pages lastModifiedTime desc.
[GET] ../pages?top=50&select=title,self&orderby=title
skip & top & select & orderby
Get pages 51 to 100. The API returns 20 entries by default with a maximum of 100.
[GET] ../pages?skip=50&top=50&select=title,self&orderby=title
Tip |
|---|
GET requests for pages that retrieve the default number of entries (that is, they don’t specify a top expression) return an @odata.nextLink link in the response that you can use to get the next 20 entries. |
When sending GET requests to the OneNote API, you can use OData query string options to customize your query and get just the information you need. They can also improve performance by reducing the number of calls to the service and the size of the response payload.
Note
|
|---|
|
For readability, the examples in this article don't use the %20 percent-encoding required for spaces in the URL query string. Example: filter=isDefault%20eq%20true |
|
Query option |
Example and description |
|---|---|
|
count |
count=true The count of entities in the collection. The value is returned in the @odata.count property in the response. |
|
expand |
expand=sections,sectionGroups The navigation properties to return inline in the response. The following properties are supported for expand expressions:
By default, GET requests for pages expands parentSection and select the section's id, name, and self properties. Default GET requests for sections and section groups expand both parentNotebook and parentSectionGroup, and select the parents' id, name, and self properties. Can be used for a single entity or a collection. Separate multiple properties with commas. Property names are case sensitive. |
|
filter |
filter=isDefault eq true A Boolean expression for whether to include an entry in the result set. Supports the following OData operators and functions:
See Supported OData operators and functions for examples. Property names and OData string comparisons are case sensitive. We recommend using the OData tolower function for string comparisons. Example: filter=tolower(name) eq 'spring' |
|
orderby |
orderby=title,createdTime desc The properties to sort by, with an optional asc (default) or desc sort order. You can sort by any property of the entity in the requested collection. The default sort order for notebooks, section groups, and sections is name asc, and for pages is lastModifiedTime desc (last modified page first). Separate multiple properties with commas, and list them in the order that you want them applied. Property names are case sensitive. |
|
search |
search=cell div The term or phrase to search for in the page title, page body, image alt text, and image OCR text. By default, search queries return results sorted by relevance. OneNote uses Bing full text search to support phrase search, stemming, spelling forgiveness, relevance and ranking, word breaking, multiple languages, and other full-text search features. Search strings are case insensitive. Applies only to pages in notebooks owned by the user (not shared with the user). Indexed content is private and can only be accessed by the owner. Password-protected pages are not indexed. Applies only to the pages endpoint. |
|
select |
select=id,title The properties to return. Can be used for a single entity or for a collection. Separate multiple properties with commas. Property names are case sensitive. |
|
skip |
skip=10 The number of entries to skip in the result set. Typically used for paging results. |
|
top |
top=50 The number of entries to return in the result set, up to a maximum of 100. The default value for pages is 20. |
Supported OData operators and functions
The OneNote API supports the following OData operators and functions in filter expressions. When using OData expressions, remember:
-
Spaces in the URL query string must be replaced with the %20 encoding. Example: filter=isDefault%20eq%20true
-
Property names and OData string comparisons are case sensitive. We recommend using the OData tolower function for string comparisons. Example: filter=tolower(name) eq 'spring'
|
Comparison operator |
Example |
|
eq (equal to) |
createdByAppId eq '{app-id}' |
|
ne (not equal to) |
userRole ne 'Owner' |
|
gt (greater than) |
createdTime gt 2014-02-23 |
|
ge (greater than or equal to) |
lastModifiedTime ge 2014-05-05T07:00:00Z |
|
lt (less than) |
createdTime lt 2014-02-23 |
|
le (less than or equal to) |
lastModifiedTime le 2014-02-23 |
|
Logical operator |
Example |
|
and |
createdTime le 2014-01-30 and createdTime gt 2014-01-23 |
|
or |
createdByAppId eq '{app-id}' or createdByAppId eq '{app-id}' |
|
not |
not contains(tolower(title),'school') |
|
String function |
Example |
|
contains |
contains(tolower(title),'spring') |
|
endswith |
endswith(tolower(title),'spring') |
|
startswith |
startswith(tolower(title),'spring') |
|
length |
length(title) eq 19 |
|
indexof |
indexof(tolower(title),'spring') eq 1 |
|
substring |
substring(tolower(title),1) eq 'spring' |
|
tolower |
tolower(title) eq 'spring' |
|
toupper |
toupper(title) eq 'SPRING' |
|
trim |
trim(tolower(title)) eq 'spring' |
|
concat |
concat(title,'- by MyRecipesApp') eq 'Carrot Cake Recipe - by MyRecipesApp' |
You can use the OData filter, select, expand, and orderby query string options to customize a query using the properties of OneNote entities. For the list of properties and property types, see:
The expand query string option can be used with the following navigation properties:
-
Pages: parentNotebook, parentSection
-
Sections: parentNotebook, parentSectionGroup
-
Section groups: sections, sectionGroups, parentNotebook, parentSectionGroup
-
Notebooks: sections, sectionGroups
To retrieve pages, sections, section groups, or notebooks, you’ll need to request one of the following permission scopes when you authenticate the user.
-
office.onenote
-
office.onenote_update_by_app
-
office.onenote_update
Choose the scope that best suits your app's functionality. For more information about permission scopes and how they work, see OneNote permission scopes.
Note