Hi, I'm trying to get the list of repositories in Bitbucket Cloud running cURL on a Windows laptop. For testing, I type the following command in the command prompt:
curl https://api.bitbucket.org/2.0/repositories
And the output is just a long, unformatted text, not JSON formatted as shown in the documentations - see below.
What am I doing wrong? Thanks,
{"pagelen": 10, "values": [{"scm": "git", "has_wiki": false, "links": {"watchers": {"href": "https://api.bitbucket.org/2.0/repositories/jwalton/opup/watchers"}, "branches": {"href": "https://api.bitbucket.org/2.0/repositories/jwalton/opup/refs/branches"}, "tags": {"href": "https://api.bitbucket.org/2.0/repositories/jwalton/opup/refs/tags"}, "commits": {"href": "https://api.bitbucket.org/2.0/repositories/jwalton/opup/commits"}, "clone": [{"href": "https://bitbucket.org/jwalton/opup.git", "name": "https"}, {"href": "git@bitbucket.org:jwalton/opup.git", "name": "ssh"}], "self": {"href": "https://api.bitbucket.org/2.0/repositories/jwalton/opup"}, "source": {"href": "https://api.bitbucket.org/2.0/repositories/jwalton/opup/src"}, "html": {"href": "https://bitbucket.org/jwalton/opup"}, "avatar": {"href": "https://bytebucket.org/ravatar/%7B7e35bde1-67e7-4d8f-ae29-05dd10424072%7D?ts=java"}, "hooks": {"href": "https://api.bitbucket.org/2.0/repositories/jwalton/opup/hooks"}, "forks": {"href": "https://api.bitbucket.org/2.0/repositories/jwalton/opup/forks"}, ..."next": "https://api.bitbucket.org/2.0/repositories?after=2011-09-21T00%3A05%3A50.970472%2B00%3A00"}
Hi @Eduardo Velasquez,
The curl command you are using is going to return all public repositories in Bitbucket Cloud. Is this what you are trying to do?
If you want to get all repositories of a certain workspace instead, including private ones, you will need to include the workspace-id in the URL and also authentication details.
curl -u BitbucketUsername:AppPassword https://api.bitbucket.org/2.0/repositories/WORKSPACE-ID
where BitbucketUsername replace with your Bitbucket usernameAppPassword replace with an app password for your accountWORKSPACE-ID replace with the workspace id of the workspace that you want to get repos for
The output you posted here seems to be only part of the output, and I see 3 dots before the field "next"
, ... "next":
Is this how the output shows in your command line application? Or did you remove part of the output when copying-pasting it here?
If the output gets truncated, as a workaround you can try using the option -o in order to write the output in a file and inspect it there
curl https://api.bitbucket.org/2.0/repositories -o myFile.txt
Kind regards,Theodora
Hi @Theodora Boudale, thanks for your comments. All I want is to test the command using cURL on my Windows laptop that's why I'm accessing the public repositories and yes, I just copied a portion of the output here, to show that the output is not JSON formatted as shown in the documentation. I also tested the same cURL command in a LINUX server and the result is the same, the output is not JSON formatted.
Apologies, I misunderstood your question.
Curl does not format its output. If you want the output to be displayed formatted, you can use another tool that does that, e.g. jq:
If you install jq on your machine, you can run from command prompt
curl https://api.bitbucket.org/2.0/repositories | jq .
and the output will be formatted.
Thanks @Theodora Boudale worked like a charm!
Too bad we have to use an additional software to format the output. Other software such as ArtiFactory and Jenkins REST API outputs are JSON formatted using curl and I was expecting the same using Bitbucket Cloud REST API.
Oh well, maybe in a future release.
Thanks again. Have a great day!
Hi @Theodora Boudale and @Eduardo Velasquez you might find my notes on an earlier thread helpful. They address to some mistakes in the support document related to Windows.
Also, when using the SSH method of authentication, you need to use the ssh:// protocol. For example, simply setting the url like this will do the trick:
git remote set-url origin ssh://git@bitbucket.org/<workspace-id>/<repo-name>
Hi @Paul Sherman, unfortunately your observations are not related with the reported issue but I do appreciate your time. A feature request has been created by @Theodora Boudale to address it. Thanks,
It looks like you're new here. Sign in or register to get started.