I have a integration with one of the system and for this I have 2 rest api's one is getting token for calling the main api and another api is adding some notes to that system. So, my question is how to call these 2 rest API's in one Business rule I tried calling them one by one but I don't know it's throwing error like this when I use it in single Business rule!!!
I'm using below code:
var token;
try {
var r = new sn_ws.RESTMessageV2('Integration with BCC', 'Retrive Token');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var lcn = JSON.parse(responseBody);
var value = lcn.access_token;
token = value;
} catch (ex) {
var message = ex.message;
}
var cmts = current.u_additional_comments.toString();
var bccid = current.correlation_id.toString();
var finalDec = removeHtmlTags(cmts);
var body = {};
body.requestBody = {
noteDetails: {
notes: {
characterSetCode: 'US-ASCII',
mediaTypeCode: 'text/plain',
content: finalDec,
}
},
customerProblemID: {
id: bccid,
applicationId: "CCP_Email"
}
},
body.requestInformation = {
};
var jsonString = JSON.stringify(body);
gs.info('++Body' + jsonString);
if (token != '' || token != null) {
token = 'Bearer ' + token;
gs.info('+Access Token: ' + token);
try {
var r1 = new sn_ws1.RESTMessageV2('Integration with BCC', 'Post Notes to BCC');
r1.setStringParameterNoEscape('Authorization', token);
r1.setRequestBody(jsonString);
var response1 = r1.execute();
var responseBody1 = response1.getBody();
var httpStatus1 = response1.getStatusCode();
gs.info('Response Body:'+responseBody1 +'\n Status Code:' +httpStatus1);
} catch (ex) {
var message1 = ex.message1;
}
}
function removeHtmlTags(input) {
var regex = /<[^>]*>/g;
// Remove HTML tags from the input string
var stringWithoutSpecialEntities = input.replace(/&[^\s;]+;/g, '');
var output = stringWithoutSpecialEntities.replace(regex, '');
return output;
}
current.u_comment_to_bcc = 'false';
current.update();