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

1 accepted

0 votes
Answer accepted

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

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

Hi @vkalakuntla ,

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

Hi @Earl_McCutcheon ,

 

On trying the suggested steps I am facing the below error:

Can not deserialize instance of java.lang.String out of START_OBJECT token

Could you please help.

 

Regards,

Debayan

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Opsgenie

Authentication Options for Atlassian’s Opsgenie

What’s New as of May 21, 2020 Hi there! We recently made some changes to the way you can leverage Single-sign on and authorization within Opsgenie. Based on customer preference and feedback we intr...

61 views 1 1
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