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

SOLVED - add_results return HTTP 400 without additional error messages


#1

Hi guys,
I’m implementing some APIs on testrail using the provided java connector.
I call the “add_results” method as

client.sendPost(“add_results/” + runId, object);

where runId=20 (and can be retrieved correctly on the web portal) and object is structured as:

{“results”:[{“status_id”:1,“comment”:“Comment”,“test_id”:101}]}

Even here, the test_id 101 exists and can be retrieved on the web portal.

Doing such a call, I got a

com.gurock.testrail.APIException: TestRail API returned HTTP 400 (No additional error message received)

Enabling the debug, I can read in the log file:

[D] 2016-01-07 16:14:01 [163ms]: id:41487795 SELECT *
FROM runs
WHERE (id = 20) (at Database_driver->_after_query)
[D] 2016-01-07 16:14:01 [163ms]: id:41487795 Query took 0.7 ms (at Database_driver->_after_query)
[D] 2016-01-07 16:14:01 [165ms]: id:41487795 SELECT *
FROM projects
WHERE (id = 20) (at Database_driver->_after_query)
[D] 2016-01-07 16:14:01 [165ms]: id:41487795 Query took 0.57 ms (at Database_driver->_after_query)
[D] 2016-01-07 16:14:01 [167ms]: id:41487795 SELECT *
FROM projects
WHERE (id = 20) (at Database_driver->_after_query)
[D] 2016-01-07 16:14:01 [167ms]: id:41487795 Query took 0.61 ms (at Database_driver->_after_query)
[D] 2016-01-07 16:14:01 [168ms]: id:41487795 SELECT *
FROM project_access
WHERE (project_id = 20) AND (user_id = 8) (at Database_driver->_after_query)
[D] 2016-01-07 16:14:01 [168ms]: id:41487795 Query took 0.41 ms (at Database_driver->_after_query)
[D] 2016-01-07 16:14:01 [169ms]: id:41487795 Loaded model “role” (at Loader_core->model)
[D] 2016-01-07 16:14:01 [170ms]: id:41487795 SELECT *
FROM roles
ORDER BY display_order ASC, name ASC (at Database_driver->_after_query)
[D] 2016-01-07 16:14:01 [170ms]: id:41487795 Query took 0.59 ms (at Database_driver->_after_query)
[D] 2016-01-07 16:14:01 [174ms]: id:41487795 SELECT *
FROM fields
WHERE (entity_id = 2)
ORDER BY is_system DESC, location_id ASC, display_order (at Database_driver->_after_query)
[D] 2016-01-07 16:14:01 [174ms]: id:41487795 Query took 0.63 ms (at Database_driver->_after_query)
[D] 2016-01-07 16:14:01 [178ms]: id:41487795 Loaded model “cache” (at Loader_core->model)
[D] 2016-01-07 16:14:01 [180ms]: id:41487795 SELECT *
FROM statuses
ORDER BY display_order (at Database_driver->_after_query)
[D] 2016-01-07 16:14:01 [180ms]: id:41487795 Query took 1.08 ms (at Database_driver->_after_query)
[E] 2016-01-07 16:14:01 [181ms]: [ValidationException] Field :custom_environment is a required field.
Details:
File: /var/www/html/testrail/sys/helpers/ex.php
Line: 25
Status Code: 500
Host: share.vivates.ch
Uri: /testrail/index.php?/api/v2/add_results/20 (POST)
Browser: Java/1.7.0_79
PHP: 5.4.16
Server: Linux 3.10.0-229.20.1.el7.x86_64 #1 SMP Tue Nov 3 19:10:07 UTC 2015 x86_64
Trace:
at ex::raise (ex.php:25)
at ex::raise (controller.php:289)
at Controller->_validate (v2.php:2966)
at V2_controller->_add_results_validate_common (v2.php:2817)
at V2_controller->add_results (controller.php:254)
at Controller->_invoke_web_call (controller.php:167)
at Controller->_invoke_web (controller.php:119)
at Controller->_invoke (gizmo.php:107)
at require_once (index.php:106)

Any suggestion?

Thank you in advance


#3

Hi guys,
digging better in the documentation, the variable “custom_” was, as the name clearly suggests, a custom variable.
Since it was defined as mandatory, but I didn’t send it in my POST request, Testrail correctly screamed about that.
By sending such variable, I got the right reply.


#4

Hello Maurizio,

Thanks for your posting and great to hear that you found the issue already :slightly_smiling:

The validation error should also be returned as part of the API response (as Java exception) and we will make sure to review why this isn’t the case here.

Cheers,
Tobias


#5

i am also facing the above issue and am trying to send this object in add results apt

{“status_id”:“5”,“Comments”:“girishauto”,“case_id”:“2957964”,“version”:1.0,“custom_testcase_id”:“tc001”,“custom_script_id”:“tc001”}

the code
client.sendPost(“add_results_for_cases/”+4465,resultfi);

the error
TestRail API returned HTTP 400(“Field :results is not a valid array.”)
at com.gurock.testrail.APIClient.sendRequest(APIClient.java:285)
at com.gurock.testrail.APIClient.sendPost(APIClient.java:130)
at resr.gi.main(gi.java:162)

PLS HELP ME FIX THIS ASAP


#6

Hi there,

Thanks for your reply. The add_result_for_cases method would expect a valid array for the results and it looks as though you’re attempting to add just a single result. Can you try the add_result_for_case method using the same code to see if this works for you?

Regards,
Marco