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

Next challenges

Recent achievements

Recognition

  • Give kudos
  • My kudos

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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?

 

1 answer

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
Community showcase
Published in Bitbucket

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

1,897 views 0 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you