Integrate v0 with Confluence quickly and easily using our step-by-step guide. Discover expert tips to streamline your workflow and boost productivity.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
package.json file and locate the "dependencies" section.
"axios": "^0.27.2"
package.json. Your project will now include axios when it is packaged or built.
ConfluenceClient.ts in your project’s source directory (for example, in the src folder).
import axios from 'axios';
export interface ConfluenceConfig {
baseUrl: string;
username: string;
apiToken: string;
}
export class ConfluenceClient {
private config: ConfluenceConfig;
constructor(config: ConfluenceConfig) {
this.config = config;
}
private get auth() {
// Create a Base64 encoded authentication token
const token = Buffer.from(${this.config.username}:${this.config.apiToken}).toString('base64');
return Basic ${token};
}
// Method to retrieve a Confluence page by page ID
async getPage(pageId: string): Promise {
const url = ${this.config.baseUrl}/rest/api/content/${pageId};
const response = await axios.get(url, {
headers: {
Authorization: this.auth,
'Content-Type': 'application/json'
}
});
return response.data;
}
// Method to create a new Confluence page
async createPage(spaceKey: string, title: string, body: string, parentId?: string): Promise {
const url = ${this.config.baseUrl}/rest/api/content;
let newPage: any = {
type: "page",
title: title,
space: { key: spaceKey },
body: {
storage: {
value: body,
representation: "storage"
}
}
};
// Optionally set a parent page using its ID
if (parentId) {
newPage = {
...newPage,
ancestors: [{ id: parentId }]
};
}
const response = await axios.post(url, newPage, {
headers: {
Authorization: this.auth,
'Content-Type': 'application/json'
}
});
return response.data;
}
}
App.ts or similar.
import { ConfluenceClient, ConfluenceConfig } from './ConfluenceClient';
// Replace with your actual Confluence details
const confluenceConfig: ConfluenceConfig = {
baseUrl: 'https://your-confluence-instance.atlassian.net/wiki',
username: '[email protected]',
apiToken: 'your-api-token'
};
const confluenceClient = new ConfluenceClient(confluenceConfig);
getPage and createPage methods in your code wherever you need to interact with Confluence. For example, to retrieve a page by its ID, add:
async function fetchConfluencePage() {
try {
const page = await confluenceClient.getPage('123456');
console.log('Page Data:', page);
} catch (error) {
console.error('Error fetching page:', error);
}
}
fetchConfluencePage();
async function publishNewPage() {
try {
const newPage = await confluenceClient.createPage(
'SPACEKEY',
'New Page Title',
'This is sample content for the new page.
',
'654321' // Optional parent page ID
);
console.log('New Page Created:', newPage);
} catch (error) {
console.error('Error creating page:', error);
}
}
publishNewPage();
package.json will be picked up.When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.