APIv2 [GET] Group Search (/api/v2/authorizations/groups) returns empty json with statuscode 200

Must-share information (formatted with Markdown):

  • SonarQube Enterprise 10.5.1
  • ZIP
  • I’m trying to use the API v2 /api/v2/authorizations/groups
  • Trying to access the [GET] Group Search function (/api/v2/authorizations/groups)

The API v2 works fine and returns what its supposed to, if it finds a group with the [GET] group search function json + statuscode 200.

However, it also returns statuscode 200 but with an empty response if the group doesn’t exist/not found. According to the api v2 documentation should return 404 with { “message”: “…” }.

Example call (simple get call with Invoke-RestMethod):

$Url = "server.mydomain.io"
$API_PATH = "/api/v2/authorizations/groups"
$API_PARAM = "?q=$GroupName&pageSize=$PageSize&pageIndex=$PageNumber"
$Response = Invoke-SonarQubeApiV2GetWithParams -Url $Url -Path $API_PATH -Params $API_PARAM

Anyone else have this problem wtih 10.5 or 10.6?

Hey there.

In reality, with the API you’re using searching for a group (you could type an incomplete group name of an existing group and if the search is working right, a group would appear in the results).

As noted for the q parameter

Filter on name. This parameter can either perform an exact match, or a partial match (contains), it is case insensitive.

So I don’t think returning a 404 would make sense… and with that said, that makes it very confusing we document a 404 case. I’ll flag this for an expert!

Thanks, the 404 status seems kind of confusing if it wont happen. :slight_smile:

In true hateoas spirit, I see status 200 and I always seem to get a json back with group count 0 for the empty responses; I think it makes sense to use ($Response.page.total -gt 0) in my code in stead of StatusCode 200/404.

{
  "groups": [],
  "page": {
    "pageIndex": "1",
    "pageSize": "100",
    "total": "0"
  }
}

Nice catch @jensmadsen :eagle: :eye:

We created a ticket to update the documentation.

Thank you for reporting this :pray:

:vulcan_salute:

1 Like

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