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

API 2.0 Find files in a branch

StuMid December 16, 2020

Hey all,

Using the API and running this query for example...

https://api.bitbucket.org/2.0/workspaces/MyWorkspace/search/code?search_query=myfile.json+repo:myrepo

returns only myfile.json if it exists in the Master branch of the "myrepo" repo. I can't find any information on how to search within another branch.

How can I alter this search to search either a specific branch or the entire repo?

Thanks...

1 answer

0 votes
seanaty
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 17, 2020

@StuMid the code search API only indexes the main branch so you're correct that you can only use this API with that branch to search file contents.

That said, you can use the src API to fetch files from any branch given that you know the filename.

https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/src/%7Bcommit%7D/%7Bpath%7D

You can use a branch name where it says "commit" but there is an annoying limitation that the branch name cannot contain a slash. If the branch name contains a slash you'd have to take a 2 step approach and first look up the commit of the branch using the branch API.

Adolfo Perez Solis March 9, 2023

Reading the documentation seems like you also need to know the path in addition to the filename when using the src API you suggested isn't it? In 2023 isn't still an easy way to search for files in a given branch? Without knowing the full path of the file

Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events