Get the content of confluence page data in json format through the rest api

mohammedafzal
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 11, 2023

I can access the confluence page content through the endpoint - 
rest/api/content/{id}?expand=body.storage.


The response of the above endpoint is in HTML format. 

I need the response in the JSON format or any easy way to convert the body to JSON format?.

Any help would be much appreciated. 

1 answer

0 votes
Charlie Misonne
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 12, 2023

Hi @mohammedafzal

The content of Confluence pages can be quite complex. It does not only contain flat text but also macros, formatting details, layouting, ... If you expect the API to return only the text and nothing else I'm afraid it has not been foreseen in the API.

Here is a suggestion: try using the new v2 API. You also have to choose a storage format with a query parameter:

<base-url>/wiki/api/v2/pages/<page-id>?body-format=atlas_doc_format

Options are:

  • storage: html style
  • view: also html but different
  • atlas_doc_format: a structured JSON representation of the body.
    It might suit your needs better altough the json is still quite complex but at least you don't have to worry about the HTML tags.
    With some scripting you could only extract the actual text more easily than with the other formats.

Here is the v2 API documentation: https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-page/#api-pages-id-get

I hope this helps at least a bit!

mohammedafzal
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 13, 2023


We have a self deployed instance of Atlassian tools on premises. 
 <base-url>/wiki/api/v2/pages/<page-id>?body-format=atlas_doc_format -- when we test this endpoint, it is throwing 404. 

Anyother solution would help.

Thanks for your quick support. 

Charlie Misonne
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 13, 2023

I'm sorry. For some reason I thought you were on Cloud.

I don't think there is anything similar of on premise solutions.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events