Pulling a table from Confluence using Jira REST API
Asked by Charles Fleck:

I'm trying to pull a table from Confluence using the Jira REST API, but I don't seem to get the table's full HTML.

The HTTP Get request I'm sending is:

<https://simplexity.atlassian.net/wiki/rest/api/content/{my_page_id}?expand=body.storage>

I can find the table headers in the HTML body of the response, but I can't find any of the table entries. Is there a method to get the full body for the page's HTML? Including the whole table?

Thank you!

Charles


Answers:
author: Shawn C
body: Hi Charles,

That API Call should give you the Body Content (Storage) of the page referenced; the Confluence table would look something like this:

```
...
 "body": {
 "storage": {
 "value": "<p class=\"auto-cursor-target\"><br /></p><table><colgroup><col /><col /><col /><col /></colgroup><tbody><tr><th>A</th><th>B</th><th>C</th><th>D</th></tr><tr><td>?1</td><td>2?</td><td>3?</td><td>4?</td></tr><tr><td colspan=\"1\">Z</td><td colspan=\"1\">Y</td><td colspan=\"1\">X</td><td colspan=\"1\">W</td></tr></tbody></table><p class=\"auto-cursor-target\"><br /></p>"
...
```

What kind of table is on this page? Is it something generated by a Macro?

Cheers,  
Shawn

comments: author: Charles Fleck
body: Hey Shawn,

It definitely looks more like something being generated by a Macro.

This is the full body that I'm seeing:

