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

Bitbucket REST API does not return JSON format running cURL on Windows

Eduardo Velasquez May 5, 2022

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"}

 

2 answers

1 accepted

0 votes
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 9, 2022

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 username
AppPassword replace with an app password for your account
WORKSPACE-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

Eduardo Velasquez May 9, 2022

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.

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 11, 2022

Hi @Eduardo Velasquez,

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.

Kind regards,
Theodora

Eduardo Velasquez May 11, 2022

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!

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 18, 2022

Hi Eduardo,

You are very welcome, it's good to hear that this worked!

I created a feature request in our issue tracker for the Bitbucket API to return the output JSON formatted:

You can add your vote to that ticket (by selecting the Vote for this issue link) as the number of votes helps the development team and product managers better understand the demand for new features. You are more than welcome to leave any feedback, and you can also add yourself as a watcher (by selecting the Start watching this issue link) if you'd like to get notified via email on updates.

Implementation of new features is done as per our policy here and any updates will be posted in the feature request.

Have a great day too! Please feel free to reach out if you ever need anything else!

Kind regards,
Theodora

Like Eduardo Velasquez likes this
Eduardo Velasquez May 18, 2022

Thank you Theodora! You got my vote!

Like Theodora Boudale likes this
0 votes
Paul Sherman October 26, 2022

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>

Eduardo Velasquez October 26, 2022

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,

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events