Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Curl throws error "There was an error parsing JSON"

Jehan Bhathena
Community Champion
August 11, 2023

I'm trying to search for the issues that we get out of a JQL query using CURL. I'm substituting the field name with a variable I fetch in the previous steps.

Variable is a migrated custom field eg."Field Name (migrated)"

curl --request POST --url 'https://<baseURL>.atlassian.net/rest/api/3/search' \
--header "Content-Type: application/json" \
--header 'Accept: application/json' \
--header "Authorization: Basic ${token}" \
--data "{\"jql\": \"\"${VAR}\" IS NOT EMPTY\"}"

 Error :

{"errorMessages":["There was an error parsing JSON. Check that your request body is valid."]}

When I try this with single quoted for the data it works, but I need to use double quotes so that the Variable can be expanded, does anyone know if the API request needs any updating

2 answers

1 accepted

1 vote
Answer accepted
Jehan Bhathena
Community Champion
August 13, 2023

Syntax that solved the issue for me: 

image.png

Explanation for the above syntax:

My input variable was a string like this : "Custom Field (migrated)", since this string contains whitespaces and a round bracket when I did not use the addition double quotes around it, bash assumed those needed to be considered as individual arguments and thus ended up making 3 different sub-vars (not the right term but for the ease of explanation adding it)

Reference : https://stackoverflow.com/a/10067297

Thanks to @Wagner Santos for hinting at using single quotes for all the parts that remain consistent.

0 votes
Wagner Santos
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 11, 2023

I have replaced --data with --json, and it worked for me. Could you please try it out?

--json '{"jql":"'$VAR' IS NOT EMPTY"}'
Jehan Bhathena
Community Champion
August 13, 2023

Hi @Wagner Santos ,

Thank you for the response, unfortunately this too did not work.

image.png

Below is the syntax :
image.png

I think it is the round brackets in the custom field name that is causing the issue.

Wagner Santos
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 14, 2023

Glad to hear you have found a solution already!

Regarding the --json unknown error, it seems to be related to your curl client version. --json parameter was introduced on version 7.82.0. So you might want to update it.

I also realized this parameter is just a shortcut to make your curl code cleaner when working with JSON. 😆 https://github.com/curl/curl/pull/8314 

curl --version can be used to check your client version.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events