Skip to content

Error when Retrieving Pages of a Notebook Section using Graph Client #913

Open
@fgonzalez-glmc

Description

@fgonzalez-glmc

Issue: Error when Retrieving Pages Content of a Notebook Section using Graph Client

Description:
I'm using the Microsoft Graph client to retrieve data from a SharePoint site's OneNote notebook. When attempting to get the content of pages within a notebook's section, I encounter an error. Here’s the relevant portion of my code:

def print_site_notebook_structure():
    client = GraphClient.with_client_secret(
        os.getenv("TENANT_ID"),
        os.getenv("CLIENT_ID"),
        os.getenv("CLIENT_SECRET"),
    )
    site_url = os.getenv("SITE_URL")
    
    # Retrieve all notebooks in a single query
    notebooks = client.sites.get_by_url(site_url).onenote.notebooks.get().execute_query()
    
    # Fetch sections for each notebook
    notebook_sections = {
        notebook: notebook.sections.get().execute_query() for notebook in notebooks
    }
    
    # Attempt to fetch pages for each section
    section_pages = {
        section: section.pages.get_all().execute_query()  # This line causes an error
        for sections in notebook_sections.values()
        for section in sections
    }

    # Print the structure of notebooks, sections, and pages
    for notebook in notebooks:
        print(notebook.display_name)
        for section in notebook_sections[notebook]:
            print(f"    {section.display_name}")
            for page in section_pages[section]:
                print(f"        {page.title}")

Error Encountered:
When calling section.pages.get_all().execute_query(), I receive the following error:

requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://graph.microsoft.com/v1.0/sites/{site_id}/onenote/notebooks/{notebook_id}/sections/{section_id}/pages

Investigation & Findings:
After testing and researching the API, I discovered that the correct endpoint for retrieving pages within a section is:

https://graph.microsoft.com/v1.0/sites/{site_id}/onenote/sections/{section_id}/pages

It appears that /notebooks/{notebook_id} should be excluded from the URL path when fetching section pages.

Hope this helps clarify the issue and helps fix the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions