Forum Discussion

RobertoM's avatar
RobertoM
New Contributor
3 years ago
Solved

How to get a list of test cases belonging to a folder including subfolders with APIs

Hello,

I am looking for a way to get a list of test cases belonging to a folder including also subfolders using API calls. If I use /testcase/search I can provide folder field into query key but in this way I only get the test cases that belong to the folder and not to subfolders.

Is there a way to do it?

  • jfelix's avatar
    jfelix
    3 years ago

    Hi, RobertoM 

     

    Since you're using the Confluence plugin, you're likely to be using the Server/DC version of the app. In this case, you can use the private API to achieve this.

     

    The endpoint is https://{{your-jira-url}}/rest/tests/1.0/testcase/search?archived=false&fields=id,key,projectId,name&maxResults=40&query=testCase.projectId+IN+({{your-project-id}})+AND+testCase.folderTreeId+IN+({{your-folder-id}})&startAt=0

     

    Use your Jira username and your password to authenticate, using Basic Auth authorization.

     

    You can get the project ID via the Jira REST API.

     

    Please keep in mind that this is not officially supported and therefore this endpoint might change in the future without any previous notice.

     

    It would be nice if you could raise this in the Ideas Portal even though this workaround works for you, so the team can gather interest around this feature and provide official ways to do it.

     

    Cheers!

3 Replies

  • jfelix's avatar
    jfelix
    SmartBear Alumni (Retired)

    Hi, RobertoM! Thanks for your question.

     

    I'm afraid Zephyr Scale does not provide an official way to do this.

     

    If you're using the Server version of the app, you can get that data using a query like query=projectKey = "XYZ" AND folder IN("/A", "/A/B", "/A/B/C"). Please note that you have to provide the full path when querying a subfolder.

     

    If you're using the Cloud version, you can write a script that queries the folder data via GET /folders and use the response to get the test cases that belong to a specific folder ID, via GET /testcases?projectKey={{projectKey}}&folderId={{folderId}}.

     

    If this solution does not meet your needs, please create a new entry in the Ideas Portal, describing your needs:

    1. For Server/DC: https://zephyr-scale-server-dc.ideas.aha.io
    2. For Cloud: https://zephyr-scale-cloud.ideas.aha.io/ideas

    Cheers!

    • RobertoM's avatar
      RobertoM
      New Contributor

      Thank you jfelix. I was hoping there was another way to do that. Just to give an example I use an addon called Zephyr Scale Reporting for Confluence that gives some macros to create reports. And within those macros it extracts a list of all folders and also gives the possibility to select test cases belonging to a folder including all subfolders (I am using the Server version).

      Your suggestion to use the query with the folder IN ("A", "B") works if you know what are the folders. My need would be to know the number of test cases included in one folder and its subfolders without giving the name of the subfolders because subfolders might be added or removed.

      • jfelix's avatar
        jfelix
        SmartBear Alumni (Retired)

        Hi, RobertoM 

         

        Since you're using the Confluence plugin, you're likely to be using the Server/DC version of the app. In this case, you can use the private API to achieve this.

         

        The endpoint is https://{{your-jira-url}}/rest/tests/1.0/testcase/search?archived=false&fields=id,key,projectId,name&maxResults=40&query=testCase.projectId+IN+({{your-project-id}})+AND+testCase.folderTreeId+IN+({{your-folder-id}})&startAt=0

         

        Use your Jira username and your password to authenticate, using Basic Auth authorization.

         

        You can get the project ID via the Jira REST API.

         

        Please keep in mind that this is not officially supported and therefore this endpoint might change in the future without any previous notice.

         

        It would be nice if you could raise this in the Ideas Portal even though this workaround works for you, so the team can gather interest around this feature and provide official ways to do it.

         

        Cheers!