REST API: styled view returning format errors
Asked by Blake Pitts:

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


Answers:
author: Diego
body: 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](https://marketplace.atlassian.com/apps/284/confluence-command-line-interface-cli?hosting=cloud&tab=installation)  

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

- [CLI Client Installation and Use](https://bobswift.atlassian.net/wiki/spaces/ACLI/pages/98009238/CLI+Client+Installation+and+Use#CLIClientInstallationandUse-Downloads)  

And here are a few parameters usage examples:  
- [Examples](https://bobswift.atlassian.net/wiki/spaces/CSOAP/pages/10584066/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!  

comments: author: Blake Pitts
body: Hey Diego,

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


author: Diego
body: 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!


author: Gianluca
body: 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?


Tags: cloud

confluence-cloud

development

page

rest-api