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,364,968
Community Members
 
Community Events
168
Community Groups

Bitbucket REST API - reference branches with forward slash in name

Hello everyone!

I am having trouble figuring out how one can reference branches with the forward slash / character in the name while making API calls.

When using URL encoding, Bitbucket will assume that the encoded forward slash (%2F) is a path parameter delimiter.

A simple example: trying to access README.md on a branch called "feature/test" with the following command will fail, as Bitbucket will try to access it on the non-existent "feature" branch, and will assume "test" is part of the path.

Request:  curl 'https://api.bitbucket.org/2.0/repositories/my-workspace/myrepository/src/feature%2Ftest/README.md'

Response: {"data":{"shas":["feature"]},"type":"error","error":{"message":"Commit not found","data":{"shas":["feature"]}}}

Is there any workaround for this? Because I've been searching for similar issues and so far haven't come up with anything.

1 answer

Oh, probably shouldn't be holding my breath over this one...

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

Anyone know of a workaround?

seanaty Atlassian Team Jan 03, 2022

Work around is to make 2 API calls. Use the branch API to get the current commit of that branch, then use the current commit to call the source API.

Like Mark Hegedus likes this

Hi @seanaty ! Thank you for your quick reply, this solution works.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events