How to get Conflunece knowledge base data through API?
Asked by Rahul Kumar:

Hi  

I want to integrate Confluence into my website.  

I need the following two functionality:  

1. User comes to my website and clicks Connect. The user grants authorization.  
2. User search in our 'dedicated search section of confluence', they will start seeing the data(if they have authorized) .  

<br />

Can anyone provide the documentation for getting Confluence KnowledgeBase Data through API?


Answers:
author: Diego
body: Hello there! Hey Rahul, thanks for reaching out to Community.

You can use REST API to perform searches in Confluence. Here we have documentation on this here:

**[Confluence Server Developer - REST API](https://developer.atlassian.com/server/confluence/confluence-server-rest-api/)**

[**Confluence Cloud Developer - REST API**](https://developer.atlassian.com/cloud/confluence/rest/?_ga=2.75048274.1703416670.1552311486-1770418407.1541684782#d2e190)

Since we need to authenticate to send the search request and get the response, you can find some very useful information in this other thread, here in the Community:

**[How to login to Confluence using REST API](https://community.atlassian.com/t5/Confluence-questions/How-to-login-to-confluence-using-REST-API/qaq-p/675831)**

Let us know if this helps you out Rahul!

comments: author: Rahul Kumar
body: HI [@Diego](/t5/user/viewprofilepage/user-id/1188952) , thanks for the reply.  

I am able to get Confluence **content** through rest API.  

But, the content which is made **global,** is only accessible through the rest API.  

How will I get data, if not global?  

*I want to emphasise, **my website** which I have mentioned here is* non-Atlassian*website, like - www.abcde\*\*\*\*xyz.com.*


author: Diego
body: Hello Rahul!

Yes, most of this procedure will be done by REST API. Here is an example of search using REST API:

```
curl -u admin:admin -G "http://myinstance.address:8090/rest/api/content/search" --data-urlencode "cql=(type=page and space=low and title ~ "LOWERTOWN")" \ | python -m json.tool
```

The example above will search for a **Confluence Page** within the space with **low as its key** and that has the title set as **LOWERTOWN**.

The username:password is mandatory. You will need to get it from your users through a variable. This variable should be populated by the website user itself.

You can check here how to create more complex queries for Confluence:

**[Advanced Searching using CQL](https://developer.atlassian.com/server/confluence/advanced-searching-using-cql/)**

Also, here we have some REST API examples:

**[Confluence Server - REST API examples](https://developer.atlassian.com/server/confluence/confluence-rest-api-examples/)**

With the result, we now need to look into **_links and "webui"**. This shows us what is the address that Confluence looks into when accessing this page. In this current example, the full results are as follow:
> {  
> "_expandable": {  
> "ancestors": "",  
> "body": "",  
> "children": "",  
> "container": "",  
> "descendants": "",  
> "extensions": "",  
> "history": "/rest/api/content/3997785/history",  
> "metadata": "",  
> "operations": "",  
> "space": "/rest/api/space/low",  
> "version": ""  
> },  
> "_links": {  
> "self": "<http://myinstance.address:8090/rest/api/content/3997785>",  
> "tinyui": "/x/WQA9",  
> "webui": "/display/low/LOWERTOWN"  
> },  
> "id": "3997785",  
> "restrictions": {},  
> "status": "current",  
> "title": "LOWERTOWN",  
> "type": "page"  
> }  
> \],  
> "size": 1,  
> "start": 0  
> }

By grabbing the "webui" link, we can recreate the full page link, which would be *<http://myinstance.address:8090/display/low/LOWERTOWN>*.

With this link, we can now try to **show the page within an iFrame:**

    <iframe src="http://myinstance.address:8090/display/low/LOWERTOWN"></iframe>

Confluence may ask for authentication at this point or straight up refuse to show the page. In this case, we will need to look into XRSF:

**[Confluence page does not display in an iframe](https://confluence.atlassian.com/confkb/confluence-page-does-not-display-in-an-iframe-827335781.html)**

All the data manipulation will need to be done by means external to Confluence and REST API. You could try and use JavaScript for this:

**[Cookie-based auth for REST APIs](https://developer.atlassian.com/cloud/jira/platform/jira-rest-api-cookie-based-authentication/?_ga=2.100402398.1703416670.1552311486-1770418407.1541684782)**

[**Writing a JavaScript REST client**](https://blog.miguelgrinberg.com/post/writing-a-javascript-rest-client)

Hope this drives your objectives a little further Rahul! Let us know your results, looking forward to your reply.


Tags: atl-adm

knowledge-base

rest-api