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));
===========================================================
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
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.,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Qwerky City ,
take a look here https://support.atlassian.com/confluence-cloud/docs/manage-oauth-access-tokens/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.