logo
Published on

Getting started with Confluence REST API

developer tools
Authors

Automation is becoming increasingly popular as humans striver to imrpove the quality of their work and reduce the time spent on repetitive tasks. Confluence is a popular tool for creating, organizing, and sharing knowledge within teams and organizations. The Confluence REST API provides a way to interact with Confluence programmatically, enabling you to automate tasks, integrate Confluence with other tools, and build custom applications.

Authentication

  • First, things first, you need to authenticate yourself to the Confluence REST API to use it.
  • The recommended way to authenticate is to use a Personal Access Token (PAT).
  • Once you have a PAT, you can use it to authenticate to the Confluence REST API by setting the Authorization header.
  • Example:
# List all the spaces in your Confluence instance

curl -D- -X GET -H "Content-Type: application/json" -H "Authorization: Bearer <your-pat>" https://<your-domain>/confluence/rest/api/space

Authorization - If you are using a PAT, the level of access you have to the Confluence REST API is determined by the permissions of the user who created the PAT.

REST API Endpoints

Using SDKs as an alternative

  • In some cases, you might find it easier to use an SDK to interact with the Confluence REST API.
  • Atlassian provides SDKs for various programming languages like Java, Python, and DotNet etc.
  • Python example:
# Install the atlassian-python-api package:
#   pip install atlassian-python-api

from atlassian import Confluence

confluence = Confluence(
    url='https://<your-domain>/confluence',
    username=None,
    token='<your-personal-access-token>'
)

spaces = confluence.get_all_spaces()
print(spaces)

Other Attlasian products

  • You can also use the REST APIs or SDKs to programmatically interact with other Atlassian products like Jira, Bitbucket, and Bamboo.
  • For example, the following example show how to query JIRA using Jira Query Language(JQL) and the Python SDK:
from atlassian import Jira

jira = Jira(
    url='https://<your-domain>/jira',
    username=None,
    password='<your-personal-access-token>'
  )
JQL = 'status IN ("To Do", "In Progress") ORDER BY issuekey'
data = jira.jql(JQL)
print(data)
  • You can follow the same steps as Condfluence to create your JIRA PAT and use it to authenticate.
  • The JIRA REST Endpoints can also be used to interact with JIRA programmatically.
  • For example:
# List all the projects in your JIRA instance
curl -D- -X GET -H "Content-Type: application/json" -H "Bearer <your-pat>" https://<your-domain>/jira/rest/api/2/project

Conclusion

  • The Confluence REST API provides a powerful way to interact with Confluence programmatically.
  • Whether you are automating tasks, integrating Confluence with other tools, or building custom applications, the REST API gives you the flexibility to do so.
  • With the recent rise of AI and advancements in NLP, you can even build intelligent assisstants that will help you manage and leverage your Knowledge Base to build intelligent operations.