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

How to set case_ids when add a test run in java?


need help on how to set the case_id. I was try to set the value as

Map<String, Object> data = new HashMap<String, Object>();

data.put(“name”,“this is test run created via API”);
data.put(“case_ids”, new int[]{17,86});
data.put(“suite_id”, “1”);
data.put(“inculde_all”, “false”);
c = (JSONObject) client.sendPost(“add_run/10”, data);

After run the class, I got the error message as

TestRail API returned HTTP 400(“Invalid or incomplete JSON string in API request.”

Any suggestion?

400 Bad Request, response on when creating a new test run from API call


Thanks for your posting. You would need to pass the case IDs as List object and this looks as follows, for example:

List cases = new ArrayList();
cases.add(new Integer(17));
cases.add(new Integer(86));
data.put("case_ids", cases);

I hope this helps!



it works!

appreciate the help!


Great to hear that and you are welcome!



Hi, please help with following code,
this code results in successful creation of a new Test Run everytime, but the problem is that instead of creating Test Run with the 2 caseIDs i have given, it creates Test Run with all 1500 test cases I have.
Also how can I assign a name to the Test Run it creates, as now it is creating new Test Run with name ‘Master’ everytime

    Map data = new HashMap();
    data.put("created by farhan","this is test run created via API");

    data.put("suite_id", "34");

    List cases = new ArrayList();
    cases.add(new Integer(5804));
    cases.add(new Integer(5777));

    data.put("case_ids", cases);
    data.put("inculde_all", "false");

    c = (JSONObject) client.sendPost("add_run/1", data);


I just found the answer
instead of using
data.put(“inculde_all”, “false”);
i used
data.put(“include_all”, new Boolean(false));

and it worked fine i.e. created test run with only 2 testcases i wanted



Hi @farhan,

Thanks for your posting. Yes, you would need to use objects and the JSON serializer would expect this format. Great to hear you found it out already and that it works now!



Hi @tgurock

I will happy if you can tell me what does not work in my code.
I want to create new test run and add to it 2 test cases. My code successful create a new test run but don’t add cases to it.
Map data = new HashMap();
data.put(“name”, testRunName);
data.put(“include_all”, false);

    List cases = new ArrayList();
    cases.add(new Integer(3347615));
    data.put("case_ids", cases);
    JSONObject c = (JSONObject) client.sendPost("add_run/" + String.valueOf(projectId.getId()), data);

Thanks in advance
PS: I also try to create a new one and then to update, but same same… can not see cases in test run