Is it possible to export a table to CSV using the REST API?

Is there a way to use the Confluence REST API to identify a table on a page, then export that table to CSV file programmatically?

I was able to query the page and expand body with “the expand=body.export_view” and I was able to see the HTML of the table. Is there an easier way to convert this to a CSV file using the Confluence REST API?

Welcome to the Atlassian developer community, @evensteven

There are significant differences between Confluence Cloud and Server/Data Center that would make for different answers. Which one are you using?

Hi @ibuchanan , we are using Confluence Data Center

Your response implies that there are two answers?
It would be nice if you could just share them with us …

Hi @evensteven , I have the exact same question.
Did you get an answer, or could you solve the problem otherwise?

Welcome to the Atlassian developer community @etienne.

My short response is I don’t know it.

For a longer response, I do know the document formats are different between the 2. On Cloud, a table is a node in the Atlassian Document Format. Here, you would need a JSON parser and understanding of that specific schema. On Server & Data Center, a table is a HTML in the Confluence Storage Format. In this scenario, you would need an HTML parser and general understanding of HTML tables. I think there are examples in many programming languages.

The REST API calls for both are similar. For Server/DC, there are a set of REST API examples showing some of the expansions and manipulations of the document format.

Hi @ibuchanan ,

Thanks a lot for your response. We are currently in a migration from Server to Cloud - I guess it’s better to wait for this to be finished, before I start to mess around with HTML parsing.

However, it seems that in neither case there is a simple out-of-the-box solution … I was hoping for finding the table by some ID and then being able to construct an URL for the CSV download as it is triggered by the ‘Export to CSV’ item from the table’s filter menu. This might have involved some parsing to find the table, but could have avoided parsing the table’s content itself.

So not as easy as I had hoped, but no problem. Thanks again and have a nice day …
Cheers

@etienne,

I confirm there isn’t a simple out-of-the-box solution. Indeed, I was curious about this “Export to CSV” that you mentioned and learned that’s likely provided by an App. Maybe that’s a good feature request for them to provide that kind of export through their own REST APIs?

Years ago I was involved in building a Confluence Cloud customisation to create a global report based on aggregating Page Properties Reports in different spaces. Parsing HTML worked just fine.

Yes, parsing HTML is doable. But it must be done manually - annoying if you have HTML within the TD’s. The CSV export does all of this already: eliminating HTML tags, doing the separators and masking for CSV, etc. And if the number of columns or the table formatting changes, you can run into problems.

There is some DIV with a ‘tablefilter-table-wrapper’ class around such tables. And this DIV has an ‘id’ that is reused as ‘csv-export-…’ identifier for the button that triggers the export. Haven’t looked into the JavaScript yet to see how the URL is build - hoped someone already found out, or that there was a more standard way to do.

But as @ibuchanan mentioned, the table filter wrapper including the CSV export obviously comes with an extension and is not a build in feature. Did not know that - my bad. If it’s not build in, then it’s very unlikely that there is a common CSV export function / download URL / API call. Sorry for the confusion.