Must-share information (formatted with Markdown):
-
which versions are you using
Enterprise Edition Version 10.2.1 (build 78527) -
what are you trying to achieve
Create a project using api -
what have you tried so far to achieve this
I am using the below to search the existing projects & it works fine,
def search_project(api_key):
headers = {
"Authorization": f"Bearer {api_key}"
}
params = {
"q": var.sonar_project_key
}
response = requests.get(api_url, headers=headers, params=params)
return response.json()
but when using the below to create a new project, it is giving a status code 200 & the project is not getting created.
def create_project(api_key, working_branch=None):
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
payload = {
"name": var.sonar_project_key,
"project": var.sonar_project_key,
"visibility": "private"
}
if working_branch:
payload["mainBranch"] = working_branch
response = requests.post(api_url, json=payload, headers=headers)
return response
I tried using it with / without the branch, visibility etc but still getting the 200 response. I also tried using a user token as well as a global analysis token but there is no change in the response.