I am trying to figure out how to update my page - I need to replace everything inside a <body>
tag always.
OneNote API says:
The following elements do not support any PATCH actions: - img or object (absolutely positioned) - meta, head - tr, tda, span, any style tags
Note: Absolutely positioned div, img, or object elements are direct children of the page body that define style=position:absolute.
Ok, that's clear. So I can't replace the <object>
that does not have an ID, because if it doesn't it either should be part of <div>
with id or it belongs to topmost div.
Here is my page's content:
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<title>image and PDF 2</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body data-absolute-enabled="true" style="font-family:Calibri;font-size:11pt">
<div id="div:{cfaf2831-c9e3-4b68-99ac-c4fc0bac0937}{32}" data-id="_default" style="position:absolute;left:48px;top:120px;width:624px">
<p id="p:{cfaf2831-c9e3-4b68-99ac-c4fc0bac0937}{38}" style="margin-top:2.8pt;margin-bottom:2.8pt"> SOME TEXT HERE <br />
</p>
<object data-attachment="pdf-sample.pdf" type="application/pdf" data="https://www.onenote.com/api/v1.0/me/notes/resources/0-3329938c15524891836ef46f570c17ce!1-6481EB8A1188E91C!389/$value" />
<img id="img:{cfaf2831-c9e3-4b68-99ac-c4fc0bac0937}{42}" alt="Image" src="https://www.onenote.com/api/v1.0/me/notes/resources/0-dfd3e39146d4425b974a71479787845f!1-6481EB8A1188E91C!389/$value" data-src-type="image/jpeg" data-fullres-src="https://www.onenote.com/api/v1.0/me/notes/resources/0-dfd3e39146d4425b974a71479787845f!1-6481EB8A1188E91C!389/$value" data-fullres-src-type="image/jpeg" />
<object data-attachment="_SaferoomTestDOC.doc" type="application/msword" data="https://www.onenote.com/api/v1.0/me/notes/resources/0-07e77c13690247e88afcd20af3b45a12!1-6481EB8A1188E91C!389/$value" />
</div>
</body>
</html>
Now if I want to replace the image above (<img>
) I do like this:
{
'target':'img:{cfaf2831-c9e3-4b68-99ac-c4fc0bac0937}{42}',
'action':'replace',
'content':'<img src="NEW IMAGE" alt="NEW IMAGE" />'
},
But how do I replace the object which in my case is a PDF or Word document?
And how do I replace the whole <body>
?
P.S. I've tried wrapping <object>
object tags into divs, the <div>
tags are stripped on upload.
P.P.S. I always need to replace the whole content inside the body and all the objects and images.
But how do I replace the object which in my case is a PDF or Word document? And how do I replace the whole ?
In this scenario, we can delete the old page and create a new one. Here is an sample to create a page with a word and image embed in the page:
POST https://www.onenote.com/api/v1.0/me/notes/pages
Content-Type: multipart/form-data; boundary=-------------------------acebdf13572468
Authorization: Bearer {token}
---------------------------acebdf13572468
Content-Disposition:form-data; name="Presentation"
Content-Type:text/html
<!DOCTYPE html>
<html>
<head>
<title>A page with rendered images and an attached file</title>
<meta name="created" content="2016-05-30T07:30:00-08:00" />
</head>
<body>
<p>Here's an image from an <i>online source</i>:</p>
<img src="http://png-4.findicons.com/files/icons/2795/office_2013_hd/2000/onenote.png" alt="an image on the page" width="500" />
<p>Here's an image uploaded as <b>binary data</b>:</p>
<img src="name:imageBlock1" alt="an image on the page" width="300" />
<p>Here's a file attachment:</p>
<object data-attachment="doc1.docx" data="name:fileBlock1" type="application/docx" />
</body>
</html>
---------------------------acebdf13572468
Content-Disposition: form-data; name="imageBlock1"; filename="wdIcon.jpg"
Content-Type: image/jpeg
<@INCLUDE *C:\users\username\desktop\wdIcon.jpg*@>
---------------------------acebdf13572468
Content-Disposition: form-data; name="fileBlock1"; filename="doc1.docx"
Content-Type: application/msword
<@INCLUDE *C:\users\username\desktop\doc1.docx*@>
---------------------------acebdf13572468—