Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How Download Repository as ZIP file via API 2.0

I have read through all the relevant questions but did not see an answer to this specific question:

I need to download the repository (as an archive file) via the API v2.0 via node app.  There will not be any user context for the request so I need to authenticate the request. I have been using Basic auth (using an app password) for the other api requests I have been using.

This url was suggested in one posting and it works from Postman: 

 https://bitbucket.org/<workspace>/<repoSlug>/get/main.zip

but I need to make the request via axios, and am having a hard time passing the proper authentication. 

This is the current attempt that returns a 401:

axios.request({ 
  method: 'get',
  url:`https://bitbucket.org/${workspace}/${repoSlug}/get/${branch}.zip`,
  responseType: 'stream',
  headers: { auth: { username: secret.username, password: secret.password }}
});

I would rather make the request to the API, but have not found this functionality in the version 2 API.

2 answers

1 accepted

0 votes
Answer accepted

I was finally able to get this to work in a Node.js app passing Basic auth parameters.  I thought i would post this for people with the same question.

See code below:

 

 // This will download the repository as zip file returning data as stream.

async _download (url, username, password) {
// where 'url' is something like:
// /${workspace}/${repoSlug}/get/${whateverNameYouWant}.zip

const auth = new Buffer.from(`${username}:${password}`).toString('base64');
const fileResponse = await axios.request(
{

method: 'get',
baseURL: 'https://bitbucket.org',
url: url,
responseType: 'stream',
headers: {
Authorization: `Basic ${auth}`
}

});

return fileResponse.data;
}
0 votes

Hi @Corey Malcom and welcome to the community.

I'm afraid that we don't have any API endpoint that downloads a zip file of the repository.

We have a feature request about this in our issue tracker, that you can vote for and add yourself as a watcher:

The workaround is indeed to use the following:

curl -u username:app-password https://bitbucket.org/<workspace-id>/<repo-slug>/get/master.zip --output master.zip

I am not familiar with axios, so I'm not sure how to troubleshoot the error you are getting. A 401 response is usually associated with invalid authentication credentials, so I would suggest double checking if you're using an app-password that has appropriate permissions.

If you are able to successfully retrieve the zip via a curl command or Postman using the same app-password as in axios, I would recommend reaching out to the support team of axios. I believe they're better equipped to troubleshoot why the request is failing, when it succeeds with other tools using the same url and credentials.

Kind regards,
Theodora

@Theodora Boudale  Thank you for the response, but I had already found that curl command, and was looking for an API endpoint for this.  I did however finally get this to work via a node app.  I am going to post the answer below.

Like Theodora Boudale likes this

Good to hear that you managed to get this to work, and thank you for posting the solution!

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Calling any interview participants for Bitbucket Data Center

Hi everyone,  We are looking to learn more about development teams’ workflows and pain points, especially around DevOps, integrations, administration, scale, security, and the related challeng...

485 views 5 4
Read article

Community Events

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

Events near you