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

NickP October 31, 2019

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
Atlassian Team members are employees working across the company in a wide variety of roles.
April 3, 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

NickP April 13, 2022

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).

0 votes
NickP November 1, 2019

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
AUG Leaders

Atlassian Community Events