0

I used some code to implement the OneNote API found here on the OneNote API page, https://dev.onenote.com/docs#/reference/post-pages/v10menotessectionsidpages/post

Here is the code I have so far in my Word Add In class:

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    CreatePage();
}


public async void CreatePage()
{
    var baseAddress = new Uri("https://www.onenote.com/api/");

    using (var httpClient = new HttpClient { BaseAddress = baseAddress })
    {
        httpClient.DefaultRequestHeaders.TryAddWithoutValidation("authorization", "Bearer tokenString");
        string sampleHtml = @"<html> <head> <title> Page with some info on it</title></head></html>";
        using (var content = new StringContent(sampleHtml, Encoding.Default, "applicaiton/xhtml+xml"))
        {
            using (var response = await httpClient.PostAsync("apis/onenote/reference/post-pages/v10menotessectionsidpages/undefined", content))
            {
                string responseData = await response.Content.ReadAsStringAsync();
            }
        }
    }
} 

The app runs fine with no build errors/bugs, but it doesn't create the intended OneNote page that I have been looking for. I have been stuck trying to create a page from the onenote api.

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

1

The endpoint uri does not look correct. It should be a POST on https://www.onenote.com/api/v1.0/me/notes/sections/{sectionId}/pages

Also, there is a typo in your content type

Manjusha
  • 538
  • 2
  • 4