SonarQube Web API - Issue About api/measures/component

I am using Sonarqube Web, version API- With Web API I am able to authenticate, create and delete projects. I have a problem when I try to get the results of the completed evaluation of my projects. For this, I use GET api/measures/component HTTP request with project key as ‘component’ parameter and the keys of the elements I want to retrieve as the ‘metricKeys’ parameter.

The response I get is the following:

{"errors":[{"msg":"The \u0027component\u0027 parameter is missing"}]}

The driver code:

auth_response = session.get(url + 'api/metrics/search')

obj = {'component': 'humaneval_0', 'metricKeys': 'code_smells, bugs, new_vulnerabilities'}
measures_response = session.get(url + 'api/measures/component', data=obj)


‘Authenticate’ Subroutine:

def authenticate(url, myToken):
    session = requests.Session()
    #authenticate session with token
    session.auth = (myToken, '')

    auth = + 'api/user_tokens/search')
    response = session.get(url + 'api')

    return session

Any help would be much appreciated.


Could you try to do the same request using a tool like curl, wget or a browser?
Just to figure out if the problem is the client’s code.

1 Like

I tried using a browser and it worked. Turns out I have a problem with my code, that I have to put the parameters under “params” instead of “data” with HTTP GET requests, unlike POST requests.

My code:

measures_response = session.get(url + 'api/measures/component', data=obj)

Is changed with:

measures_response = session.get(url + 'api/measures/component', params=obj)

Thank you very much for your help!

1 Like

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