Using add_case method I want to add a test case to a particular test suite. But it requires the section_id which I am not able to find programmatically in Java as I use get_sections to get the array of sections but no section_id key can be seen there.
id field is the section_id for that section.
But I am getting com.gurock.testrail.APIException: TestRail API returned HTTP 400(No additional error message received) by using id field.
I am using following code in Java -
Map data = new HashMap();
JSONObject jSon = (JSONObject) client.sendPost(“add_section/2” , data);
Map data1 = new HashMap(); data1.put("title", "Test");
client.sendPost(“add_case/” + jSon.get(“id”).toString() , data1);
Thanks for your posting! Do you know which of the API requests fail? I assume the
add_section call succeeds and
add_case fails? Section IDs can either be looked up as part of the
add_section result like you do in the example, or by looking at the list of sections that is returned by
get_sections (via the
id property in both cases).
You are right the add_section call succeeds and add_case fails…I also tried by getting the JSONArray using getSections and tried to extract by get the “ID” property.
Can you give show me any Java code snippet which is doing the add_case call or else can you show me how to see the section ID using in my TestRail UI because I am not able to find the section Id anywhere in the UI(please refer the attached snapshot).
Thanks for your reply! The section ID is not directly exposed via the UI but the example code from above looks correct. Could you please check if you have a required field (besides Priority/Type) configured for the cases? In this case, the API request would also fail if you don’t include the field. The API request would also return this as part of the API response. If you don’t see this as part of the exception, could you please step into the Java API binding code (at around line 190) and see what’s returned by TestRail?
Thanks a lot for your suggestion. Checking the configuration and investigating the System Logs to find the required field while making the add_case call solved my purpose.
Actually what donalaya answered that id field is the section ID was right. I verified this by just adding a case manually in one of the sections and getting the section id programmatically by using the get_Case:-
JSONObject testCase = (JSONObject) client.sendGet(“get_case/2021”);
Then I retrieved the sections and checked the ID of that section which proved that the “ID” field is the section ID:-
JSONArray sections = (JSONArray) client.sendGet(“get_sections/2&suite_id=15”);
Following are the snapshots in my debug environment which I want to put for reference, which could be helpful for others as well while visiting this post:-
So now I got my answer. The System Log in TestRail is really a great thing to investigate the errors while making calls programmatically.
Great to hear that it works now The ‘field is required’ message should also be part of the Java exception you get as part of the sendPost call (in addition to the System Log in TestRail) but we will make sure to review this again on our side.