Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

Invalid or incomplete JSON string in API request


#1

when trying to do a post request using the add_results_for_cases via curl, I encounter the following error: {"error":"Invalid or incomplete JSON string in API request."}

Below is the curl command I used:
$ curl -g -u “username:password” -H “content-type: application/json” -d ‘“results”:[{“case_id”:429098 ,“status_id”: 1, “comment”: “This test passed"ssed”},{“case_id”:429100 ,“status_id”: 1, “comment”: “This test passed”},{“case_id”:429101 ,“status_id”: 1, “comment”: “This test passed”},{“case_id”:429102 ,“status_id”: 1, “comment”: “This test passed”}]’ https://testrailURL/index.php?/api/v2/add_results_for_cases/1956

I would like to know whats wrong with the json data I used. or can you tell me the correct format the API will accept?


#2

There’s a missing { at the beginning of the data string and a missing } at the end. Also, there might have been a cut-n-paste issue with the comment data on the first result. Here’s the command with those changes made:

curl -g -u "username:password" -H "content-type: application/json" -d '{"results":[{"case_id":429098 ,"status_id": 1, "comment": "This test passed"},{"case_id":429100 ,"status_id": 1, "comment": "This test passed"},{"case_id":429101 ,"status_id": 1, "comment": "This test passed"},{"case_id":429102 ,"status_id": 1, "comment": "This test passed"}]}' https://testrailURL/index.php?/api/v2/add_results_for_cases/1956


#3

Oh, another thing. It’s a POST to add results so you’ll need to specify that.

curl -g -u "username:password" -X POST -H "content-type: application/json" -d '{"results":[{"case_id":429098 ,"status_id": 1, "comment": "This test passed"},{"case_id":429100 ,"status_id": 1, "comment": "This test passed"},{"case_id":429101 ,"status_id": 1, "comment": "This test passed"},{"case_id":429102 ,"status_id": 1, "comment": "This test passed"}]}' https://testrailURL/index.php?/api/v2/add_results_for_cases/1956