curl extract obtained from the confluence server is not getting parsed by python mjson.tool
Asked by Nikhilesh Saggere:

Hi,

I am using the below command to extract the data from the confluence server

```
curl -u user:"passkey" -X GET "https://confluence.sw.mycompany.com/pages/viewpage.action?pageId=127798346" | python -mjson.tool
```

This command though it extracts but while piping it to the python json format converter it is giving an error as show here:

```
 % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 79367 0 79367 0 0 50295 0 --:--:-- 0:00:01 --:--:-- 50295
Expecting value: line 2 column 1 (char 5)
```

However if I redirect the output of the curl command to a text file, I get the html content.

Could you please help me resolve this error.

My assumption: The confluence server is returning a html output, which python is treating as a byte array instead of strings so it is giving this error.

Please check and let me know.

I have followed the example available here:

<https://developer.atlassian.com/server/confluence/confluence-rest-api-examples/>

```
?curl -u admin:admin -X GET "http://localhost:8080/confluence/rest/api/content?type=blogpost&start=0 &limit=10&expand=space,history,body.view,metadata.labels" | python -mjson.tool
```


Answers:
author: Prince Nyeche
body: Hi [@Nikhilesh Saggere](/t5/user/viewprofilepage/user-id/4168653)

Welcome to Community! If you're accessing via API endpoint from here <https://developer.atlassian.com/server/confluence/confluence-rest-api-examples/> , the output should be in JSON and not HTML. However you should check the directory Confluence is installed, does yours say

```
http://localhost:8080/confluence/rest/api/content
```

or something else as "/confluence" is the directory where Confluence is installed on the Doc's example. if yours is a different directory, then you might want to change that in order to get the output. You can run a test of the URL on your Browser to see the output first, before attempting the curl extraction.

comments: author: Nikhilesh Saggere
body: Hi Prince,

Thank you for your response!

I am a novice in the confluence programming, could you please elaborate where I have to check the installation of the confluence directory? Is it on the server? Because I have not installed the server by myself and it is taken care by the IT department in my organization (Who seems to have no clue on how to check this)

And also when I performed the following URL test on my browser  
<https://confluence.sw.mycompany.com/rest/api/content>

I get huge content like this

```
{"results":[{"id":"2064464","type":"page","status":"current","title":"FRANS Home","extensions":{"position":"none"},"_links":{"webui":"/display/~beq03163/Frans+De+Buys%27s+Home","edit":"/pages/resumedraft.action?draftId=2064464","tinyui":"/x/UIAf","self":"https://confluence.sw.mycompany.com/rest/api/content/2064464"},"_expandable":
```

Please help, does it mean i am getting the output in JSON format?


author: Prince Nyeche
body: Hi [@Nikhilesh Saggere](/t5/user/viewprofilepage/user-id/4168653)

This is the URL <https://confluence.sw.mycompany.com/rest/api/content> you should use instead, since that url works. so your request should be

```
?curl -u user:password -X GET "https://confluence.sw.mycompany.com/rest/api/content?type=blogpost&start=0 &limit=10&expand=space,history,body.view,metadata.labels" | python -m json.tool
```


author: Nikhilesh Saggere
body: Thank you for this information.

If i understand correctly, the following fields which are there as part of the URL shall be replaced by the page that i am interested in, istn't?

```
/content?type=blogpost&start=0 &limit=10&expand=space,history,body.view,metadata.labels"
```

i.e, blogpost and space with actual names used in the confluence page.?


author: Prince Nyeche
body: This "space,history,body.view,metadata.labels" you do not need to change as you're expanding the json. if you need a specific page, use CQL "rest/api/content/search?cql=space=TEST" mentioned on [Advanced searching](https://developer.atlassian.com/server/confluence/advanced-searching-using-cql/).


author: Nikhilesh Saggere
body: Thanks [@Prince Nyeche](/t5/user/viewprofilepage/user-id/1928483) It is working now.


author: Prince Nyeche
body: Hey [@Nikhilesh Saggere](/t5/user/viewprofilepage/user-id/4168653)

Glad to help out, if the above answers your question. Please accept the answer, so other users can see it as a solution.


author: Nikhilesh Saggere
body: Done!


author: Spatel
body: Hi [@Prince Nyeche](/t5/user/viewprofilepage/user-id/1928483)   

I'm totally new to using rest api for confluence. Can you please help me with this  

<https://community.atlassian.com/t5/Jira-questions/PowerShell-to-add-users-in-local-group-in-Confluence/qaq-p/1542009>

Thanks!


Tags: confluence-server

server