2

I am reading around here and I am seeing multiple messages about the /pages endpoint that is not working a expected It seems that the OneNote APIs (MS Graph or Office365) are not returning all the pages that the user can see. In particular recent pages are not shown as available.

This message is for those of you who work for Microsoft and who keep an eye on this forum. Please if you have any explanation or workaround for this we would like to hear about it. If this is work in progress we would also like to know when the APIs can be considered stable and reliable enough to consider them OK for production use

Update:

Permissions or scopes
    scopes=[
            "Notes.Read",
            "Notes.Read.All",
            "Notes.ReadWrite",
            ]

This is for a device authorization flow, the device is acting as a Microsoft Online account. The app is registered to Azure as personal app but the enterprise one does the same

The authorization process is described here
What type of app/authentication flow should I select to read my cloud OneNote content using a Python script and a personal Microsoft account?

After that I am using this endpoint to get the notebooks
https://graph.microsoft.com/v1.0/users/user-id/onenote/notebooks

from the returned json I pick the endpoint for the notebook I want to read and I access the endpoint the link stored in notebook['sectionsUrl']. This call returns a sections json From this I pick the section I want and I access the link stored in section['pagesUrl']

Each call returns the expected info excepting the last one, when I get an arbitrary low number of pages in the section I want to explore. There is nothing wrong with the format of the info, it is just incomplete or not up to date

Not sure if this is related but when I try to access the pages in a section from MS Graph Explored I am seeing the same behavior (not all the pages are reported). This is a shared notebook and I am using the owner account for all the above so it should not be a permission problem

    from msal import PublicClientApplication
    import requests
    endpoint= "https://graph.microsoft.com/v1.0/me/onenote"
    authority = "https://login.microsoftonline.com/consumers"
    app=PublicClientApplication(client_id=client_id, authority=authority)
    flow = app.initiate_device_flow(scopes=scopes)
    # there is an interactive part here that I automated using selenium, you 
    # are supposed to ouse a link to enter a code and then autorize the 
    # device; code not shown
    result = app.acquire_token_by_device_flow(flow)
    token= result['access_token']
    headers={'Authorization': 'Bearer ' + token}
    endpoint= "https://graph.microsoft.com/v1.0/users/c5af8759-4785-4abf-9434-xxxxxxxxx/onenote/notebooks"
    notebooks = requests.get(endpoint,headers=headers).json()
    for notebook in notebooks['value']:
        print(notebook['displayName']) 
        print(notebook['sectionsUrl']) 
        print(notebook['sectionGroupsUrl']) 
# I pick a certain notebook 
    section=[section for section in sections if section['displayName']=="Test"][0]
    endpoint=notebook['sectionsUrl']
    pages=requests.get(endpoint,headers=headers).json() 

    for page in pages['value']:
        print(page['title']) 

Update2 If I use this endpoint https://graph.microsoft.com/v1.0/users/user-id/onenote/sections/section-id/pages I would expect to get the complete list of pages for that section. That is not working

After reading again and again the docs I my understanding is that the approach is to call https://graph.microsoft.com/v1.0/users/user-id/onenote/pages$fiter or search etc etc

I this correct? Also I vaguely remember there is a way to search for a section and have it expanded so that the search returs the children too.

Am I close to understanding this?

Thank you MM

MiniMe
  • 1,057
  • 4
  • 22
  • 47

0 Answers0