How to update a project key via API?

I am currently using SonarQube 9.9 LTS deployed on-prem.

We are working on the standardization of project keys and need to update the existing project keys (for ~10K projects) as part of this process. So, I wanted to do this via (api/projects/update_key) call.
I am using a token of an admin id which has administer system and administer project accesses.

I tried to update the project key via a python script which throw a 403 error message.

The below is a sample python script

base_url = ""
headers = {}
headers['Authorization'] = self.sonar_auth_token
response_update_key =, headers=headers, params=data_params, verify=False)

When I checked it in Postman, I got “Insufficient privileges” error message, if I am entering a user token generated as api key added to header as Private-Token for the same account where it got successful if I am passing basic authentication.

Could you please guide what I am missing?

Appreciate your help!


don’t know much about Python, but your authorization seems wrong.
A quick search came up with

from requests.auth import HTTPBasicAuth
r =, auth=HTTPBasicAuth('user', 'pass'), data=payload)

Note = Sonarqube basic authentication uses <token>: means just the token plus delimiter with a blank password.
So i guess it’s ...HTTPBasicAuth('user', '')... !?


1 Like

Hi @Rebse

Thank you for taking your time to respond. I was able to fix the issue by appending a : at the end, which I missed earlier for the token :slight_smile:

Thank you!!