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

Simple "get_results" Demo failed



I am trying to do a simple demo to “get_results” of an test case.
I ran the code below, but got “HTTP 301” error. Our Testrail login Url is “”, so what the root url should be set for APIClient url? or something else caused the failure? Thanks!

public class TestrailHttpRequest {

public static void main(String[] args) throws Exception {
    APIClient client = new APIClient("");

        JSONObject json = (JSONObject) client.sendGet("get_results/T86082");
    catch(APIException e){
        System.out.println("Error Message is: "+e.getMessage());


It failed with error below:

com.gurock.testrail.APIException: TestRail API return HTTP 301 (No additional error message received)
at com.gurock.testrail.APIClient.sendRequest(
at com.gurock.testrail.APIClient.sendGet(
at TestrailHttpRequest.main(
Error Message is: TestRail API return HTTP 301 (No additional error message received)


The first problem is you included the T in the test id (maybe this works but not in example code). I believe it is implied by the request you are making.

Since you are requesting results you will get a JSONArray of JSONObject types back.

This should work:
JSONArray json = (JSONArray) client.sendGet(“get_results/86082”);

and then iterate over json to output JSONObjects…

for ((JSONObject) obj : json) {


Thank you Jgourlay, after removing the “T” in test id, then code works!

I have two more questions:

  1. I am not the administrator of our Testrail, how can I know which version of Testrail is?
  2. With API “add_result” or “add_result_for_case”, how can I attach file when add test result by API?



Hi Vincent,

Thanks for your posting. You get the 301 response because TestRail is running with https (and not standard http), so the address needs to be:

  1. The version of TestRail is shown in the administration area but also in the help/about dialog (Help & Feedback > About TestRail in the upper right) or on the login screen.

  2. Uploading attachments via the API is not directly possible and we recommend uploading files and screenshots to an external location and then including a link (or embedding the images) as part of the test result comment.

I hope this helps!



Hi Tgurock,

Thank you for your response, your suggestions are really helpful, I found the version of the Testrail, and good to know the best way of uploading screenshots by API.



You are welcome, Vincent, great to hear that this helps :slight_smile: