Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Jira API v2 bad request using special caracteres Edited

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?

1 answer

0 votes

Hello @Rafael Gustavo Panizzon ,

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
Community showcase
Published in Jira

⏰ Day in the life of a Jira Admin!

Hello Community! We thoroughly enjoyed this just-for-fun conversation in the Jira Admin Group about what it's like to be a Jira Admin. For #JiraJuly, our talented designers created these graphics t...

947 views 2 22
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