Bitbucket REST API does not return JSON format running cURL on Windows
Asked by Eduardo Velasquez:

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


Answers:
author: Theodora Boudale
body: Hi [@Eduardo Velasquez](/t5/user/viewprofilepage/user-id/3833836),

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

<br />

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

comments: author: Eduardo Velasquez
body: Hi [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086), 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**.


author: Theodora Boudale
body: Hi [@Eduardo Velasquez](/t5/user/viewprofilepage/user-id/3833836),

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**:

* <https://stedolan.github.io/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


author: Eduardo Velasquez
body: Thanks [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) 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!


author: Theodora Boudale
body: 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:

* <https://jira.atlassian.com/browse/BCLOUD-21908>

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](https://confluence.atlassian.com/support/implementation-of-new-features-policy-201294576.html) 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


author: Eduardo Velasquez
body: Thank you Theodora! You got my vote!


author: Paul Sherman
body: Hi [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) and [@Eduardo Velasquez](/t5/user/viewprofilepage/user-id/3833836) you might find my [notes](https://community.atlassian.com/t5/Bitbucket-questions/SSH-setup-for-Windows-not-working/qaq-p/799145#U2173546) 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\>

comments: author: Eduardo Velasquez
body: Hi [@Paul Sherman](/t5/user/viewprofilepage/user-id/5063094), 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](/t5/user/viewprofilepage/user-id/818086) to address it. Thanks,


Tags: bitbucket-cloud

cloud

curl

rest-api

windows