SonarQube Web API for Permission Template

  • Version of SonarQube Server: 10.8.1.101195
  • SonarQube deployed: Docker
  • what are you trying to achieve:
    I’ve been trying to apply bulk permission template via API since we have a lot of projects and I’m also trying to make sure this effort is reusable.

I’m encountering this error for a while now with my script:

{“errors”:[{“msg”:“Template name or template id must be provided, not both.”}]}

I tried a couple of combination of TemplateId, template and templateName on the command and every possible combination of formatting for comma delimited list but to no avail.

I might be doing something wrong here, so help is appreciated!

Here’s what I’m trying to make work:

curl -X POST “https://test-sonarqube.com/api/permissions/bulk_apply_template
-u “<token123!>”
-H “Content-Type: application/json”
-d ‘{
“templateName”: “sample-template”,
“projects”: [“project1”, “project2”]
}’

Hey there!

SonarQube expects a URL-encoded request. You can use the following curl commands:

  1. With -G (curl’s GET method with data parameters attached to the URL):
curl -u TOKEN: -G \
  -X POST 'http://localhost:9000/api/permissions/bulk_apply_template' \
  -d templateName=sample -d projects=deeper-sast-demo,python-flask-demo
  1. Or more simply, pass the parameters directly in the URL:
curl -u TOKEN: \
  -X POST 'http://localhost:9000/api/permissions/bulk_apply_template?templateName=sample&projects=deeper-sast-demo,python-flask-demo'

SonarQube does not accept a JSON body for this request; parameters must be URL-encoded.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.