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

Bitbucket REST API - reference branches with forward slash in name

Mark Hegedus January 3, 2022

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

2 votes
Mark Hegedus January 3, 2022

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

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

Freddy Esneyder Jaimes Ruiz
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 17, 2024

@seanaty Thank you very much, it worked for me.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events