I try to add a new testrun via the TestRail API v2 method add_run in Java. It results in the following APIException:
com.gurock.testrail.APIException: TestRail API returned HTTP 400("Invalid or incomplete JSON string in API request.")
Here is my Java code (I'm using Java :
public JSONObject AddTestRunTest(String sTRUrl, String sUserName, String sPassword ) {
JSONObject jsonObject = null;
APIClient client = new APIClient(sTRUrl);
client.setUser(sUserName);
client.setPassword(sPassword);
String sjsonString = "{\"suite_id\": 166, " +
" \"name\": \"New TestRun\", " +
"\"assignedto_id\": 2 , " +
"\"include_all\": false, " +
"\"case_ids\": [18361, 18341, 18342, 18344, 18345, 18346, 18347, 18322, 18348, 18349, 18350, 18351, 18352] }";
try {
String sAPIMethod = "add_run/18";
jsonObject = (JSONObject) client.sendPost(sAPIMethod, sjsonString );
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (APIException e) {
e.printStackTrace();
}
return jsonObject;
}
Response-Code from method add_run 400 says: Invalid or unknown project.
BUT I'm sure that the project-, session- and even caseids are correct, existing and fit together.
I know this for sure, because if I do the same via curl it works.
Here my curl - command:
curl -D- -u Username:Password -X POST --data @create-testrun.json -H "Content-Type: application/json" TestRail-Host/testrail/index.php?/api/v2/add_run/18
Here the content of the file create-testrun.json (simply a copy of the content of my java-varaible - see above):
{"suite_id": 166, "name": "New TestRun", "assignedto_id": 2 , "include_all": false, "case_ids": [18361, 18341, 18342, 18344, 18345, 18346, 18347, 18322, 18348, 18349, 18350, 18351, 18352] }