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