Jira API v2 bad request using special caracteres

Deleted user July 22, 2021

Hello!

I'm using the Jira API v2 to create an issue. I'm facing a trouble when I send a string with special caracteres on description filed.

Here the example that is working for me when I send a POST method to rest/api/2/issue:

var dataToCreateAnIssue = "{\"fields\":{\"project\":{\"key\":\"" + key + "\"},\"summary\":\"" + title + "\",\"description\":\"" + descp+ "\",\"issuetype\":{\"name\":\"Bug\"}}}";

But when I have special caracteres like ">" or "<" in my string dataToCreateAnIssue, I got the error 'The remote server returned an error: (400) Bad Request.'
I need to automate it, and my string will always have various special caracteres.

How can I resolve this? Any suggestion?

2 answers

0 votes
Deleted user August 5, 2021

Still have the same trouble using your suggestion to additional formatting, it is working with some strings and the same with various special caracteres don't worked. There's a limit of caracteres that I can use in description?

0 votes
Earl McCutcheon
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 23, 2021

Hello @[deleted] ,

The description field needs some additional formatting to preserve the input variables as text rather than command inputs for the API call, and the following stripped-down example should do the trick to pass in the "<" and ">" characters as a basic example for the minimum inputs needed for a create issue POST:

curl --request POST \ 
--url
'https://your-domain.atlassian.net/rest/api/3/issue' \
--user
'email@example.com:<api_token>' \
--header
'Accept: application/json' \
--header
'Content-Type: application/json' \ --data '{
"update": {},
"fields": {
"summary": "TEST API CREATE ISSUE",
"issuetype": {
"id": "10001"
},
"project": {
"id": "10000"
},
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "TEST API description with special characters < and >",
"type": "text"
}
]
}
]
}
}
}'

Additional details on the field formating check out the example section under the Create issue API documentation 

Regards,
Earl

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events