Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

REST API: styled view returning format errors

Blake Pitts August 7, 2018

I'm trying to return the CSS and HTML for a confluence page. The response comes back with a lot of other characters mixed into the HTML and CSS such as: \n, \, etc. Is there a way to get a cleaner response back? 

 

Thank you,

Blake

1 answer

0 votes
Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 21, 2018

Hello Blake, good question you have there.
Currently, the API does insert some unwanted characters in the HTML output.
However, our vendor Bob Swift has the Command Line Interface for Confluence:

- Confluence Command Line Interface

You will find instructions on how to use the application here:

- CLI Client Installation and Use

And here are a few parameters usage examples:
- Examples

The basic structure you are looking to use is this:

./confluence.sh --server http://<your-instance-url> --user <user-with-permissions> --password "<user-password>" --action getSource  --space "<space-name>"  --id <page-id>

This will return the page HTML without the unwanted characters.

Let the community know if this helps your case!

Blake Pitts August 21, 2018

Hey Diego, 

Thank you for your response. So this will bring back the HTML code that I can use on my own site?

Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 21, 2018

Hello Blake!
Yes, this plugin will return the HTML code you are looking for.

However, I went ahead and searched a little bit further. It seems that waht the API does is add \ backslashes to keep JSON coherent. The \n is displayed due to the fact that the browser does not understand it, thus showing the line break.
You can achieve the same using a Python script:

Installing what you need:

sudo pip install requests
sudo pip install json

The script itself, using Confluence own REST API:

import requests
import json

url = 'http://<your-instance-url>/rest/api/content/<page-Id>?expand=body.export_view'

headers = {'Content-Type': 'application/json'}

r = requests.get(url, auth=('admin', 'admin'), headers=headers)
obj = json.loads(r.text)

print(obj['body']['export_view']['value'])

Remember to replace <your-instance-url> and <page-Id>

And you can call the script like this:

python confluence_body_export.py

Let us know if you can implement the script!

Gianluca
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!
November 22, 2018

Hey Diego,

I have a confluence page containing a table and a link to a issue.

the "body ->  export_view -> value" that I recieve is the following:

 

<p>prova provaProva Prova Prova</p><div class="table-wrap"><table class="confluenceTable"><colgroup><col/><col/></colgroup><tbody><tr><th class="confluenceTh">contatore_utilita</th><th class="confluenceTh"><p>0</p></th></tr></tbody></table></div><p class="auto-cursor-target"><style>
.jira-issue {
padding: 0 0 0 2px;
line-height: 20px;
}

.jira-issue img {
padding-right: 5px;
}

.jira-issue .aui-lozenge {
line-height: 18px;
vertical-align: top;
}

.jira-issue .icon {
background-position: left center;
background-repeat: no-repeat;
display: inline-block;
font-size: 0;
max-height: 16px;
text-align: left;
text-indent: -9999em;
vertical-align: text-bottom;
}
</style>

<span class="jira-issue" data-jira-key="CRIP-19" data-client-id="SINGLE_<id>" >
<a href="<mydomain:port>/browse/CRIP-19" class="jira-issue-key"><span
class="aui-icon aui-icon-wait issue-placeholder"></span>CRIP-19</a>
-
<span class="summary">Getting issue details...</span>
<span class="aui-lozenge aui-lozenge-subtle aui-lozenge-default issue-placeholder">STATUS</span>
</span>
</p>

 

As you can see, the classes related to the table such as  table-wrap, confluenceTable, and confluenceTh are not returned. 

Also classes on AUI are not returned, such as aui-lozenge ecc.

Is it a correct behaviour? Can I find these classes somewhere else?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events