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

Posting a Result via JSON


#1

I am really struggling to find a format that I can post to JSON from postman. Can someone please post a few examples based on the requests I am trying to complete?

I was able to get the get_case working
http://SERVERXYZ/testrail/index.php?/api/v2/get_case/3651

TestRail Values:
R169
T17769
C3651

but I just cant get the add_result to work.
http://SERVERXYZ/testrail/index.php?/api/v2/add_result/3651&test_id=17769&status_id=1&comment=pass&version=2.0&elapsed=30s&defects=ABC-5310&assignedto_id=2

Every time I get the following Error.
“error”: “One of Status ID, Assigned To or Comment is required”

Any help would be greatly appreciated. Thank You in advance!


#2

add_result requires the test_id, not the case_id.

e.g.

http://SERVERXYZ/testrail/index.php?/api/v2/add_result/17769


#3

Hi Derek,

Thanks for your posting! You would to submit the fields in JSON format and via the HTTP request body. We have low-level example of how this looks like here:

http://docs.gurock.com/testrail-api2/accessing

It’s alternatively also possible to use one of our official API bindings but it seems you are already using Postman instead. We don’t have experience with Postman to be honest but JSON is a standard format and I’m sure Postman has support for JSON as well.

https://www.getpostman.com/docs/requests
https://www.getpostman.com/docs/text_editor

Cheers,
Tobias


#4

Good Morning Glen @gmcdonald. Thank You for the example. Unfortunately I am still getting the same error. I tried to dial the expression back to

SERVERXYZ/testrail/index.php?/api/v2/add_result/17769&status_id=1&comment=pass

Please see attached screen shots (note: the url was updated to a generic url After the rest was run)

and a bunch of other variations with no luck. Any other suggestions?

I have also been through all the documentation Tobias @tgurock mentioned and have multiple variations I could cobble together from the examples. I have also double check my Json through and independent site to verify it was well formed

/api/v2/add_result/17769
status_id:1
assignedto_id:5
comment:pass

I have verified its not a header, authentication or connection issue by validating that the Get interacts via postman.
http://SERVERXYZ/testrail/index.php?/api/v2/get_case/3651

Here is a (very) short list of the variations I have tried by just providing the url and letting postman auto format the parameters

SERVERXYZ/testrail/index.php?/api/v2/add_result/17769:&status_id=1
SERVERXYZ/testrail/index.php?/api/v2/add_result/=T17769:&status_id=1
SERVERXYZ/testrail/index.php?/api/v2/add_result/T17769:&status_id=1

Then I also tried explicitly formating the parameters based on the examples from Tobias.

{
“results”: [{
“test_id”: 17769,
“status_id”: 5,
“comment”: “This test failed”,
“defects”: “TR-7”
}]

}

SERVERXYZ/testrail/index.php?/api/v2/add_result/17769 HTTP/1.1
{ “status_id”: 1 }

SERVERXYZ/testrail/index.php?/api/v2/add_result/17769 HTTP/1.1
status_id:1

All producing this error
{
“error”: “Field :test_id is not a valid ID.”
}


#5

Hi Derek,

There a few issues with your attempts. First of all, all parameters listed under “Request fields” in the API documentation must be passed via the HTTP body and not as query/GET parameters. You would also need to format the HTTP body as JSON:

POST /index.php?/api/v2/add_result/1 HTTP/1.1
Host: example.testrail.com
Content-Type: application/json

{ "status_id": 1 }

(HTTP request including request headers and JSON body)

Another issue are the test IDs you submit. add_result expects the numeric part of the test IDs (T### numbers in the UI) and it seems that 17769 is not a valid test ID. Is this a test case ID instead (the C### numbers)?

Cheers,
Tobias


#6

Hi Tobias,
I appreciate the help and patience.

Here are the values from TR

TestRail Values:
R169
T17769
C3651

I updated the request using the body (not the parameters) See Screenshot

Thoughts?


#7

Alright Gents, I am closing the book on this one. Postman must be doing something funky because I was able to get the exact same http requests to work via SoapUI.

Thanks,
Derek


#8

Thanks for the update, Derek, sounds good! One issue I see with the previous screenshot is that you are submitting the API method (api/v2/add_result/…) as part of the request body but you should only include the actual JSON. But good to hear that it works now with SoapUI!

Cheers,
Tobias