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

API to get tests in section



I have a section ID and need to map that to test cases under it. How do I do that with the API?

get_test() and get_tests() do not say anything about sections:

get_section() and get_sections() say nothing about tests:

The problem I am trying to solve is to use the API to automatically map a CI test case to a test plan/test run/test case. Tests are grouped under sections and there can be several with same name (e.g., tst_install) but under different sections.

Currently I can find the matching test plan, matching test run configurations, the test section inside the plan (matched by section name), but fail at the point of finding the exact test under the test run to upload results to. Need a way to find the test case(s) under given section.

How to?


Hi there,

Thanks for the post! In order to get all test cases within a section you’ll need to use the get_cases API method. You can use the method with a project or suite ID to list all cases within a project or suite, and you can append &section_id=<ID> to the call URL to see the test cases for a specific section.

I hope that helps!


Thanks. It helps. I guess I get confused with test vs case. Now I found the correct section a test is under.

Now my problem is, I have a test plan with a set of test runs under it. For each of these test runs, there is a set of test cases.

How do I find which test cases are attached to a test run? I first query the TestRail API for a specific test plan using various filtering criteria. When I find the plan, I need to find the correct test run ID for the test case. I have the test case ID from filtering the project tests and sections as you showed above.

The test run API only gives me “include_all” to tell if all tests in suite were included. But I cannot find a way to get list of what tests were selected for ar un if not all.

This is the test run AP I mean:

And I need both test id and run id for the add_results_for_case API call.

So I have test case id, test plan id, and all the test run ids under the plan. How do I find out which of these test runs is the test id attached to?


Hey there,

This is when the get_tests method will come in handy. In TestRail, the test cases are created independent of any runs, and are there to be a reusable resource throughout the testing cycles of a project. Once a test case is added to a test run, it is given a new ID as a test that is specific to the context of that run. If you’re wanting to get a list of test cases that are used in a run, you can use the get_tests method with the run ID to see a list of all of the tests contained in the run, and the response will include the test case IDs.

Hope that helps!


I am a bit late to the reply but this is what I ended up using and it works for me. The overall process becomes rather convoluted with so many chained calls all around but it works. Thanks.