Hi,
This is my whole scenario: Export OneNote pages via powershell, then upload them via REST API into Confluence.
The export is fine and I´m getting functional html-pages. But how do I upload them into confluence without external solutions like plugins or server-addons?
My current script (creating pages is working with e.g. <p> test content </p>):
#Variables
$Credentials = GET-Credential
$ConfluenceURL = "https://<domain>.com/rest/api/content/"
$pageContentHTML = GET-Content C:\<directory>\TestFile.htm
#Where the page gets created
$spaceKey = '<key>' #Space Key
$parentId = "<parentID>" #ID of parent page
$pageTitle = 'A first test page'
#Content
$pageContent = $pageContentHTML
#Generate post request as PowerShell objects
$post = @{
type = 'page'
"ancestors" = @(
@{"id" = $parentId}
)
title = $pageTitle
space = @{ key = $spaceKey}
body = @{
storage = @{
value = '$pageContent'
representation = 'storage'
}
}
}
#Header for authentification
$header = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(($Credentials.UserName+":"+[System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($Credentials.Password)) )))}
#Convert post to json
$json = ConvertTo-Json $post
#Post request to Confluence
try {
Invoke-RestMethod -Uri $ConfluenceURL -Method POST -ContentType "application/json" -Body $json -Headers $header
} catch {$_.Exception.Response }
Thank you
so long
Jan
Meanwhile I managed it with parsing through the html-file and find my content with help of the tags. The end result is one big string, which is passed as a variable into "value" in the post request. Perhaps not that beautiful, but it works.
$doc = New-Object -Com "HTMLFile"
$pagePath = "C:\<path>\file.html"
$doc.IHTMLDocument2_write($(Get-Content $pagePath -raw))
foreach ($tag in $doc.all) {
if (($tag.innerHTML -like $tag.InnerText) -and ($tag.InnerText)) {
.... <code> ....
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.