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

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

0 vote

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

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

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

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

1,749 views 1 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you