Blog
In a previous article, I talked about Jira, and if you are a Jira user, chances are that you also use Confluence as they often go hand in hand, Jira as a ticketing application and Confluence as an enterprise knowledge management system.
From the perspective of integrations, connecting to Confluence and invoking its APIs looks and feels practically the same as with Jira:
Let's go through it all step-by-step, starting off with the creation of an API token.
To invoke Confluence, you use an API token that can be shared with other Atlassian products, such as Jira. If you do not have one already, here is how to create it:
In your Zato Dashboard, go to Cloud -> Atlassian -> Confluence:
Click "Create a new connection" and fill out the form below. The username is the same as the email address that you log in to Confluence or Jira with.
Now, click "Change API Token" and enter the token created in the previous section:
Authoring a Zato service that invokes Confluence follows a pattern that will feel familiar no matter what kind of an API you integrate with:
In the case of the code below, we are merely logging the response from Confluence. In a bigger integration, we would process it accordingly, e.g. parts of the output could be synchronized with Jira or another system.
Note the 'client.get_all_pages_from_space' method below - the client will offer other methods as well, e.g. get_space, get_page_as_pdf or ways to run CQL (Confluence Query Language) directly. Use auto-completion in your IDE to discover all the methods available.
# -*- coding: utf-8 -*-
# Zato
from zato.common.typing_ import cast_
from zato.server.service import Service
# ###########################################################################
if 0:
from zato.server.connection.confluence_ import ConfluenceClient
# ###########################################################################
class GetAllPages(Service):
def handle(self):
# Name of the Confluence space that our pages are in
space = 'ABC'
# Name of the connection definition to use
conn_name = 'My Confluence Connection'
# .. create a reference to our connection definition ..
confluence = self.cloud.confluence[conn_name]
# .. obtain a client to Confluence ..
with confluence.conn.client() as client: # type: ConfluenceClient
# Cast to enable code completion
client = cast_('ConfluenceClient', client)
# Get all pages from our space
pages = client.get_all_pages_from_space(space)
self.logger.info('Pages received -> %s', pages)
# ###########################################################################
That is all - you have create an Atlassian API token, a Zato Confluence connection and you have integrated with Confluence in Python!