Unable to get response from Sonarqube web api endpoints in Postman

Hi Team,

Goal: I am trying to get code coverage, severity data from Sonarqube cloud.

I am making use of Postman to test Sonarqube webapi endpoints but not getting desired result.
(Note: Generated token in Sonarqube and provided it in Postman token_bearer)

example GET API:
https://sonar.pnr.com/api/project_tags/search

Output: getting random HTML code, with 200 OK status

[
<!doctype html>

. . . ]

Desired output should be like below.

{
“tags”: [
“official”,
“offshore”,
“playoff”
]
}


I have tried most of the endpoints, the result is same, random HTML code.

Below are some the API. I have tried,
(All get requests)

https://sonar.pnr.com/api/measures/component?metricKeys=coverage
(Component key is optional)

https://sonar.pnr.com/api/components/show

What is the right way to consume the sonarqube endpoints?

Thanks in advance.
Praveen

1 Like

Hi,

Welcome to the community!

You said “Sonarqube cloud”. I guess you mean SonarQube? If so, then what you’ve listed is correct. E.G. https://next.sonarqube.com/sonarqube/api/project_tags/search.

You say you keep getting random HTML code. Have you looked at what the returned page says? It may be relevant to your problem.

 
Ann

Hi Ann,

Thanks for your reply,
I analysed the response from the API, it does not have any valid information.


What is the correct way to call SonarQube web APIs from postman?

Thanks for your time.

Regards,
Praveen

I tried with Java code…

message attribute is empty.

“message=,”

Hi.

The user token isn’t a bearer token, the SonarQube API uses HTTP basic authentication.

https://docs.sonarqube.org/latest/extend/web-api/

User Token

This is the recommended way. Benefits are described in the page User Token. The token is sent via the login field of HTTP basic authentication, without any password.

1 Like

Hi Felipe,

Used basic auth, the result is same.


Hi,

Let’s back up. Log in to SonarQube with your browser and try calling the API directly (in your browser location bar). What do you get? Because based on the screenshots, it looks like you may be being redirected to the SonarQube app.

 
Ann

Hi Ann,

When I hit api directly in browser

https://sonar.pnr.com/api/measures/component?metricKeys=coverage

It redirects to
https://sonar.pnr.com/sonar/dashboard?id=project_name

Yes, you are right, it is redirected back to SonarQube app.

Hi,

So to solve this issue, you’ll need to deal with the redirect. Then you should be able to use Postman without a problem.

 
HTH,
Ann

1 Like

Hi Ann,

Thanks for the reply,
Do you know on how to handle these redirects?
Any settings we need to change within Sonarqube

Much Appreciated.

Regards,
Praveen

Hi Praveen,

This isn’t happening within SonarQube. You probably need to talk to your network folks.

 
Ann

1 Like

Thanks a lot Ann.

Much Appreciated!!

Regards,
Praveen

Looks like you need to call https://sonar.pnr.com/sonar/api/measures/component?metricKeys=coverage
Istead of https://sonar.pnr.com/api/measures/component?metricKeys=coverage

1 Like

Yes, @nixel2007

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