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,473
Community Members
 
Community Events
176
Community Groups

How to retrieve the contents of a file from a feature branch using the REST api?

Edited

Hello. This is probably simple, but for some reason it's got me stymied.

I have a repo with three branches.

I have a branch called "master"
If I curl against https://api.bitbucket.org/2.0/repositories/myorg/myrepo/src/master/README.md
I get the contents of my README.md file for the master branch.
That's good.

I have a branch called "dev"
If I curl against https://api.bitbucket.org/2.0/repositories/myorg/myrepo/src/dev/README.md
I get the contents of my README.md file for the dev branch.
That's good.

I have a branch called "feature/my-new-feature"
If I curl against https://api.bitbucket.org/2.0/repositories/myorg/myrepo/src/feature/my-new-feature/README.md
I get 404 NOT FOUND, and the body of the returned message contains an error saying "message": "Commit not found"
That's confusing.

If I look at the documentation for the form of the API I'm trying to use:
/repositories/{username}/{repo_slug}/src/{node}/{path} described at https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/src/%7Bnode%7D/%7Bpath%7D
And look at the Path Parameters section where "node" is described (which in my case I assume maps to "feature/my-new-feature"?)
The description says "(No Description)", which doesn't get me anywhere.

If I curl https://api.bitbucket.org/2.0/repositories/myorg/myrepo/refs/branches/feature/my-new-feature
I get back json that includes information on the latest commit (I think), I can dig the commit SHA1 out of the target.hash value and then
curl https://api.bitbucket.org/2.0/repositories/myorg/myrepo/src/{commit SHA}/README.md
and get the README.md, but I need to be able to accomplish this with a single URL (It's an input to a deployment tool and I don't have the option of digging around the json and formatting a 2nd request).

Does anybody know why I can't do the above?

 

2 answers

1 accepted

0 votes
Answer accepted
seanaty Atlassian Team Apr 03, 2022

Hey @NickP I just happened on this issue and the reason it wasn't working was because of the slash in the branch name. There's a public issue for it here with a ton more information about why it exists, some workarounds and some possible long term fixes.

https://jira.atlassian.com/browse/BCLOUD-9969

Oh, wow. It's been a while. Thanks and I'll accept this as the answer. We're not trying to deploy feature branches at this point anyway (at least not via the mechanism that I was testing when I posted this).

An update on this, for anyone who might be interested. I discovered that if I create my new branch my-new-feature as NOT a "feature" branch (In the Create Branch window leave the default Type as Other). I can then then curl my files, https://api.bitbucket.org/2.0/repositories/myorg/myrepo/src/my-new-feature/README.md works. So it seems to be something to do with it being a "feature" branch. I haven't tried with Bugfix, Hotfix, or Release.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events