My goal is to create a page with a table in a confluence wiki using the provided REST API that can be easily edited by users of the wiki using the WYSIWYG editor after the page has been created.
I have taken apart texts and put into different categories into an array of arrays, and then generated an html table (a string) out of this, which works great.
However posting this raw html table (in $htmlTable) as content to the REST API
$data = array("type" => "page", "title" => someTitle,
"space" => array("key" => "$uploadSpace"),
"body" => array("storage" => array("value" => "$htmlTable", "representation" => "storage")));
returns a 400 statusCode error. Obviously because the input is not properly escaped using htmlspecialchars
for encoding the string into html, but how would I create a stuctured input that translates into an html table otherwise?
I have attempted to pass my html table with a confluence macro that renders the html input into a table for viewing:
$data = array("type" => "page", "title" => someTitle,
"space" => array("key" => "$uploadSpace"),
"body" => array("storage" => array("value" => "<ac:structured-macro ac:name=\"html\"><ac:plain-text-body><![CDATA[$htmlTable]]></ac:plain-text-body></ac:structured-macro>", "representation" => "storage")));
This renders my html table on the page, however this fails the easily editable in WYSIWYG requirement as users of the wiki would see the html code contained in a macro afterwards.
Thank you very much in advance.
After a long struggle, found the fix.
Add the macro code over your HTML content.
$bodyFormatted variable holds the HTML content.
Encode to json and pass thru REST. Before that one important process, where I failed.
"Enabling the HTML Macro" Ref: https://confluence.atlassian.com/conf55/confluence-user-s-guide/creating-content/using-the-editor/working-with-macros/html-macro
Inspite of warnings, enable the mentioned module (html (html-xhtml))
Process your API calls and now check the content. Hope you are done. Once the work is done, disable the modules, to prevent the cross scripting attacks.