Hi,
I am trying to use Bitbucket server rest api in python to get an archive of a certain commit. I am following the rest api documentation as below.
/REST/API/1.0/PROJECTS/{PROJECTKEY}/REPOS/{REPOSITORYSLUG}/ARCHIVE?AT&FILENAME&FORMAT&PATH&PREFIX
My python code to implement above api is as below.
>>> url = 'https://bitbucket.xxxx.com/rest/api/1.0/projects/CMPOC/repos/hello-world/archive?at=b34bb40f9e5&format=zip'
>>> r = requests.get(url, auth=('username', 'password'), headers=headers)
>>> print(r.status_code)
404
I am getting 404 status code. Any help would be highly appreciated.
Regards,
Kailash
Hello Kailash,
I wrote a quick script in python3 to try the same and could only get a 404 if I put in the URL incorrectly (I also tried using the short hash and the full hash for the commit, it worked regardless of which I used). From what I can see, the actual rest call seems to be formulated correctly. So this can only be either the project, repo, or the base URL aren't added correctly. When you access your site (let's say on the login screen) do you see https://bitbucket.xxxx.com/login or https://bitbucket.xxxx.com/<SOME CONTEXT PATH>/login? If it's the latter, ensure you place that in the API call as well as you need the context path for it to work.
If you aren't using a context path, I would try to navigate to the commit itself and confirm everything has been typed correctly.
Regards,
Aaron Levinson
Dev Tools Support Engineer
Hi Aaron,
Thanks for your reply. I am able to get a 200 status code using below URL.
https://bitbucket.xxxx.com/rest/archive/latest/projects/projKey/repos/repoKey/archive?at=commitId&format=zip"
But I am not sure where its downloading the zip package or its downloading at all. Documentation only says it stream an archive but how can I save the archive to my local?
Appreciate your help!
Regards,
Kailash Patra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Aaron,
https://bitbucket.xxxx.com/rest/archive/latest/projects/projKey/repos/repoKey/archive?at=commitId&format=zip"
Above URL was working till yesterday. If I add path= query to above URL it was downloading the content of the path only.
But today above url not working anymore. After doing some research seems like above url not valid anymore and below is the new url.
https://bitbucket.xxxx.com/plugins/servlet/archive/projects/projKey/repos/repoKey?at=commitId
Also path= query is no longer working with this new url and its downloading the entire repo.
Appreciate if you could help.
Thanks,
Kailash
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Kailash,
I'm unsure as to how a REST API would be valid one day, and not the next. The API doesn't change. You mentioned "path= query is no longer working." If you can show me exactly what query you are attempting to run and what you are expecting out of it, I can have a better chance of being able to assist you.
Regards,
Aaron Levinson
Dev Tools Support Engineer
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Aaron,
I just reinstalled Bitbucket server archive plugin and now both the below url started working as expected with path= query
https://bitbucket.xxxx.com/plugins/servlet/archive/projects/projKey/repos/repoKey?at=commitId
Regards,
Kailash
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.