I am trying to update a OneNote page using the PATCH
request through the Microsoft Graph API. I keep getting Error 19999
which according to this https://msdn.microsoft.com/en-us/office/office365/howto/onenote-error-codes means "Unknown Error"
var pageId = settings.DefaultPage;
string requestUrl = $"https://graph.microsoft.com/v1.0/me/onenote/pages/{pageId}/content";
string body = @"{
{
'target':'body',
'action':'append',
'position':'after',
'content':'<div> added new </div>'}}";
var content = new StringContent(body, Encoding.UTF8, "application/json");
HttpRequestMessage req = new HttpRequestMessage()
{
Method = new HttpMethod("PATCH"),
Content = content,
RequestUri = new Uri(requestUrl)
};
HttpClient client = new HttpClient()
{
BaseAddress = new Uri(requestUrl),
};
client.DefaultRequestHeaders.TryAddWithoutValidation("authorization", "Bearer " + settings.MsaAccessCode);
HttpResponseMessage response = await client.SendAsync(req);
I can verify that the Authorization Code is valid (as I am able to do other actions like creating a new page) and has the necessary scopes to update a page. Can anyone help me with identifying the problem here?
Your JSON is invalid. Here is what I believe you want.
[{
"target": "body",
"action": "append",
"position": "after",
"content": "<div> added new </div>"
}]