0

If we have a link to another OneNote page in the HTML content:

<a href="onenote:SectionB.one#Note1&amp;section-id={<section-id>}&amp;page-id={<page-id>}&amp;end&amp;base-path=https://<path>"

... before I write a parsing routine to extract that link, I thought I'd ask if I'd overlooked anything in the OneNote API to make this easier.

===========================================================================

[EDIT] Well, I've written my routine to extract the page-id of the linked note, but that page-id turns out to be quite different from the page-id that's returned as a property (id) of the linked note itself - and it doesn't work :(

Here's an example:

(1) page-id extracted from link: A8CECE6F-6AD8-4680-9773-6C01E96C91D0

(2) page-id as property of note:

0-5f49903893f048d0a3b1893ef004411f!1-240BD74C83900C17!124435

Vastly different, as you see. Accessing the page content via:

 ../pages/{page-id}/content

... for (1) returns nothing

... for (2) returns the full page content.

(The section-ids returned by both methods are also entirely different.)

So, how can I extract from the link a page-id that works?

Velojet
  • 878
  • 11
  • 18

1 Answers1

2

Unfortunately, the OneNote API currently does not support identifying links to other OneNote pages in page content. Links in OneNote can be links to anything: websites, other OneNote pages/sections/notebooks, network shares... The API does support getting links to pages by using

    GET ~/pages
    GET ~/sections/id/pages

The page metadata model contains a links object with the clientUrl and the webUrl.


Editing after your question update: You're right - the id in the link does not correspond to the id of the OneNote API. You can however compare the id in the link with the id in the OneNoteClientUrl exposed in the API. Here's an example of the response of a

    GET ~/sections/id/pages
    GET ~/pages

{ "title": "Created from WAC", "createdByAppId": "", "links": { "oneNoteClientUrl": { "href": "onenote:https://d.docs.live.net/29056cf89bb2d216/Documents/TestingNotification/Harrie%27s%20Section.one#Created%20from%20WAC&section-id=49b630fa-26cd-43fa-9c45-5c62d547ee3d&page-id=a60de930-0b03-4527-bf54-09f3b61d8838&end" }, "oneNoteWebUrl": { "href": "https://onedrive.live.com/redir.aspx?cid=29056cf89bb2d216&page=edit&resid=29056CF89BB2D216!156&parId=29056CF89BB2D216!105&wd=target%28Harrie%27s%20Section.one%7C49b630fa-26cd-43fa-9c45-5c62d547ee3d%2FCreated%20from%20WAC%7Ca60de930-0b03-4527-bf54-09f3b61d8838%2F%29" } }, "contentUrl": "https://www.onenote.com/api/v1.0/me/notes/pages/0-a50842a9873945379f3d891a7420aa39!14-29056CF89BB2D216!162/content", "thumbnailUrl": "https://www.onenote.com/api/v1.0/me/notes/pages/0-a50842a9873945379f3d891a7420aa39!14-29056CF89BB2D216!162/thumbnail", "lastModifiedTime": "2016-03-28T21:36:22Z", "id": "0-a50842a9873945379f3d891a7420aa39!14-29056CF89BB2D216!162", "self": "https://www.onenote.com/api/v1.0/me/notes/pages/0-a50842a9873945379f3d891a7420aa39!14-29056CF89BB2D216!162", "createdTime": "2016-03-24T20:38:16Z", "parentSection@odata.context": "https://www.onenote.com/api/v1.0/$metadata#me/notes/pages('0-a50842a9873945379f3d891a7420aa39%2114-29056CF89BB2D216%21162')/parentSection(id,name,self)/$entity", "parentSection": { "id": "0-29056CF89BB2D216!162", "name": "Harrie's Section", "self": "https://www.onenote.com/api/v1.0/me/notes/sections/0-29056CF89BB2D216!162" } }

You can also filter server side (if you want to save yourself from paging and regex's ;) ) for id's in the links by using:

    GET ~/pages?$filter=contains(links/oneNoteClientUrl/href,'a60de930-0b03-4527-bf54-09f3b61d8838')
Jorge Aguirre
  • 2,787
  • 3
  • 20
  • 27
  • 1
    If this is something you believe the API should support, I encourage you to create an entry in our uservoice site! https://onenote.uservoice.com/forums/245490-onenote-developer-apis – Jorge Aguirre Mar 24 '16 at 18:28
  • 1
    Thanks again for a super-prompt answer, Jorge. I'll now go ahead and write my parsing routine knowing I'm not reinventing the wheel. And I will also put in a uservoice request. – Velojet Mar 24 '16 at 18:34
  • Thanks once more, Jorge. That's very helpful and clarifies the direction I should be taking to access the linked page. – Velojet Mar 25 '16 at 19:07
  • 1
    Reporting back: That all did the job nicely, thanks, Jorge. I used your server-side filter to ease the pain. It took a while to get it to work until I discovered the page-id extracted from the href link needed to be forced to lowercase to get a match (odd that they use different cases?). – Velojet Mar 28 '16 at 01:59
  • **UPDATE/CORRECTION**: The filter request recently stopped working for us, with an error 400 (Bad request). Graph Explorer gave the message `"The number of maximum sections is exceeded for this request. To get pages for accounts with a high number of sections, we recommend getting pages for one section at a time (use the ~/sections/{id}/pages API)."` When we did this, the request was successful. So the filter request recommended by Jorge Aguirre should now be `GET ~/sections//pages?$filter=contains(links/oneNoteClientUrl/href,'')`. – Velojet Oct 26 '19 at 20:00