Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×

Forums

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

HTTP request server side

Jesús Jorge Muñoz
Contributor
March 16, 2018

Hello everyone,

I am trying to make a HTTP request from server side, but I think I am not doing it in the proper way.

I am using Node.js + ACE to make a Confluence connect add-on. I am trying to get the HTML code of a certain page in Confluence by using a macro.

In index.js file, I have this code:

app.get('/v1/cover-key', addon.authenticate(), function(req, res){
var pageId = req.query['pageId'],
pageVersion = req.query['pageVersion'],
userKey = req.query['userKey'];
var clientKey = req.context.clientKey;

getHTTPClient (clientKey, userKey).get({
url: '/rest/api/content/53150016?expand=body.view'
},
function(err, response, contents){

if(err || (response.statusCode < 200 || response.statusCode > 299)) {
console.log(err);
}

console.log(contents);
/* Process content and render some view*/
}
);
});

function getHTTPClient (clientKey, userKey){
return addon.httpClient({
clientKey : clientKey,
userKey : userKey,
appKey : addon.key
});
}


With this code, in server side console I get a lot of logging messages with the same content, as if the server was making continuous requests to the instance. In the other hand, in Confluence, I get this message:

"There were errors rendering macro:

  • An unknown error occurred."


Somehow, I figured out that I cannot concatenate query parameters directly to the url using this HTTP client, since if I change url by this one, everything runs fine: 

/rest/api/content/53150016


Then, searching in request client docs, I discovered that I must specify query parameters using "qs" object, so I changed my HTTP client code to this one:

 getHTTPClient (clientKey, userKey).get({
url: '/rest/api/content/53150016',
qs : { expand : 'body.view'}
},
function(err, response, contents){

if(err || (response.statusCode < 200 || response.statusCode > 299)) {
console.log(err);
}

console.log(contents);
/* Process content and render some view*/
}
);

 
But with this code, I get this error:

"HTTP Status 401 - Expecting claim 'qsh' to have value '82cff2bae10b32813530aa4ed7fa6ed70f9cf9dfff19f9b1916bcf350232e466' but instead it has the value 'dd7335e7bcae854cbb80f1f218605b98bbc1e37369aa288c4eff8e638fe485c8'"

What is wrong here?

Thanks in advance,

Jesus

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Kombi, the best car ever
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 4, 2018

Hello, Jesus!

 

According to the Confluence Cloud REST API Documentation:

401 Unauthorized

Returned if the authentication credentials are incorrect or missing from the request.

You'll need to verify once again your authentication method, and make sure that you are following the guidelines from the documentation accordingly before you manage to fetch data from the /rest/api/{contentid} endpoint. Refer to:

And double check your code, this should help you out.

 

Kind regards,

Marco A. Bomfim

TAGS
AUG Leaders

Atlassian Community Events