Filtering, sorting and partial responses on the REST API not working ???

Adam Brunt
Contributor
February 1, 2024

Hi all,

I am trying to call the REST API [ with the correct authentication ] with the following:

https://api.bitbucket.org/2.0/repositories/foo/bar/environments?q=name="Test"

According to the docs this should return all environments, in foo/bar, with a name of "Test" but it just brings back all the environments. I get similar results when trying to use ?sort [ order doesn't change ] and ?fields [ all the environments data is returned rather than the fields I list ]

Am I missing something obvious here ? Or does filtering/sorting/partial responses not actually work ?

Regards,

Adam

 

2 answers

1 accepted

1 vote
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 2, 2024

Hi Adam,

I'm afraid that this API endpoint does not support sorting or filtering at the moment. Partial responses with the fields query parameter are possible, the way Saxea _Flowie_ explained.

We have a feature request in our issue tracker for supporting filtering and sorting for this endpoint:

You can add your vote there to express your interest.

In the meantime, you can get all the environments with the API, and then use another tool that filters JSON data to filter the results (e.g. jq is such a tool).

Kind regards,
Theodora

0 votes
Saxea _Flowie_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 1, 2024

Hi @Adam Brunt ,

Not a solution, but I tested and can confirm I'm seeing the same behaviour.

The APIs usually error when you use a field that is not filterable. However with this one, it doesn't fail, no matter what you use as filter, and it doesn't respect the pagelen and sort also. 

The fields is the only one that seem to work. Note you have to use fields=values.name.

Adam Brunt
Contributor
February 2, 2024

Thanks @Saxea _Flowie_ for confirming I wasn't going mad :)

To be fair, the documentation does say "Most 2.0 API resources that return paginated collections" but it would be helpful, in that case, to state in the docs which ones don't !!

Luckily in our case, we only have 4 environments so it's not such an issue to search through all the results; just so long as the pipelines endpoint does support filtering & sorting.

I will also try the values. part as well.

Now to do some investigating on how to filter by several fields (some of them nested deep down) at the same time :)

Like Sabine Mayer likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events