I have 3 branches in my repository : main, branch1 and branch2
In Bitbucket Cloud REST API Documentation, there is an API to get the root directory of main branch: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-source/#api-repositories-workspace-repo-slug-src-get
But I want to get root directory (basically all the src files under branch branch1) of branch1 not main branch. So, are there any way to achieve this by passing any query parameter on this endpoint: `GET /2.0/repositories/{workspace}/{repo_slug}/src`
I tried the solution suggested here in this question asked by someone, but even that's not working: Fetch-list-of-files-with-details-present-under-branch-or-tag/qaq-p/1148751
If Bitbucket Developer team can confirm whether this feature (passing ?branch=<branch_name> query param to get specific branch src files) will be supported in next Bitbucket Cloud 2.0 REST API release or not, then It would be really helpful. Till then if someone know the work around or the specific solution, please comment.
Thanks.
Hello, @meetakbari25, and welcome to the Atlassian Community!
You can use the Get file or directory contents in order to list the files in a directory of your repository :
2.0/repositories/{workspace}/{repo_slug}/src/{commit}/{path}
The {commit} portion of the URL can be replaced with a branch or tag name as well. The {path} attribute is the directory of the repository you want to list the files. If you want to list the root directory, you can leave the {path} blank, but the trailing slash at the end of the URL is required.
So a request for listing the files of the root directory of a branch named branch1 would look like below :
curl -X GET -u USERNAME:APP_PASSWORD https://api.bitbucket.org/2.0/repositories/<workspace>/<repository>/src/branch1/
You can try using the example command above and let us know it goes :)
Thank you, @meetakbari25 !
Patrik S
Hello @Patrik S
Just wanted to let you know that I'm trying to use this endpoint like you described and it doesn't work.
I'm trying to retrieve directory for specific branch and I'm using:
https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/src/{branch_name}/
Best regards,
Marko Blagus
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Marko Blagus ,
I've just tested on my end using the endpoint
https://api.bitbucket.org/2.0/repositories/<workspace>/<repository>/src/<branch-name>/
and the files of the root directory were correctly listed.
Could you please share more details of the issue you are facing? Are you receiving any errors, or is the response just empty?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.