Trey Balut
Trey Balut

Reputation: 1395

Create OneNote (client) Notebook with OneNote API

I can use the code below to create a page in a section and I can create a Notebook in the OneNote OneDrive using the APIGee console app, but I cannot figure out how to create a new Notebook in the OneNote client program. Below is a snippet of my code to create a page in the Foo section.

How can I modify this code to create a new Notebook in the client?

private static readonly Uri PagesEndPoint = new Uri("https://www.onenote.com/api/v1.0/pages?sectionName=Foo");

                HttpResponseMessage response;
            using (var imageContent = new StreamContent(await GetBinaryStream("assets\\SOAP.jpg")))
            {
                imageContent.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
                HttpRequestMessage createMessage = new HttpRequestMessage(HttpMethod.Post, PagesEndPoint)
                {
                    Content = new MultipartFormDataContent
                    {
                        {new StringContent(simpleHtml, System.Text.Encoding.UTF8, "text/html"), "Presentation"},{imageContent, imagePartName}
                    }
                };


                // Must send the request within the using block, or the image stream will have been disposed.
                response = await client.SendAsync(createMessage);
            }

            tbResponse.Text = response.ToString();
            return await TranslateResponse(response);

Upvotes: 1

Views: 590

Answers (2)

jayongg
jayongg

Reputation: 513

If you have OneNote installed, you may use the OneNote COM API. There is a VanillaAddin you can modify here: https://github.com/OneNoteDev/VanillaAddIn

In addition you can just write a Console app using the same COM API to do this (so you don't need to write a COM Add-in).

Upvotes: 1

JamesLau-MSFT
JamesLau-MSFT

Reputation: 284

If the create notebook API call returns a success (201), it means the notebook has been created successfully on the user's OneDrive. However, the notebook will not automatically show up in the OneNote clients for the user. The user will need to open the newly created notebook in one of the OneNote client apps.

Alternatively, you can use the links.oneNoteClientUrl.href property from the API response message to open the notebook for the user in the OneNote client for them.

Hope that helps.

Thanks, James

Upvotes: 2

Related Questions