The following code snippet works with SonarCloud and a valid token (given a project_uuid parameter to set):
import json
import os
import requests
# API Call : https://sonarcloud.io/api/navigation/component?component=olivier-schmitt_aws-cda
def get_project_info(project_uuid):
# Provide your SonarCloud token using the env var SC_TOKEN
sc_token_from_env = os.environ.get('SC_TOKEN')
url = f'https://sonarcloud.io/api/navigation/component?component={project_uuid}'
response = requests.get(url, auth=(str(sc_token_from_env), ''))
if response.ok:
data = json.loads(response.text)
return data
else:
raise Exception(response)
result = get_project_info('olivier-schmitt_aws-ca')
print(json.dumps(result))
It’s based in the requests package a very famous one but it should work with other similar packages.
Hello.
Thanks for your answer.
I tried with your example and return 401 (not authorized).
The project that I try get content it is a organization project, but should works because I have full permission in the organization.
apart from a little typo in the function call ( get_project_info('olivier-schmitt_aws-ca') -> get_project_info('olivier-schmitt_aws-cda') ) the python snippet from @Olivier_Schmitt works for me as well. could you maybe share a minimal feature how you try to authenticate? something like this: