Add text as a table format to Jira comment..

Deleted user December 3, 2019

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

1 accepted

1 vote
Answer accepted
Earl McCutcheon
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 4, 2019

Hello @[deleted] ,

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

Deleted user December 5, 2019

Ok fine..Thanks for your reply.

will try and let you know ..

Like Earl McCutcheon likes this
Deleted user December 12, 2019

Hi Earl,

Is there anyway to pass the dynamic string (in table format) to JSON (which will be used to add comment to JIRA). Or do we need to build the Json object for it?

 

Thanks

Vishnu

Earl McCutcheon
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 13, 2019

Hi @[deleted] ,

Not that I am aware of, the API is expecting the input data in a raw JSON formatted package and the Front end is where you have to go to interface with the human readable content as it has the application code to run all the conversions to render the data into the human readable format.

Regards,
Earl

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events