Multiple Permission in single API call

Hello SonarQube Community, @Bachri_Abdel

I’m using the SonarQube API to add a group to multiple projects and assign multiple permissions to that group. However, when I run my script, it only applies the first permission (issueadmin) and ignores the rest.

What I’m Trying to Do:

  • Assign a group to multiple projects.
  • Grant the group all six permissions:
    • issueadmin, securityhotspotadmin, scan, admin, user, codeviewer
  • Use the /api/permissions/add_group endpoint to assign each permission.

I know only one Permission per api call.
I cant try the Permission Template becuase when i add the template it will overide the exsisitng permission and erase that and add the template i passed so , i cant go with template.

Issue I’m Facing:

  • The API only applies the first permission (issueadmin) and does not add the rest.
  • This happens even when I loop through each permission separately.
  • There’s no error returned from the API—it just doesn’t apply the additional permissions.

import requests
import time
SONARQUBE_URL = "https://test.com"
AUTH_TOKEN = "testkey" 

PROJECT_KEYS = ["test_proj_key"]  

GROUP_NAMES = ["test group"] 

PERMISSIONS = ["issueadmin", "securityhotspotadmin",  "scan",  "admin","user", "codeviewer", ]

API_URL = f"{SONARQUBE_URL}/api/permissions/add_group"

auth = (AUTH_TOKEN, "")

for project in PROJECT_KEYS:
    for group in GROUP_NAMES:
        for permission in PERMISSIONS:
            params = {
                "projectKey": project,
                "groupName": group,
                "permission": permission
            }
            
            response = requests.post(API_URL, auth=auth, params=params)
            
            if response.status_code == 204:
                print(f'Successfully added permission "{permission}" for group "{group}" to project "{project}".')
            else:
                print(f'Failed to add permission "{permission}" for group "{group}" to project "{project}". Status: {response.status_code}, Response: {response.text}')

Hi,

Welcome to the community!

I invite you to familiarize yourself with the FAQ, and in particular, this section:

I created a topic, when can I expect a response?

This is an open community with people volunteering their free time to provide assistance. We’re eager to contribute to the community, but you are not guaranteed a fast response.

Be patient

  • Wait a few days before bumping a topic that hasn’t received a response.
  • Do not @name mention individuals not involved in the topic.

@-ing people not already involved in a topic does not move you to the top of their to-do list. Generally, just the opposite.

What is returned?

 
Ann