I am working on a VUE project where I'd like to be able to create a list of files which are in my private repo and then use that list to copy the matching files from my private repo into a zip folder for the user to download.
I have the create list and download zip folder functionality figured out so far.
However I am totally new to using APIs so I'm looking for advice on whether this is possible or not and what the best way to go about it would be.
Do you need help with getting a list of files via API or the contents of these files? Or perhaps both?
Could you also please let us know whether this concerns repositories hosted in Bitbucket Cloud or Bitbucket Server?
Thank you for your reply. If the repository is hosted on bitbucket.org, then this is Bitbucket Cloud (Bitbucket Server is a product you install on your own servers, so this is self-hosted).
For Bitbucket Cloud, you can use this endpoint to get a list of the root directory on the main branch of the repo (at the latest commit):
An example call could be the following:
curl -sL -X GET --user username:password http://api.bitbucket.org/2.0/repositories/repo-owner/repo-slug/src
username is the username of a Bitbucket account with access to the repo
password is this account's password or an app-password with appropriate permissions
repo-owner is the workspace ID of the workspace that owns the repo
repo-slug is the slug for this repository
If you want to get a list of the files/directories at a specific commit, you can specify the commit as follows:
curl -sL -X GET --user username:password http://api.bitbucket.org/2.0/repositories/repo-owner/repo-slug/src/commit-hash/
In order to get the contents of a specific file or a directory, you can use the following endpoint:
An example call would be the following:
curl -sL -u username:password -H "Content-Type: application/x-www-form-urlencoded" https://api.bitbucket.org/2.0/repositories/repo-owner/repo-slug/src/commit-hash/file_path
commit-hash replace with the hash of the specific commit you are interested in
file_path is either the path+name of a specific file, OR the path of a directory in the repo
In the call above, if file_path is the path of a directory in the repo, then the call will return the contents of this directory.
If file_path is the path+name for a specific file, you will get the contents of this file. You can then redirect the output to a file named e.g. file1 on your machine as follows:
curl -sL -u username:password -H "Content-Type: application/x-www-form-urlencoded" https://api.bitbucket.org/2.0/repositories/repo-owner/repo-slug/src/commit-hash/file_path > file1
I hope this helps, please feel free to let me know if you have any questions.
Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster ! While we’re all excited about the new improvements to Bitbucket ...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events