microsoft-graph-apimicrosoft-graph-sdksonenote-apimicrosoft-graph-filesmicrosoft-graph-onenote

Graph API OneNote: Create section with page content


I have a requirement where I need to download the OneNote notebook and upload it again on demand.

I am using Graph API (DriveItem API) to track changes in the OneNote notebook and download it.

Now when I download it I an see that for section and page there is one single file downloaded. This file has data in binary which I believe is Page data and section metadata.

I am using OneNote API When I am uploading this again. This is because the Graph API doesn't have support for creating NoteBook items.

So I can create NoteBook using OneNote API but I am not getting how can I upload the downloaded content (section+page data) to this newly created notebook. I can create section and pages individually but my problem is while downloading I have got section and page data combined in one file.

Let me know if anyone has faced such an issue and is aware of any fix/workaround.


Solution

  • I'm assuming you are using the OneDrive-API component of microsoft-graph to download the OneNote Notebook (which is a special folder) with it's constituent files (OneNote .one files are Sections with pages and .onetoc2 are index files for ordering sections). The resultant Notebooks cannot be simply uploaded because they don't have the special flag to indicate to OneNote they are OneNote Notebooks. You can however create an empty Notebook and then upload the .one files into it via the OneDrive-API upload PUT request. An alternative is to treat the Sharepoint site as a WebDAV server and using a utility such as rclone.