"\<p\>\<a href=\\"[https://simplexity.atlassian.net/issues/?jql=project%20%3D%20PROJREQ%20AND%20component%20%3D%20%22Governance%20Exemption%22\\"\>List]() of Project Governance Wavered Projects\</a\>\</p\>\<h1\>Attachments\</h1\>\<p\>\<ac:structured-macro ac:name=\\"attachments\\" ac:schema-version=\\"1\\" ac:macro-id=\\"eeb7e41d-9ed9-406c-9628-029b82ed52a2\\" /\>\</p\>\<h1 class=\\"auto-cursor-target\\"\>Dashboard\</h1\>\<p\>\<ac:structured-macro ac:name=\\"detailssummary\\" ac:schema-version=\\"2\\" ac:macro-id=\\"3600a17b-d196-41d6-905b-144bef3f1601\\"\>\<ac:parameter ac:name=\\"firstcolumn\\"\>Project Status Page\</ac:parameter\>\<ac:parameter ac:name=\\"headings\\"\>Client-Name, Project-Name, Project-Number, Project-Manager, Sales-Lead, Signed-Quote-MSA, Client-Docs-Link, JIRA-Link, BOM-Link, PDM-Link, FW-SW-Repo-Link, EE-Repo-Link, Comments-Setup, PO-ECR-Coverage-Labor, PO-ECR-Coverage-Materials, PO-ECR-Coverage-Travel, Actual-Spend-Labor, Approx-Spend-Materials, Actual-Spend-Travel, Deposit-Invoiced, Invoiced, Invoice-Date-Last, Invoice-Balance-Overdue, Comments-Financials, Scope-Coverage, Client-Meeting-Last, Client-Meeting-Next, Project-End-Target, Comments-Client-Status, Resource-Status, Schedule-Status, Technical-Status, Risk-Status, Build-Status, Comments-Status, Requirements-Capture-Status, Requirements-Link, Design-Specs-Status, Design-Specs-Link, Test-Plan-Development-Status, Test-Plan-Link, Test-Plan-Execution-Completion, Acceptance-Criteria-Development-Status, Acceptance-Criteria-Link, Acceptance-Criteria-Execution-Completion, ME-Design-Review-Status, FW-and-SW-Design-Review-Status, EE-Design-Review-Status, Deliverables-Internal-Review-Status, Project-Retrospective-Link, Project-Retrospective-Date, Project-Closeout-JIRA-Link\</ac:parameter\>\<ac:parameter ac:name=\\"pageSize\\"\>200\</ac:parameter\>\<ac:parameter ac:name=\\"sortBy\\"\>Client-Name\</ac:parameter\>\<ac:parameter ac:name=\\"cql\\"\>label = \&quot;project-governance\&quot;\</ac:parameter\>\</ac:structured-macro\>\</p\>\<h1\>Page Update Report\</h1\>\<p\>\<ac:structured-macro ac:name=\\"recently-updated-dashboard\\" ac:schema-version=\\"1\\" ac:macro-id=\\"3d3e5a7b-02b4-41a2-8005-3faf5e243c90\\"\>\<ac:parameter ac:name=\\"spaces\\"\>\<ri:space ri:space-key=\\"\*\\" /\>\</ac:parameter\>\<ac:parameter ac:name=\\"labels\\"\>project-governance\</ac:parameter\>\</ac:structured-macro\>\</p\>\<h1\>Documentation\</h1\>\<ul\>\<li\>\<p class=\\"auto-cursor-target\\"\>Uses javascript bookmarklet to download table above as CSV file.\<br /\>Add as a new bookmark with this code for the URL:\</p\>\<ac:structured-macro ac:name=\\"code\\" ac:schema-version=\\"1\\" ac:macro-id=\\"9f4583b9-4de9-4e86-a68c-e442128b8f7a\\"\>\<ac:plain-text-body\>\<!\[CDATA\[javascript\&colon;void function(){function e(e,t){var a=document.createElement(\\"script\\");a.src=e;var n=document.getElementsByTagName(\\"head\\")\[0\],o=!1;a.onload=a.onreadystatechange=function(){o\|\|this.readyState%26%26\\"loaded\\"!=this.readyState%26%26\\"complete\\"!=this.readyState\|\|(o=!0,t(),a.onload=a.onreadystatechange=null,n.removeChild(a))},n.appendChild(a)}function t(){jQuery(\\".csvLink\\").remove(),jQuery(\\"table\\").each(function(e){jQuery(this).attr(\\"data-csvtable\\",e).before('\<a href=\\"%23\\" class=\\"csvLink\\" data-forcsvtable=\\"'+e+'\\"\>Export to CSV\</a\>')}),jQuery(\\".csvLink\\").click(function(){var e=\\"\\",t=jQuery(this).attr(\\"data-forcsvtable\\");jQuery('table\[data-csvtable=\\"'+t+'\\"\] tr').each(function(){jQuery(\\"td, th\\",this).each(function(t){0!=t%26%26(e+=\\",\\"),e+='\\"'+jQuery(this).text().replace(/\\\\xa0/g,\\" \\").replace(/\\\\r%3F\\\\n\|\\\\r/g,\\"\\").replace(/\\"/g,'\\"\\"')+'\\"'}),e+=\\"\\\\r\\\\n\\"}),jQuery(\\".csvLink\\").remove(),a(\\"TableExport.csv\\",\\"text/csv\\",e)})}function a(e,t,a){if(window.navigator.msSaveOrOpenBlob){var n=new Blob(\[decodeURIComponent(encodeURI(a))\],{type:\\"text/csv;charset=utf-8\\"});window.navigator.msSaveBlob(n,e)}else{var o=document.createElement(\\"a\\");o.setAttribute(\\"href\\",\\"data:\\"+t+\\";charset=utf-8,\\"+encodeURIComponent(a)),o.setAttribute(\\"download\\",e),document.body.appendChild(o),o.click(),document.body.removeChild(o)}}\\"undefined\\"==typeof jQuery%3Fe(\\"//code.jquery.com/jquery-latest.min.js\\",function(){t()}):t()}();\]\]\>\</ac:plain-text-body\>\</ac:structured-macro\>\<p class=\\"auto-cursor-target\\"\>\<br /\>\</p\>\</li\>\<li\>Uses Excel file with:\<ul\>\<li\>Power Query to pull in data file, clean up columns, create calculated data.\</li\>\<li\>Conditional formatting to highlight cells based on values.\</li\>\</ul\>\</li\>\</ul\>\<p\>\<br /\>\</p\>"

Is there a method to retrieve the table using the REST API even if it's generated by a Macro?

Thank you!

Charles


author: Shawn C
body: Hi Charles,

Thanks for the info. It looks like we're using the [Recently Updated Dashboard](https://confluence.atlassian.com/pages/viewpage.action?pageId=169607931) macro and I'm afraid that this macro is dynamically generated on page load. Due to this, we'll not have any HTML content until after we visit the page and view its source/inspect element.

If you could provide me with some additional information about what you're trying to pull and report on in this or other macros that we'd need the HTML for, I could submit a Feature Request on your behalf with our Developers.

Regards,  
Shawn


author: Charles Fleck
body: Hey Shawn,

Thank you, that's very helpful! I'll have to check in with my manager to figure out what course of action to take. I'll let you know when I hear back.

Thanks again,

Charles


Tags: atl-adm

rest-api