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

Run_id fails to be passed as a variable for the API add_result_for_case



All I am trying to do is create a TestRun, obtain the run_id and use this run_id to update the result. Here is my code:

run = client.send_post(‘add_run/2’,
“suite_id” : 11,
“name” : ‘Automation Bhavesh’,
“assignedto_id” : 4,
“include_all” : 0,
“case_ids” : [165]

runid = run[‘id’]
print runid

“status_id” : 1,
“version” : “3.4.0”,
“elapsed” : “5m”,

However this leads to a failure as follows:

Traceback (most recent call last):
File “”, line 28, in
“elapsed” : “5m”,
File “/Users/blad/Documents/Python/Testrail API/”, line 51, in send_post
return self.__send_request(‘POST’, uri, data)
File “/Users/blad/Documents/Python/Testrail API/”, line 79, in __send_request
(e.code, error))
testrail.APIError: TestRail API returned HTTP 400 (“Field :run_id is not a valid ID.”)

***When I try to pass manually the correct value for the run_id, there is success. Please let me know why can’t I pass the variable when I am calling the API and what is the correct method of doing it.


Been a while with python, so my memory of variable interpretation in strings might be faulty, but would it work if you changed the one line to this:

client.send_post('add_result_for_case/' + str(runid) + '/165',

Wasn’t sure if runid was a string or int, so I added the str() to it.