Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

I cannot access to Confluence from API

Qwerky City November 11, 2022

Dear Person who may it concern,

 

I am struggling with access Confluence page from node.js.

error bad request returns when I run below node.js from terminal.

So, I think it is issue from Authentication.

 

Below is code that try to access confluence.

 

===========================================================

const PORT = 8000;

const express = require("express");
const axios = require("axios");
const cheerio = require("cheerio");

const app = express();

//Web scraping
const URL =
"https://confluence.xxxxxx.com/confluence/display/xxxxx/confluce page name here/";
const data = [];

axios(URL)
.then((response) => {
const htmlParser = response.data;
// console.log(htmlParser);
const $ = cheerio.load(htmlParser);

$(".table-wrap", htmlParser).each(function () {
const title = $(this)
.find(
'.teamcdummyprojectSchedule(Schedule)'
)
.text();
data.push({ title });
console.log(data);
});
})
.catch((error) => console.log(error));

 

===========================================================

1 answer

1 vote
Fabio Racobaldo _Catworkx_
Community Champion
November 12, 2022

Hi @Qwerky City ,

welcome to the Atlassian community!

In order to retrieve content, you need to use a REST Api like the following https://developer.atlassian.com/cloud/confluence/rest/v1/api-group-content/#api-wiki-rest-api-content-get

At that link you will find also an example for Node.js

Hope this helps,

Fabio

Qwerky City November 14, 2022

Dear @Fabio Racobaldo _Catworkx_ 

Thank you for your answer.

It seems I still have issue with login authentication to Confluence from API.

 

fetch('https://your-domain.atlassian.net/wiki/rest/api/content',

{ method: 'GET', headers: { 'Authorization': `Basic ${Buffer.from( 'email@example.com:<api_token>' ).toString('base64')}`, 'Accept': 'application/json' } })

 

fetch('https://your-domain.atlassian.net/wiki/rest/api/content',

email@example.com : I input my login email address

<api_token> : Remove <>, and input personal token for target confluence page

 

Since I can scrape contents in non-authentication webpages, so I think it's issue on login authentication.,

Qwerky City November 17, 2022

Dear @Fabio Racobaldo _Catworkx_ 

Sorry it seems what I input in <api_token> is personal token, not access token.

But still not sure where I can find its access token from Confluence.

Qwerky City November 19, 2022

Dear @Fabio Racobaldo _Catworkx_ 

Thank you so much for your reference.

I took a look, but it seems something different with my Confluence (UI, function is not same as one in Google).

Because my Confluence is customized by my company.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events