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

How do you create a Jira issue with code snippet in the description using REST API?

I am trying to create a Jira issue with a code snippet in the description.

I am new to the Atlassian REST API, so help would be much appreciated.

Also, a link to what kinds of formatting the description field can take for creating a Jira issue would be much appreciated.

2 answers

2 accepted

0 votes
Answer accepted
Nir Haimov Community Leader Nov 24, 2019

Hi,

You need to send a POST call to:
https://your_jira_url/rest/api/2/issue/{issueKey}/comment

add header:
"Content-Type", "application/json"

your body data should be like:
{
    "body": "{code:java}// code placeholder{code}"
}

I want to create an issue and insert a description. The code block needs to be in the description. I saw something here:

https://confluence.atlassian.com/doc/code-block-macro-139390.html

 

I have tried inserting the code macro inside of the "description" text and it worked.

{
"fields": {
"summary": "Some Summary",
"description": "{code:title=Detailed Results|theme=FadeToGrey|linenumbers=true|language=javascript|firstline=0001|collapse=true}some code with proper escapes{code}",
"project": {
"key": "some_key"
},
"priority": {
"id": "some_priority"
},
"issuetype": {
"name": "some_issue_type"
}
}
}

 

My underlying question is where I can find documentation for this. What attributes and fields can I place inside the "description" attribute?

0 votes
Answer accepted

After many trials and errors and trying to see what the Jira UI was sending to its backend, I tried something like this as the JSON body with a POST call to "/rest/api/3/issue/" to create an issue:

{
"fields": {
"summary": "Some Summary",
"description": {
"version": 1,
"type": "doc",
"content": [
{
"type": "codeBlock",
"attrs": {
"language": "javascript"
},
"content": [
{
"type": "text",
"text": "some code here with proper escapes"
}
]
}
]
},
"project": {
"key": "some_key"
},
"priority": {
"id": "some_priority"
},
"issuetype": {
"name": "some_issue_type"
}
}
}

 

I'm not sure what the best way to do this is, so I think there needs to be more documentation and examples. Maybe I am looking at the wrong places, but the documentation looks a little sparse.

https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-rest-api-3-issue-post

Screen Shot 2019-11-25 at 11.42.26 AM.pngI would like to know what attributes I can mess around with for "description", but the "fields" attribute is just an object without any explanation of how to utilize the "description" attribute inside of it.

Suggest an answer

Log in or Sign up to answer
TAGS

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