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

Bitbucket Rest Api call using python resulting in 404 status code for archive

Kailash Patra December 13, 2017

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

1 answer

1 accepted

0 votes
Answer accepted
Aaron
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 15, 2017

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

Kailash Patra December 16, 2017

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

Kailash Patra December 19, 2017

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

Aaron
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 21, 2017

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

Kailash Patra December 21, 2017

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/rest/archive/latest/projects/projKey/repos/repoKey/archive?at=commitId&format=zip

https://bitbucket.xxxx.com/plugins/servlet/archive/projects/projKey/repos/repoKey?at=commitId

Regards,
Kailash

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events