How to use Confluence Cloud in iFrame
Asked by Dylan Kusters:

Hello,

I would like to use Confluence Cloud environment in a iFrame. Is was wondering if this is possible and how it can be done?  
I saw the next topic: <https://confluence.atlassian.com/confkb/confluence-page-does-not-display-in-an-iframe-827335781.html>  
But I guess this is for the server version?

The error I get at this moment is: in a frame because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self'".

Can someone please help me? Or is there an other way in stead of using it in an iFrame?

Thanks in advance,  
Dylan


Answers:
author: Brad Lauzon
body: I have the same situation as Dylan where we would like to display confluence pages via iframe to another site since the data in confluence pages are wiki. Rest api would be good for pulling data from JIRA type scenario. Anyone figure out how to do this?

comments: author: Oliver Chapple
body: We've used Confluence Cloud's rest API instead of using an iFrame and it works fine for this as it contains HTML within the JSON results.

Here is an example Get webhook string you can use to Get some Confluence space pages using the title to retrieve specific ones. This particular string is being fetched by my Landbot chatbot which has a webhook feature:-   

[https://yourcompany.atlassian.net/wiki/rest/api/content/search?cql=type=page+and+space+in+(PKB)+and+title+\~@{textintitle](https://yourcompany.atlassian.net/wiki/rest/api/content/search?cql=type=page+and+space+in+(PKB)+and+title+~@{textintitle)}  

Where PKB is the Confluence Space name and the @{textintitle} is a custom Landbot Chatbot variable I am passing to Confluence's REST API (with a \~ to search wild, so a keyword anywhere within the pages' titles) . JSON is returned by the Webhook which you can pretty easily JSON.parse to get the elements you want out of the JSON string You need the + signs in the Get Address to replace spaces to work properly with Confluence Cloud REST API. This is how I have built the Webdadi Chabot using Landbot with Webhooks to Confluence Cloud REST API.  

Don't forget that the variable you're passing in as the keywords to search for needs to be in the format with quotes - so "keywordB+keywordB"  

You can substitute 'title' for 'text' to search the page content and then you can also get more structured data out of Confluence's API by adding the 'expand' param, where Confluence gives you more expanded data even HTML in some parts of the JSON.

e.g.  

[https://youcompany.atlassian.net/wiki/rest/api/content/search?cql=title\~%22@{textintitle}%22\&expand=](https://youcompany.atlassian.net/wiki/rest/api/content/search?cql=title~%22@{textintitle}%22&expand=)body.title\&start=5\&limit=25

or an Example to get the Confluence Cloud JSON results with HTML in the JSON String.

[https://yourcompany.atlassian.net/wiki/rest/api/content/](https://webdadi.atlassian.net/wiki/rest/api/content/)" + id + "?expand=body.export_view,history.lastUpdated

Hope that helps, at least generating some useful JSON results.


author: Steve Behnke [DiscoverEquip.com]
body: I haven't attempted anything related with 'putting Confluence inside an iframe' since Confluence 3.x. I can't imagine it's become easier in the meantime. However it might be possible, I do not think that putting webapps inside other webapps via iFrame is a very good solution.

Confluence doesn't offer external 'gadgets' for you to use unfortunately.

I would strongly consider using the REST API to perform typical requests to get, create, update, and delete Questions content. You could probably quickly proof-of-concept it with a simple \<form\> set to POST. For instance, a little 'feed' gadget and a submission box could be constructed with a few lines of HTML and some JAVASCRIPT.

* <https://docs.atlassian.com/confluence-questions/rest/index.html>


author: Dylan Kusters
body: Hello Steve,  

Thanks for your quick answer. The reason I would like to do this is because we are having an application and we would like to have an integrated online community for all the users of the application. So that when they are in a process of our application, they can ask a question directly on that moment.

Is this enough info ?  

Regards

Dylan


author: Steve Behnke [DiscoverEquip.com]
body: Perhaps you should talk about why you're trying to do this, so someone here can dissuade you. Hosting a webapp in another iframe is usually a bad idea, because most developers aren't going to design their application in such a way that it would work when rendered through an iframe.

Confluence heavily uses iframes as it is too, I can't imagine there'd be any easy way to make it happen.

comments: author: Oliver Chapple
body: Perhaps I can suggest substituting the iframe for using the Confluence Cloud REST API and getting the HTML out of the JSON string of results using the expand param that's there with the page article encapsulated in HTML.


Tags: cloud

iframe