How to get Conflunece knowledge base data through API?

Rahul Kumar March 12, 2019

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) .


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

1 answer

0 votes
Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 13, 2019

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

Confluence Cloud Developer - REST API

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

 

Let us know if this helps you out Rahul!

Rahul Kumar March 14, 2019

HI  @Diego , 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. 

Diego
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 14, 2019

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

Also, here we have some REST API examples:

Confluence Server - 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

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

Writing a JavaScript REST client

 

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

Like Scott Epperson likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events