1

I would like to poll the quality gate execution status of my SonarQube 6.3 instance using a REST api call. I went through a few api calls, which did not give me the expected results.

I tried to use these urls:

  1. http://localhost:9000/api/resources
  2. http://localhost:9000/api/components

But I always got this response:

{"errors":[{"msg":"Unknown url : /api/resources"}]}

How can I poll the quality gate execution status via REST?

slartidan
  • 20,403
  • 15
  • 83
  • 131
Simbu
  • 766
  • 1
  • 12
  • 37

3 Answers3

3

http://localhost:9000/web_api lists the web service endpoints available on your server and provides documentation for each one. In my copy of 6.3, the documentation for "api/resources" says

Removed since 6.3, please use api/components and api/measures instead

You say you've tried http://localhost:9000/api/components and gotten an error. That's because there's not actually a web service there. You'll have to add the qualifier for the service you want, such as /api/components/search, as described in the docs for that set of services: http://localhost:9000/web_api/api/components

G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76
1

In fact there are 5 parts in a correct SonarQube web api url. They can be seen like that domain/api/controller/action?parameters, for example http://localhost:9000/api/components/show?componentKey=blue.

So we have:

  1. domain: which is represented by http://localhost:9000 in the example, it is the address where you can call your SonarQube server
  2. api: which is represented by /api in the example, it is the base path of all web service in SonarQube
  3. controller: which is represented by /components in the example, it represents a pool of web service concerning a given theme (issues, profiles, components, etc.)
  4. action: which is represented by /show in the example, it is a unit action that you can perform through the web service, for example: show, search, list, backup, delete, etc.
  5. parameters: which is represented by ?componentKey=bluein the example, they are not always mandatory but often allow you to specify further information to get more precise results

What you have forgotten here is at means to specify an action.

begarco
  • 751
  • 7
  • 20
  • How to get componentKey value of my project ? so that i will fill it in the GET call. I have tried something like domain/api/components/show?id=1. It shows error as `{"errors":[{"msg":"Component id '1' not found"}]}` – Simbu Jun 21 '17 at 05:33
  • It depends on what type of component you want to 'show', for a project for example it is simply the key you gave for the analysis. But if you do not know the key you should better use search action: it allows you to find a component based on other criteria. – begarco Jun 21 '17 at 05:39
0

http://localhost:9000/api/project_analyses/search?project=myProjectname&category=QUALITY_GATE

This query returned the status of my quality gate. Here I have mentioned the project name as myProjectname

Simbu
  • 766
  • 1
  • 12
  • 37