Missed Team ’24? Catch up on announcements here.

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

Get Archives of files and folders using RestAPI

Gokul Rajan July 4, 2023

Hi Team,

I'm trying to get a folder in my repo as zip or download a file in my repo in it's original format.
All I could find is /src API to get meta data of folder or /src API to get content of the file.
I could download entire Repo as zip using /get API in downloads. 

However I could not find ways to download individual files and folder from bitbucket remote Repo

1 answer

0 votes
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 6, 2023

Hello @Gokul Rajan and welcome to the community! 

While it's not directly possible to download a folder using the Bitbucket Cloud API, you can use the Get a file or directory contents to list the files within a folder and then make additional API calls to download each file individually.

The sequence would be like the following:

  • List the files in a given folder of your repository. In this example, I'm using the test_folde
    curl -u USERNAME:APP_PASSWORD https://api.bitbucket.org/2.0/repositories/workspace/repository/src/<branch>/test_folder

    This should return a list of the files within the test_folder directory
  • Iterate through the returned list of the files making an API to the same endpoint to fetch the actual content of the file.
    Example for a file named my_file.txt
    curl -u USERNAME:APP_PASSWORD https://api.bitbucket.org/2.0/repositories/workspace/repository/src/<branch>/test_folder/my_file.txt -o my_file.tx
    This API endpoint will return the raw content of the file, so we -o flag in the curl command to save the result into a file.

Another option, as you mentioned, is to download an archive of the entire repository at a given branch/tag, and then extract the archive and get the folder you need : 

curl -u USERNAME:APP_PASSWORD https://bitbucket.org/<workspace>/<repository>/get/<branch or tag>.zip -o my_repo.zip

Hope that helps! Let me know in case you have any questions.

Thank you, @Gokul Rajan !

Patrik S

Gokul Rajan July 6, 2023

Hi @Patrik S ,
Thank you for your response.

We have 1000s of files in each folder then we have to make calls individually for each files. It is a heavy process. Please take it as a feature request to download units of files and folders as zip.

Also for current implementation may I know what is the rate limit for API in bitbucket? What would be the ideal delay between each request?

Thank you,
@Patrik S 

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events