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

Add_results returns an error


#1

I have such code:
Map data1 = new HashMap();
data1.put(“test_id”, 247959);
data1.put(“status_id”, 1);
data1.put(“comment”, “First test passed well”);
Map data2 = new HashMap();
data2.put(“test_id”, 247960);
data2.put(“status_id”, 1);
data2.put(“comment”, “Second test passed well”);
List list = new ArrayList();
list.add(data1);
list.add(data2);
List LIST = new ArrayList();
LIST.add(“results”);
LIST.add(list);
JSONObject c3 = (JSONObject) client2.sendPost(“add_results/1449”, LIST);
But got Exception in thread “main” com.gurock.testrail.APIException: TestRail API returned HTTP 400(“Field :results is a required field.”). Can somebody help me?!


#2

Hi!

Thanks for your posting. The final object you pass to sendPost needs to be a Map as well and this would look as follows:

Map d = new HashMap();
d.put("results", list);
.. = client2.sendPost("add_results/1449", d);

Cheers,
Tobias


#3

tgurock, thank you. As usual, your advices are perfect! :clap:


#4

That’s great to hear, thanks :smile:

Cheers,
Tobias


#5

Hi ,

I am getting error
exceptionTestRail API returned HTTP 404(“Unknown method ‘add_result_for_case’”)
and my code is below
ublic static boolean UPdatePASSTestRailResults(int tcid1) throws MalformedURLException, IOException, APIException{

//	int tcid1=T2009319;
    APIClient client = new APIClient("url");       
    client.setUser("username);
    client.setPassword("password");
     Map data = new HashMap();
    data.put("status_id", new Integer(1));
    data.put("comment", "The Test Case Executed with PASS Status");
    
    JSONObject r = (JSONObject) client.sendPost("add_result_for_case/609/18909", data);
   // Framework_Utils.InfoLog("The Test Case has been updated in TestRail with Pass status");
    return true;

}

Please let me know whts wrong in above code.


#6

Hi bhagya,

Thanks for your posting. The code looks and add_result_for_case was introduced with the initial release of the API. Can you check if the URL is correct? Do you use a TestRail Cloud instance (testrail.net/com)?

Cheers,
Tobias


#7

Hi ,
I am stuck with an issue.
I am able to do a get using this .
JSONObject c = (JSONObject) client.sendGet(“get_case/350”);
System.out.println(c.get(“title”));

i am successfully getting the title.But when i try to post using
JSONObject r = (JSONObject) client.sendPost(“add_results/T54756”, data);
its saying Exception in thread “main” com.gurock.testrail.APIException: TestRail API returned HTTP 400(“Field :run_id is not a valid ID.”).

Could you please help…i dnt know what to give here…


#8

I believe the run id can’t include the T - it should be just the numeric part (54756)


#9

Removed the T.Giving this one.
TestRail API returned HTTP 400(“Field :run_id is not a valid test run.”)
My question is that how should i know what is the run id…i know only the test case id here which is T54756

Map data = new HashMap();

    data.put("status_id", new Integer(1));
    
    data.put("comment", "failed");


    System.out.println("Data is put");
    JSONObject r = (JSONObject) client.sendPost("add_results/54756", data);

#10

D’oh - the “T” is a copy of the test case included in the run. You need the ID that starts with “R” (for Run) and only include the numeric of the Run id.


#11

i have run id then as R150.
I am giving that .
Map data = new HashMap();

    data.put("status_id", new Integer(1));
    
    data.put("comment", "failed");


    System.out.println("Data is put");
    JSONObject r = (JSONObject) client.sendPost("add_results/150", data);

still same issue:(
TestRail API returned HTTP 400(“Field :run_id is not a valid test run.”)
do i need to give test case id anywhere?


#12

Hi Sougata,

Thanks for the reply! The add_results method would expect an array if you plan to add multiple results to multiple tests, and you would need to specify the test run in the API call and the test ID in each entry of the array in the request content. As it looks as though you’re attempting to import just a single result, I would recommend using the add_result method. You can learn more about these and see examples of how to format the requests on our website here (I would recommend expanding all of the links in each API method to get the full details):

http://docs.gurock.com/testrail-api2/reference-results#add_result

Hope this helps!

Regards,
Marco


#13

Thanks,this has worked for me


#14

Hi Sougata,

Thanks for the update, glad to hear this helps!

Regards,
Marco