Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,493
Community Members
 
Community Events
176
Community Groups

Returning only specific fields via Bitbucket API

Edited
Esther Strom Community Leader Feb 09, 2022

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

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.pngpostman2.pngpostman1.png

 

1 answer

1 accepted

0 votes
Answer accepted

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

Esther Strom Community Leader Feb 11, 2022

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!

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.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events