How can I return partial results in Bitbucket Server REST API call?

Looking at the online documentation for Bitbucket Cloud, I can see that you can query the REST API and narrow the returned results by adding something like:
Instead of the full JSON representation of each repo, it would only return the slug for each repo from the values list of the JSON object.

I’d like to do the same in Bitbucket Server but the documentation has no callouts for that “Partial Response” feature. I can confirm that it doesn’t seem to have support for that because when I do the following:
curl https://<bitbucket_server>/rest/api/1.0/projects/<project_key>/repos?fields=values.slug
I still get the full JSON output as if I hadn’t added the fields restriction. I even tried with something simple like ?fields=nextPageStart and that didn’t work either.

Is there just no support for “Partial Responses” in Bitbucket Server?

1 Like

Hi @msteppe91,

yes that’s correct, this is a Bitbucket Cloud feature and Bitbucket Data Center does not support returning partial JSON objects.


Thanns @wkritzinger ! Do you know if there’s any future feature coming down the pipes that will allow such behavior in Data Center?

I’m not aware of any plans at the moment. What’s your use case? Do you want to save on the download size of the JSON returned? If possible, you could write your own plugin that return the JSON in the format you require.

I was trying to cut down on the amount of returned JSON, yes. Wouldn’t that plugin still be calling Atlassian’s REST API in the background? Even if the new plugin presented a different JSON format, the REST API call would still take just as long. I’m currently scripting something to post-process the JSON so the format isn’t the problem, the response time of the REST API is. In a similar Jira REST API call, I was able to significantly speed up the API calls by limiting the JSON returned with the ?fields classifier.

Your plugin would be calling the Java API to retrieve the data it needs, this is all done with in the JVM so it would not incur the cost of generating and parsing JSON. Jira works a bit differently and returning fewer fields might actually speed things up.
I’d recommend writing a plugin that uses the Java API to generate the data in the shape you need. All of the API that is used by our REST API is also available via the Java API.

Ahhh, that makes sense. Sorry for the misunderstanding. Thanks for the suggestions Wolfgang! I’ll look into writing that Java plug-in and see if it can suit our needs.