Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Custom Integrations Tutorial for Confluence

Introduction

Custom integrations allow you to connect Confluence with other tools and services to streamline workflows and enhance productivity. This tutorial will guide you through the process of creating a custom integration with Confluence, including setting up the environment, creating a simple integration, and testing it.

Setting Up Your Environment

Before you begin, ensure you have the following prerequisites:

  • A Confluence account with admin privileges.
  • Access to the Confluence Cloud or Server API.
  • A development environment set up with Node.js installed.

Once you have the prerequisites, you can start by creating a new project directory:

mkdir confluence-integration
cd confluence-integration

Creating a Simple Integration

In this section, we will create a simple integration that retrieves a list of pages from a Confluence space. We will use the Confluence REST API for this purpose.

First, install the Axios library for making HTTP requests:

npm install axios

Next, create a new file named index.js and add the following code:

const axios = require('axios');

const confluenceBaseUrl = 'https://your-domain.atlassian.net/wiki/rest/api';
const spaceKey = 'YOUR_SPACE_KEY';
const username = 'YOUR_USERNAME';
const apiToken = 'YOUR_API_TOKEN';

const fetchPages = async () => {
    try {
        const response = await axios.get(
            `${confluenceBaseUrl}/space/${spaceKey}/content`,
            {
                auth: {
                    username: username,
                    password: apiToken
                }
            }
        );
        console.log('Pages:', response.data);
    } catch (error) {
        console.error('Error fetching pages:', error);
    }
};

fetchPages();
                

Replace your-domain, YOUR_SPACE_KEY, YOUR_USERNAME, and YOUR_API_TOKEN with your actual Confluence information.

Testing Your Integration

To run your integration, use the following command in the terminal:

node index.js

If everything is set up correctly, you should see a list of pages from your specified Confluence space in the console.

Pages: [
    {
        id: "123456",
        title: "Sample Page",
        type: "page",
        ...
    },
    ...
]
                

This confirms that your integration is working and you can retrieve data from Confluence!

Conclusion

In this tutorial, you learned how to set up a custom integration with Confluence using Node.js and the Confluence REST API. You created a simple integration to fetch pages from a specific space and tested it successfully. From here, you can expand your integration to include additional features such as creating or updating pages, integrating with other services, and more.

Happy coding!