Create Confluence page with table and multiline text in a table cell

Context: A macro is initiated from a confluence page so that a child page is created with a status report. The data for the status report comes from Jira issues. It all works fine except for the multiline fields. I am using this as a pilot to learn Forge.

Initially I tried this (pb ~ pageBody):

  pb = `<h2>Status Update</h2>
        <table><tbody>
        <tr><th>Recent Deliverables</th><td>` + recent_text + `</td></tr>
        <tr><th>Next Deliverables</th><td>` + next_text + `</td></tr>
        </tbody></table>`;

That didn’t work so I switch to (which works):

  pb = `<h2>Status Update</h2>`;
  pb = pb + `<table><tbody>`;
  pb = pb + `<tr><th>Recent Deliverables</th><td>` + recent_text + `</td></tr>`;
  pb = pb + `<tr><th>Next Deliverables</th><td>` + next_text + `</td></tr>`;
  pb = pb + `</tbody></table>`;

“recent_text” and “next_text” contain the data from the related multiline custom fields in Jira. However, in Jira there can be several paragraphs. These text variables are just concatenations of the paragraphs. It works ok. However, when I try to add a line break for each paragraph then I get an invalid message error and the page is not created.

It seems the ‘xml’ structure for creating a confluence page through Forge is different than e.g. the one that I can submit using a Python script. I am trying to understand what the limitations are. Right now it seems special characters, line breaks, spaces all cause the API call to fail. This is most likely because I have a knowledge gap. I spent a couple of hours trying to find a solution in the community. I might have missed a posting or Atlassian documentation. Any hints are welcome.

@Meinhard,

Can you say more about which REST API endpoint you are calling to create the page?

1 Like

Thanks for following up Ian. I am using

api.asUser().requestConfluence(route`/wiki/api/v2/pages`)

I added '<br></br>' after each paragraph which adds a line break. Unfortunately I don’t recall where I found this so that I can’t provide a reference to the source.

2 Likes