Getting all project roles returns more than are in use

I am working on a project to get all of the role actors across all projects. From what I can tell, there isn’t a single API call to get a project, it’s roles, and all the actors assigned to the roles.

So instead what I planned on doing is using the “Get all project roles” /rest/api/3/role endpoint to get the available roles, and for each project and role, use the “Get project role for project” /rest/api/3/project/{projectIdOrKey}/role/{id} endpoint to get the actors.

The problem is that “Get all project roles” returns 72 results. However, when I navigate to the project role browser on our account it shows only 19 roles. It appears that many of these are duplicates, as there are 23 unique names.

So that leads me to wonder how I can get the exact list that shows within the web interface. My project could be used by others so I can’t create a static list. Also, I don’t want to rely on getting the roles from a random project as there are some which only have 4 or 5 roles available.

Welcome to the Atlassian Developer Community, @KuzmaFesenko!

As you’ve experienced, the Get all project roles REST API returns project roles for every project it is associated with which results in multiple roles of the same name to appear (but do take note that they have different IDs):

[
    {
        "self": "https://iragudo.atlassian.net/rest/api/3/role/10006",
        "name": "Administrator",
        "id": 10006,
        "description": "Admins can do most things, like update settings and add other admins.",
        "scope":
        {
            "type": "PROJECT",
            "project":
            {
                "id": "10001"
            }
        }
    },
    {
        "self": "https://iragudo.atlassian.net/rest/api/3/role/10010",
        "name": "Administrator",
        "id": 10010,
        "description": "Admins can do most things, like update settings and add other admins.",
        "scope":
        {
            "type": "PROJECT",
            "project":
            {
                "id": "10005"
            }
        }
    },
   ...
]

As there is no single API to do this, if your goal is to list down all the actors for a specific role regardless of the project they are in, then this can be achieved with your current approach. Add another step in your code to aggregate all the actors from the results of your multiple calls to /rest/api/3/project/{projectIdOrKey}/role/{id} based on the role name (and not the role id).

Hope this helps.
Ian

I appreciate the response @ianRagudo!

Unfortunately I must know the actors per role per project. I have decided to get the roles for each project, then get the actors for each role. It requires a lot of calls (several thousand!) so to mitigate I have decided to implement caching then at least subsequent runs of my script are much faster.