Praveen_MG
(Praveen MG)
January 24, 2022, 3:38pm
1
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
ganncamp
(G Ann Campbell)
January 24, 2022, 7:05pm
2
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
Praveen_MG
(Praveen MG)
January 25, 2022, 8:31am
3
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
Praveen_MG
(Praveen MG)
January 25, 2022, 9:05am
4
I tried with Java code…
message attribute is empty.
“message=,”
felipebz
(Felipe Zorzo)
January 25, 2022, 9:48am
5
Hi.
The user token isn’t a bearer token, the SonarQube API uses HTTP basic authentication.
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
Praveen_MG
(Praveen MG)
January 25, 2022, 9:58am
6
Hi Felipe,
Used basic auth, the result is same.
ganncamp
(G Ann Campbell)
January 25, 2022, 4:30pm
7
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
Praveen_MG
(Praveen MG)
January 25, 2022, 4:45pm
8
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.
ganncamp
(G Ann Campbell)
January 25, 2022, 4:52pm
9
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
Praveen_MG
(Praveen MG)
January 25, 2022, 5:13pm
10
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
ganncamp
(G Ann Campbell)
January 25, 2022, 5:20pm
11
Hi Praveen,
This isn’t happening within SonarQube. You probably need to talk to your network folks.
Ann
1 Like
nixel2007
(Nikita Fedkin)
January 30, 2022, 3:53pm
13
1 Like
system
(system)
Closed
February 7, 2022, 12:16am
15
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.