It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Add text as a table format to Jira comment..

Hi All,

I am looking to add a string in table format to JIRA Comment like the below.

heading 1  heading 2    heading 3
col A1        col A2          col A3
col B1        col B2          col B3

Trying to consume JIRA API for adding comment and using the below JSON format.

{
    "body": {
    "type": "doc",
    "version": 1,
    "content": [
     {
         "type": "paragraph",
         "content": [
       {
          "text": "This is Final Test from POC..",
          "type": "text"
      }
  ]
 }
]
}
}

Can any one tell me how to pass the string(table format) to JSON as mentioned above?

 

Thanks

Vishnu

1 answer

0 votes
Earl McCutcheon Atlassian Team Wednesday

Hello @vkalakuntla ,

To input the data as a table you will need to use the content type "table" and add in "attrs" variables for the tables settings. 

A super easy way to get the necessary elements and layout options is to first  create a test template in a comment and run a GET to see the formatting with a preformated table.

Using the example from your question above the output for the comment body will look like the following which i put through a json pretty print modifier to make it easier to read rather than the standard single line of text:

{
"body": {
"version": 1,
"type": "doc",
"content": [
{
"type": "table",
"attrs": {
"isNumberColumnEnabled": false,
"layout": "default"
},
"content": [
{
"type": "tableRow",
"content": [
{
"type": "tableHeader",
"attrs": {},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "heading 1",
"marks": [
{
"type": "strong"
}
]
}
]
}
]
},
{
"type": "tableHeader",
"attrs": {},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "heading 2",
"marks": [
{
"type": "strong"
}
]
}
]
}
]
},
{
"type": "tableHeader",
"attrs": {},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "heading 3",
"marks": [
{
"type": "strong"
}
]
}
]
}
]
}
]
},
{
"type": "tableRow",
"content": [
{
"type": "tableCell",
"attrs": {},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "col a1"
}
]
}
]
},
{
"type": "tableCell",
"attrs": {},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "col b1"
}
]
}
]
},
{
"type": "tableCell",
"attrs": {},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "col c1"
}
]
}
]
}
]
},
{
"type": "tableRow",
"content": [
{
"type": "tableCell",
"attrs": {},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "col a2"
}
]
}
]
},
{
"type": "tableCell",
"attrs": {},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "col b2"
}
]
}
]
},
{
"type": "tableCell",
"attrs": {},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "col c2"
}
]
}
]
}
]
}
]
},
{
"type": "paragraph",
"content": []
}
]
}
}

To make formatting and editing easier I recomend saving the above to a "test.json" file and pass in the data from the file rather than directly in the POST, using the following curl format would post the comment with the table:

curl -D- -u user@email:<API TOKEN HERE> -X POST --data @/path/to/test.json -H "Content-Type: application/json" https://<BASE_URL_HERE>.atlassian.net/rest/api/3/issue/<Issue_ID or Key>/comment

Regards,
Earl

Ok fine..Thanks for your reply.

will try and let you know ..

Like Earl McCutcheon likes this

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

2019: All Wrap(ped) Up Like a Present

Hindsight might be 2020 but looking back, a lot of cool new features rolled out in 2019. From new collaboration and organizational powers to fresh templates and handy integrations, it’s been quite th...

988 views 4 8
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you