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.
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;
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Good to hear that you managed to get this to work, and thank you for posting the solution!
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.