Sonarqube API calls not working with curl

Hello There,

I am using SQ-8.9.6 when I user below api in browser it works

http://sonarqube-server:9000/api/components/search?qualifiers=TRK

but when I do curl it give me error (port 9001 is internal port which works well with localhost)

curl -X GET ‘http://localhost:9001/api/components/search?qualifiers=TRK
{“error”:{“root_cause”:[{“type”:“illegal_argument_exception”,“reason”:“request [/api/components/search] contains unrecognized parameter: [qualifiers]”}],“type”:“illegal_argument_exception”,“reason”:“request [/api/components/search] contains unrecognized parameter: [qualifiers]”},“status”:400}

this is happening for many other queries and I am not sure which query is correct

My requirement is

  1. List of sonarqube projects
  2. Lines of code per project

I am using below
[api/components/search?qualifiers=TRK ]
[api/measures/component?component=<PROJECT_KEY>&metricKeys=ncloc ]

but it gives same “contains unrecognized parameter” can someone guide what I am missing here

Regards,
SAM

Hey there.

Port 9001 is already being used by Elasticsearch – which you cannot query directly. What happens if you use port 9000?

Hello @Colin
Thanks for the response, I figured out that base url was set that was not allowing query to this localhost , but now I am not able to get response

API call = curl -u admin:XXXXXXXX -X GET ‘http://sonarqube-server:9000/api/measures/component?componentKey=sleroy:reactjs-demo&metricKeys=ncloc

Error: {“errors”:[{“msg”:“The \u0027component\u0027 parameter is missing”}

This query working

curl -u admin:XXXXXXXX -X GET ‘https://sonarqube-server:9000/api/components/search?qualifiers=TRK
{“paging”:{“pageIndex”:1,“pageSize”:100,“total”:3},“components”:[{“key”:“sleroy:reactjs-demo”,“name”:“ReactJSdemo”,“qualifier”:“TRK”,“project”:“sleroy:reactjs-demo”},{“key”:“gitlab-sonar”,“name”:“my-app”,“qualifier”:“TRK”,“project”:“gitlab-sonar_AX8lXT9yjCYHsI0QujFF”},{“key”:“grafana-test”,“name”:“grafana-test”,“qualifier”:“TRK”,“project”:“grafana-test”}]}

can you help what I am doing wrong in first query.

Regards,
SAM

You should use the component query parameter rather than componentKey

1 Like

Thank you Colin

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