Not able to do curl on any of SonarQube methods using token

Template for a good bug report, formatted with Markdown:

  • versions used - * Enterprise Edition
    Version 8.2 (build 32929)
  • error observed (wrap logs/code around triple quote ``` for proper formatting)- Not able to call any PAi using curl able to login using token see screenshot for details

Error- {“errors”:[{“msg”:“Url is incorrect : ‘/api/properties/’”}]}

  • steps to reproduce
  • potential workaround

P.S.: use the #bug:fault sub-category if you’re hitting a specific crash/error , or the #bug:fp sub-category for rules-related behaviour

Welcome :slight_smile:

the error message shows the reason = Url is incorrect /api/properties

This endpoint has been in status deprecated with Sonarqube 7.9.x LTS already and
has vanished now with Sonarqube 8.x

See yourinstance/web_api?deprecated=true&internal=true for all available endpoints.

Gilbert

2 Likes

Thanks @Rebse for your response.is there any documentation we can refer for calling the Sonarqube API with examples . We are trying to find code duplications using automation in build pipeline.

1 Like

is that query string deprecated=true&internal=true will return available methods which can be used using curl or i need to change it to deprecated=false and internal = false ?

deprecated=true&internal=true means show me all methods available right now … for this instance.
Use methods marked deprecated | internal at your own risk, they might disappear with the next
update or get public … you need to check the release notes with particular attention !!
And as Enterprise user you have two staging instances for testing.

WRT to find the code duplication, that’s job of the Sonarqube server CE engine !?
Otherwise to access metrics for a project … i guess it’s api/measures/component but i don’t know
the metricKey for code duplication …
you may check the code https://github.com/SonarSource/sonarqube
or use the dev tools of your browser

@ganncamp
!! the web api documentation should have all possible values for params !!

1 Like

@Rebse if you’re saying the API docs should include the list of metric keys, well… that list is not fixed. New plugins can add new metrics. Also, the out-of-the-box list is pretty long. No one wants to see that in the docs.

That’s what the metrics search service is for (example URL above).

 
:smiley:
Ann

1 Like

Thanks @Rebse @ganncamp i have one feedback for API documentation . It would really be great value add if documentation also includes one examples with request and parameters the way you are showing response for any request.

Hi Ann,

Of course … /api/metrics has all the metric keys, even used that in the past when searching
for available metrics :laughing:
Thanks for the pointer

Gilbert

1 Like

Thanks @Rebse. I am able to find the duplicated_blocks using api and it returns me the number of duplicate blocks. Is there any api which return the actual duplicate code with details e.g file name with line numbers and duplicate block of code the way we can view duplicate code blocks in UI.

Hi,

what’s the use case for that ?
Sonarqube web ui has all relevant metrics with timeline.
Don’t know if there is a method that returns such details.

A good starting point to dive into (any) web / rest api is to use your browser developer tools
and check what runs behind the curtain - Sonarqube web application makes use of its web api.

Gilbert

The use case is wants to generate a human readable report on each build which contains details about code duplication file names and line number in the same way a user is able to view on Sonarqube portal but only difference is instead of human an app needs to get those details .

In developer tools one has to click on each and every folder level in project structure to reach the code duplicate block. I was thinking there is a direct api which should returns this information.

Sonarqube has the human readable report you’re searching for.
The only use case for me would be to make it - beside more other Sonarqube metrics - available
in the IDE so developers don’t have to leave their workbench.
That would be job of the Sonarlint plugin, you may create a feature request.
WRT code duplication i’m not sure if there ain’t already some IDE feature/plugin available
especially for that.

If you want to collect those metrics for historical reasons … Got similar questions, e.g. how do
i see the issues from an analysis one year before … etc.
Don’t bother with the past, the most important is the current status of your projects.
With Enterprise edition you should use portfolios with daily/weekly/monthly reports showing
the current status and trends.

BTW this discussion moves straight away from the initial topic, better
create some new topic.

Hi @Rebse Thanks is there way to download the above code duplications report ( you mentioned those exists in Sonarqube already ) using SonarQube API or any other automation method ? Thanks

Please create a new thread, as this moves away from your original curl problem.

Thanks @Rebse i created a separate topic at