Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to use Confluence REST API to post HTML content?

Edited

I have done a lot of reading both here and in Stackoverflow. I still cannot make this work, and I am wondering if it is possible. I am using this example:

https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-update-a-page-with-Python-using-REST-API/qaq-p/480627

For some reason I can't reply on that page, so I am writing a new question here.

If I use the field:

'body': {
'storage':
{
'representation': 'storage',
'value': str(content)
}
}

where the content is:

<table><tbody><tr><th>H1</th><th>H2</th></tr><tr><td>column1</td><td>column2</td></tr></tbody></table>

This posts the string in content, i.e., it doesn't get formatted as a table - actually it adds a space between the tag elements.

Am I missing something, such as the 'html/body' elements in the string that I send in the storage/data field? I also tried adding these, and still it posts the actual string.

Thanks,

Dirce

PS: I also tried this simple html string: <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html>

and that also posts the string itself. So my problem is not about the table, but in figuring out what am I doing wrong in posting HTML so that Confluence will interpret it.

 

1 answer

Hi , I'm Thomas (beginner)

I work on the same challenge. Dont get the "REST API" example running. Is there a step by step tutorial.

Another interface might be "html-migration" - macro. I activated it but I can not see it in the macro-browser. Same request: is there a step by step tutorial.

I got it to work. In my code, where I show 'value': str(content)
I was making the mistake where I had encoded the content, as you would to for an http encoding. In this case, once I put in the actual string (beginning with<table> ), it worked. 

Hi Dirce, how did you manage to post the str with HTML content?

If I don't escape special HTML characters like "<" and ">" to "&lt;" and "&gt;", I get HTTP error 400 when posting HTML string to Confluence:

HTTPError: 400 Client Error: for url: https://example.net/instance_name/rest/api/content/12343567890

However, if I escape HTML, I get the HTML string posted to Confluence page as-is. For example, I get links displayed as HTML code, like <a href="some_url">Some text</a>. How did you manage to get this code to post HTML?

Thank you.

Like Zachary Hayes likes this

Having the same issue as Stan. Any solution? 

Hi All,

Even I am facing the same issue to post HTML table content to confluence page. It was working fine before. 

I am using lambda function where I am using requests module to post .

```

r = requests.post(url=url, data=json.dumps(data), headers=headers)

```

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

You’re invited: Confluence for MS Teams Live demo + Q&A

This past summer, we joined forces with Microsoft Teams as a part of our mission to help your team collaborate better, starting with more effective meetings. We released a new and improved Confluence...

82 views 0 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you