Hi, I'm after a little help with an problem. I'm trying to post a html table that is auto generated using code. If I manually add a HTML Macro to the page and paste the HTML code into the section everything works find.
I can upload the HTML code into a page without the HTML Macro and it works but I don't get the nice style sheet on the data's table which is what I am after.
I found a same on how to post/update a page with a Confluence-History Macro that works.
I just can not get the HTML Macro to work via an automated PowerShell script.
I've attached the code, the 2x bits of code that i mention above are tagged "$HTMLPage".
Thanks for your help and comments in advance.
clear-host
clear-history
write-host -ForegroundColor Cyan "Requesting Login ID and password to authenticate with confluence."
if(-not($Credentials))
{
$Credentials = Get-Credential
}
$ConfluenceURL = "https://confluence.site/rest/api/"
# Confluence ID for page.
$ConfluencePageID = "123456"
$Headers = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(($Credentials.UserName+":" `
+[System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($Credentials.Password)) )))
"Accept"="application/json"
"ContentType"="application/json"
'X-Atlassian-Token' = 'nocheck'
}
$Call = "content/{0}?expand=version,body.storage,ancestors,space,results,contenttype" -f $ConfluencePageID
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
write-host -ForegroundColor Cyan "Logging into the confluence page that requires updating"
$CurrentConfluence = Invoke-WebRequest -Method GET -Headers $Headers -Uri ($ConfluenceURL + $Call) -UseBasicParsing | ConvertFrom-Json
Write-Host -ForegroundColor Cyan "obtaining HTML input data."
# This one does not work!!
$HTMLPage= '<p><br/></p><ac:structured-macro ac:name="html" ac:schema-version="1" ac:macro-id="4f4cf0b7-23d5-43be-94a4-739407bec55c"><ac:plain-text-body><![CDATA[<div><ul><li><a href="#Domain1">Domain1</a></li><li><a href="#Domain2">Domain2</a></li><li><a href="#Domain3">Domain3</a></li><li><a href="#Domain4">Domain4</a></li><li><a href="#Domain5">Domain5</a></li></ul></div><br/><div><table> <colgroup><col/><col/></colgroup><tr><th>Domain</th><th>System Count</th></tr><tr><td>Domain1</td><td>653</td></tr><tr><td>Domain2</td><td>2</td></tr><tr><td>Domain3</td><td>527</td></tr><tr><td>Domain4</td><td>2</td></tr><tr><td>Domain5</td><td>2</td></tr></table></div><br/>
</ac:plain-text-body></ac:structured-macro>]]></ac:plain-text-body></ac:structured-macro>'
# this one works for adding a confluence History anchor
#$HtmlPage = '<p>History macro test</p><p><ac:structured-macro ac:name=\"change-history\" ac:schema-version=\"1\" ac:macro-id=\"360a0d80-082e-4c82-9ee5-0aac5b72f828\" /></p>'
$Body = '{{"type":"{0}","title":"{1}","version":{{"number":"{2}" }},"body":{{"storage":{{"value":"{3}","representation":"storage"}}}}}}' -f $CurrentConfluence.type, $CurrentConfluence.title, $HTMLVersion, $HTMLPage
$Call = "content/$($ConfluencePageID)"
Write-Host -ForegroundColor Yellow "Updated the body contents with new information."
$Error.Clear()
read-host “Press ENTER to publish the update...”
try
{
$UpdateConfluence = Invoke-WebRequest -Method Put -Uri ($ConfluenceURL + $Call) -Body $Body -Headers $Headers -ContentType "application/json;" | convertfrom-json
Write-Host -ForegroundColor Green "Update published"
}
catch
{
$Error
}