Using the APIs (version 1 or version 2) on SonarQube Data Center Edition for User-Project Report

Not sure if this is the correct category, as I don’t know if this is a “need PM for a day” topic.

What I’m trying to do:
I’m trying to generate a custom report using a couple of the readily available APIs in version 1 and version 2 of SonarQube Data Center Edition. The report most closely resembles what I see in the Administration → Background Tasks UI , which gives me a view of the successful project analysis tasks. Instead of this, I want to get a report of all projects in the server, with all users associated to that project. I can’t seem to do this right now with the api/project/search endpoint or the api/users endpoint… at least there’s no direct way to do it.

Why do I need this:
I need to analyze my instance usage and license consumption. I’m already using the api/project/license_usage endpoint, which gives me “lines of code” and “% used” for that repo, but as mentioned earlier, I don’t have a way to link all users to those repos. I use this data to reach out to the teams so that we can understand how they use SonarQube, figure out whether they’re properly using exclusion rules, and discuss their quality profiles. This helps with enablement and further adoption in my company.

What have I tried:
I already tried using api/users/search
I already tried using api/v2/users-management/users
I already tried using api/v2/authorizations/groups
I already tried using api/projects/license_usage

There’s no direct connection to a user email address and a projectkey

Sample report:

  • user email address
  • projectname
  • projectkey
  • linesofcode
  • percent_license_used

Hello,

What do you have in mind with “users associated”? Are you looking for project admin? Users having any kind of permissions to access the project? People having Issues assigned to them in this project?

Thanks for getting back to me. Ideally, it would be any user that has read or write on the project. An example report would look like:

Jon.Doe@example.com | developer | myproject/my-first-repo | keypart1-keypart2 | 56,879 | 2.5

Jason.Bourne@example.com | admin | myproject/my-first-repo | keypart1-keypart2 | 56,879 | 2.5

Peter.Parker@example.com | browse | myotherproject/my-second-repo | keypart4-keypart6 | 12,345 | 6.5

If you are looking for permissions, you will have to go project by project, and check permissions based on users directly, and groups (as there are several ways for a user to get a permission on a project).

api/permissions/users?projectKey=xxxxx&ps=100 Will help you get user’s permissions on a project
api/permissions/groups?projectKey=xxxxx&ps=100 Will get you groups’ permissions

Also, permissions can be global, so you will have to check that as well (same endpoint, without the project or group parameter).