Automate creation of groups

Hello, I am encountering an issue.

I am attempting to create groups for Sonar instances pragmatically, using the v2 API. My version of SonarQube is 25.2 Community.

The thing is, I need a way to avoid having to go to each Sonar instance I have, create a token, and then use that token to create the groups, since I have many Sonar instances. I need to create the groups when I deploy the instance. I know there is a parameter called X-Sonar-Passcode, but it doesn’t work for this endpoint.

How else could I create the groups?

Hey there.

If you really need to automate creating groups during deployment and want to avoid manual token creation for each instance, you can use the SonarQube Web API to programmatically generate user tokens by relying on username/password authentication in your deployment scripts. The POST /api/user_tokens/generate endpoint allows you to create a token if you authenticate with a user that has the necessary permissions (usually an administrator).

You can script this process to first authenticate with username and password (using basic auth), then generate a token, and finally use this new token to perform the group creation via the API. Note that this approach may expose credentials in your automation workflow, so make sure your deployment pipeline is secure and credentials are handled with care.