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

Nikhilesh Saggere November 25, 2020

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

 

1 answer

1 accepted

0 votes
Answer accepted
Prince Nyeche
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2020

Hi @Nikhilesh Saggere 

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.

Nikhilesh Saggere November 25, 2020

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?

Prince Nyeche
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2020

Hi @Nikhilesh Saggere 

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
Like Nikhilesh Saggere likes this
Nikhilesh Saggere November 25, 2020

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.?

Prince Nyeche
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2020

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

Nikhilesh Saggere November 25, 2020

Thanks @Prince Nyeche It is working now.

Prince Nyeche
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2020

Hey @Nikhilesh Saggere 

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

Nikhilesh Saggere November 25, 2020

Done!

Spatel November 27, 2020

Hi @Prince Nyeche 

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!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events