3

I want to download a single file from my Bitbucket repository. In the documentary I found the following API call.

https://api.bitbucket.org/1.0/repositories/{accountname}/{repo_slug}/raw/{revision}/{path}

However I struggle to find out what my "accountname", "repo_slug", "revision" and "path" is.

If I open the folder "scripts" in my Bitbucket account the browser displays the following link.

https://example.com/projects/MMMA/repos/iapc_reporting/browse/scripts

For accountname I used "MMMA", for repo_slug "iapc_reporting", for revision the branch "master", and for path "scripts/main.py". The URL now looks like this:

https://api.bitbucket.org/1.0/repositories/MMMA/iapc_reporting/raw/master/scripts/main.py

Unfortunately opening this link in my browser gives me an 404 error. How do I properly buidl this link? If you had a solution with the V2 API that would be even better.

jz22
  • 2,328
  • 5
  • 31
  • 50

1 Answers1

1

If your server "example.com" is managed by a BitBucket server, then the API url should be:

https://example.com/rest/api/1.0/projects/MMMA/repos/iapc_reporting

See "Bitbucket Server REST APIs".

In your case, since it is a private repo, with a curl --user user:pw:

https://example.com/rest/api/1.0/projects/MMMA/repos/iapc_reporting/raw/master/scripts/main.py
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Unfortunately this leads to a 404 error page in an xml format. – jz22 Jul 07 '17 at 08:54
  • @user3080315 Unless you have an old version of BitBucket as a server, this is the correct syntax, as documented in https://developer.atlassian.com/bitbucket/server/docs/latest/how-tos/command-line-rest.html – VonC Jul 07 '17 at 08:56
  • @user3080315 Do you at least access https://example.com/rest/api/1.0/ ? – VonC Jul 07 '17 at 08:57
  • Shows me the same page. Is that even possible that my company set up Bitbucket without the API? – jz22 Jul 07 '17 at 09:08
  • @user3080315 That possible, check with your IT support department. – VonC Jul 07 '17 at 09:10
  • I looked it up and is installed. I tried to do this curl -u username:password https://example.com/projects/MMMA/repos/iapc_reporting/browse/scripts/main.py?raw and it actually shows me the whole content of the main.py my cmd console. What do you think about that? – jz22 Jul 07 '17 at 09:40
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/148591/discussion-between-vonc-and-user3080315). – VonC Jul 07 '17 at 09:41
  • That is the URL seen by the user in the BitBucket web page. That does not use directly the API. – VonC Jul 07 '17 at 09:42