We want to set the default value for all created projects via the API.
The following curl command leads to insufficient privileges:
curl -u : --request POST https://sonarcloud.io/api/settings/set?key=sonar.leak.period&value=previous_project&component=
Why? The API key belongs to a user who is org admin.
- Is the API approach the best way to set default values for all projects in SonarCloud?
- How can I set project settings via API?
First, in order to set the default value on settings, you should use api/settings/reset instead of api/settings/set.
Then, about permission, the user needs to administrator of the project.
By default, an administrator of the organization should also be administrator of all proejcts, but if it’s not the case he can grant himself back the permission using “Administration” > “Project Management” > “Edit Permission” on the project.
Thanks for your quick reply. Sorry, my first question was a bit misleading
Is the API approach the best way to set default values for all projects in SonarCloud?
Whenever a new project is created in SonarCloud by submitting the first analysis, I wonder if I can configure the default settings for such a new project created. Not the SonarCloud default settings, but our company internal ones. For example, to force “sonar.cloud.leak” to “previous_version” instead of “30”.
How can I set project settings via API?
I gave all permissions to the user but still no luck (see screenshot). In the API documentation is stated, that the “Administer System” permission is required. Maybe I do not have that permission on a hosted SonarCloud account?
I already use the component parameter. I retrieved the value from the Project-Key-Copy Button in the SonarCloud Web UI.
curl -u abc: --request POST https://sonarcloud.io/api/settings/set?key=sonar.leak.period&value=previous_project&component=xyz
I have to add that it is a component of a an organizational account where I am the admin of. Do I need to add org information to the component param? Running out of ideas
The WS query you’re using sounds good. Do you confirm that when executing it you receive a 403 error ?
If yes, can you check that you’re an Administrator of the project ? Because even if you’re the administrator of the organization, you also need explicitly to be administrator of the project.