This repository was archived by the owner on Dec 15, 2023. It is now read-only.
Description Not sure what I am doing wrong, but when I try to insert a PDF using the OneNote API the PDF is unreadable and doesn’t render.
$tokenfile = get-content < …snip…> .json | ConvertFrom-Json
$access_token = $tokenfile .$access_token
foreach ($file in gci " /Users/steven/Documents/Receipts/2020 Receipts\*.pdf" ){
$date = [datetime ]::ParseExact($file.BaseName.Substring (0 , 17 ), ' yyyy-MM-dd HHmmss' , $null )
$pdffile = [System.IO.File ]::ReadAllBytes($file.FullName )
$pageContent = @"
--MyPartBoundary
Content-Disposition:form-data; name="Presentation"
Content-Type:text/html
<!DOCTYPE html>
<html>
<head>
<title>$ ( $file.BaseName -replace " .pdf" , " " ) </title>
<meta name="created" content="$ ( $date.ToUniversalTime ().ToString(' u' ).replace(' ' , ' T' )) " />
</head>
<body>
<p><img data-render-src="name:FileBlock" /></p>
<p><object data-attachment="$ ( $file.name ) " data="name:FileBlock" type="application/pdf" /></p>
</body>
</html>
--MyPartBoundary
Content-Disposition:form-data; name="FileBlock"
Content-Type:application/pdf
$pdfFile
--MyPartBoundary--
"@
Invoke-RestMethod - Uri ' https://graph.microsoft.com/v1.0/me/onenote/sections/<…snip...>/pages' `
- Method Post `
- ContentType ' multipart/form-data; boundary=MyPartBoundary' `
- Headers @ {" Authorization" = " Bearer $ ( $tokenfile.access_token ) " } `
- Body $pageContent
}Reactions are currently unavailable
Not sure what I am doing wrong, but when I try to insert a PDF using the OneNote API the PDF is unreadable and doesn’t render.