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.
You need to modify your table to use the Confluence Wiki Markup to markup the table. As an example, the html table:
Should be written as:
Then, when you you do the update / insert via REST, change the 'representation' from 'storage' to 'wiki'. (And remove the html macro wrapper)
This will give you a native, wysiwyg Confluence table.
The 'storage' representation indicates that the body test is already converted to the format that Confluence uses internally to store the content. You want to insert using 'wiki', and let Confluence handle any conversions for you.