Returning only specific fields via Bitbucket API
Asked by Esther Strom:

I'm trying to return a simplified list of all of our repos via API. When using the unmodified endpoint (<https://api.bitbucket.org/2.0/repositories/{workspace>}) I get something that looks like this:

```
{
"pagelen": 10,
"size": 874,
"values": [
{
"scm": "git",
"has_wiki": false,
"links": {
"watchers": {
"href": "https://api.bitbucket.org/2.0/repositories/myworkspace/our_services/watchers"
},
"branches": {
"href": "https://api.bitbucket.org/2.0/repositories/myworkspace/our_services/refs/branches"
},
"tags": {
"href": "https://api.bitbucket.org/2.0/repositories/myworkspace/our_services/refs/tags"
},
"commits": {
"href": "https://api.bitbucket.org/2.0/repositories/myworkspace/our_services/commits"
},
"clone": [
{
"href": "https://myuser@bitbucket.org/myworkspace/our_services.git",
"name": "https"
},
{
"href": "git@bitbucket.org:myworkspace/our_services.git",
"name": "ssh"
}
],
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/myworkspace/our_services"
},
"source": {
"href": "https://api.bitbucket.org/2.0/repositories/myworkspace/our_services/src"
},
"html": {
"href": "https://bitbucket.org/myworkspace/our_services"
},
"avatar": {
"href": "https://bytebucket.org/ravatar/%7B4fe5ecee-f5cb-46c5-bbc8-900cb85ef9fb%7D?ts=default"
},
"hooks": {
"href": "https://api.bitbucket.org/2.0/repositories/myworkspace/our_services/hooks"
},
"forks": {
"href": "https://api.bitbucket.org/2.0/repositories/myworkspace/our_services/forks"
},
"downloads": {
"href": "https://api.bitbucket.org/2.0/repositories/myworkspace/our_services/downloads"
},
"pullrequests": {
"href": "https://api.bitbucket.org/2.0/repositories/myworkspace/our_services/pullrequests"
}
},
"created_on": "2019-02-05T23:47:10.618606+00:00",
"full_name": "myworkspace/our_services",
"owner": {
"username": "myworkspace/our_services",
"display_name": "My Company",
"type": "team",
"uuid": "{uuid}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/workspaces/custom_url"
},
"html": {
"href": "https://bitbucket.org/most_custom_url"
},
"avatar": {
"href": "https://bitbucket.org/account/myworkspace/avatar/"
}
}
},
"size": 7392916,
"uuid": "{uuid}",
"type": "repository",
"website": "",
"override_settings": {
"branching_model": false,
"default_merge_strategy": false,
"branch_restrictions": false
},
"description": "API codebase",
"has_issues": false,
"slug": "mycompany_services",
"is_private": true,
"name": "mycompany_services",
"language": "",
"fork_policy": "no_public_forks",
"project": {
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/workspaces/myworkspace/projects/WEB"
},
"html": {
"href": "https://bitbucket.org/myworkspace/workspace/projects/WEB"
},
"avatar": {
"href": "https://bitbucket.org/account/user/myworkspace/projects/WEB/avatar/32?ts=1547489822"
}
},
"type": "project",
"name": "Website",
"key": "WEB",
"uuid": "{uuid}"
},
"mainbranch": {
"type": "branch",
"name": "master"
},
"workspace": {
"slug": "myworkspace",
"type": "workspace",
"name": "My Company,
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/workspaces/myworkspace"
},
"html": {
"href": "https://bitbucket.org/myworkspace/"
},
"avatar": {
"href": "https://bitbucket.org/workspaces/myworkspace/avatar/?ts=1587659968"
}
},
"uuid": "{uuid}"
},
"updated_on": "2022-02-09T04:48:15.052710+00:00"
}
}
```

That's just a single repo; we have over 800. All I really want from this is the full_name value.

The API's [partial-response documentation](https://developer.atlassian.com/cloud/bitbucket/rest/intro/#partial-response)

indicates that there are three ways to get a partial response: remove specific fields, add additional fields, or return only specific fields. That last one is what I want, but I can't figure out how to do it.

There are too many fields to use the ?fields=-links (or whatever field name) syntax, but the only example they have of "return only specific fields" is a json array, which has both field names and values. I don't want to filter things based on values; I want all repos returned, but only the single piece of info from each repo.

Can anyone help me out? I'm testing it in Postman; here's what I've tried so far. All of them return the same full response as shown above. (The obscured part of the URL is our workspace name.)

![postman3.png](/t5/image/serverpage/image-id/182675i791B51A299F62DBD/image-size/large?v=v2&px=999 "postman3.png")![postman2.png](/t5/image/serverpage/image-id/182676i35CEE3290428BCFA/image-size/large?v=v2&px=999 "postman2.png")![postman1.png](/t5/image/serverpage/image-id/182677i41B6BE6D58EF8572/image-size/large?v=v2&px=999 "postman1.png")


Answers:
author: Peter-Dave Sheehan
body: You have to tell the api where the "full_name" or links field is.

In this case, it's inside "values"

try with ?fields=values.full_name

comments: author: Esther Strom
body: Thanks! Because the he partial response documentation specifically mentions using the "+values.destination.repository.owner" format, and since full_name is on the same level in the json hierarchy as owner, I thought I needed to use the same format. Your way works!


author: Peter-Dave Sheehan
body: If you were returning a single repository, then ?fields=full_name would work to only show that field.

Frankly, I figured it out with trial and error and it's when i tried to retrieve a single repository that I saw that the ?field worked. All prior attempts were causing empty objects to be returned.


Tags: bitbucket-cloud

cloud

rest-api