Similar to this question:https://community.atlassian.com/t5/Jira-questions/How-do-you-create-a-Jira-issue-with-code-snippet-in-the/qaq-p/1234646
There doesn't seem to be any documentation on how to do this. Most the examples and documentation list a single line description, which is not the case many times in creating JIRA descriptions. The lack of error messages when calling the JIRA API doesn't help, as one small incorrect syntax can give a 400 client error.
It seems as if it's more black box testing calling the API to determine what works.
How do I include multiple lines in the description or key value pairs to make a successful jira API call? I'm currently calling this from python and have tested to see if the python to json syntax is correct and it is. However, still receive a 400 error after repeating the steps and same code in the link above.
Any suggestions and resolutions?
Hello @Mont
"Any suggestions and resolutions?"
Start by reading the documentation on Atlassian Document Format (ADF). This is the structured language used to build the content of the description field via the v3 REST API of Jira Cloud (which I took a random, wild guess you're referring to, since that's what the question you linked to is discussing).
To make a soft line break, you just put a newline char '\n' into the JSON text object:
{
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "This is the first line\nThis is the second line"
}
]
}
]
}
To make a hard line break, put a hardBreak object between the JSON text objects:
{
"version": 1,
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "This is the first line"
},
{
"type": "hardBreak"
},
{
"type": "text",
"text": "This is the second line"
}
]
}
]
}
Use the Document Builder to type in plain or wiki markdown text to see what the resulting ADF is.
There is also the Document Viewer where you can do the opposite... type in ADF and it will render the resulting text.
Have fun
<VeryBigHint>
Oh, and when you ask questions and don't say which type of Jira you are using (Cloud, Server or DataCentre), you don't say which REST API endpoint you are using, you don't provide code samples of what you are trying to do and you don't tag your post with the correct product tags, your question is just like a black box where people have just try and guess what it refers to.
</VeryBigHint>
I think I should probably note that I've already tried this. It doesn't work for me. I've tried it again after reading this post and I receive an error message. I have pasted what you posted above in the description and also what was posted in the documentation on the JIRA website.
HTTPError: 400 Client Error: for url: https://jira.<domain>.com/jiradc/rest/api/2/issue?updateHistory=false
I copied the code posted as answer in this form and then tried to narrow it down for trial and error as all returned an error message.
My code is here below
issue_dict = {
"project": {
"id": '123'
},
"summary": "test summary 3",
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Helo world"
}
]
}
]
},
"reporter": {"name": "id123"},
"issuetype": {"name": "Task"},
"priority": {
"name": "Critical"
}
}
I am using API version 2:
I'm also pretty sure the documentation posted here was noted in the question I linked.
Since this service is providing an API to customers who spend pay for it and there's nothing in python API documenetation regarding where to put this, I assumed this would be under description.
Hopefully this is less like a blackbox to whoever else reads this now.
NOTE when I remove this from description it works if I just put single line string.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
"I am using API version 2"
Well, that explains it. You are reading the wrong documentation for the wrong product.
ADF support is a feature of the v3 REST API of Jira CLOUD ONLY, not the v2 REST APIs of Jira SERVER or Jira DATA CENTER, which I assume you are using.
For all the v2 endpoints for any Jira platform type, the content of Description field is plain text with optional Wiki markup. Put markup formatted plain text into your JSON description object, and that's what will be rendered in the Description field.:
{
"project": {"key": "BPT"},
"issuetype": {"name": "Story"},
"summary": "Test of line breaks",
"description": "First line\nNext line with *bold text*"
}
Will result in the issue:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.