Outbound REST API help

ClareM
Tera Expert

Hi,

 

I have been following the this article which has been really useful to create a REST Message: use-bearer-token-for-rest-message-authentication 

 

The first REST Message is working and I am getting the token in the log message however the second REST Message is returning a 400 status code "Bad Request" response.

 

When I've tested the Rest Message with test values as the variable substitutes it's working fine and I'm getting a 200 status code with the expected response so I assume there is an issue with the script include.

 

I've checked that companyName, account, sortcode, type and token are all returning the correct values in a log message.

 

I've attached my script include code & REST Message and this is my script include code:

 

var BankDetailsCheck = Class.create();
BankDetailsCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {
 
    getToken: function() {
 
        try {
            var rm = new sn_ws.RESTMessageV2('bankDetailsChecker', "authenticate");
            var response = rm.execute();
            var responsebody = response.getBody();
            var httpStatus = response.getStatusCode();
 
            var a = JSON.parse(responsebody);
            var token = a.token;
            gs.log('token: '+token);
            return token;
        } catch (ex) {
            var message = ex.getMessage();
            gs.error("bankChecker:Token:Error: " + message);
        }
    },
 
retrieveBankCheckResult: function() {
var token = this.getToken();
        var companyName = this.getParameter('sysparm_companyName');
        var sortcode = this.getParameter('sysparm_sortcode');
        var account = this.getParameter('sysparm_account');
var type = this.getParameter('sysparm_type');
 
        var request = new sn_ws.RESTMessageV2('bankDetailsChecker', "checkBankDetails");
request.setStringParameter('token', token);
request.setStringParameter('customerName', companyName);
request.setStringParameter('bankAccount', account);
request.setStringParameter('sortCode', sortcode);
request.setStringParameter('accountType', type);
 
        try {
            var response = request.execute();
var httpStatus = response.getStatusCode();
            gs.log('BankDetailsCheck retrieveBankCheckResult httpStatus:' + httpStatus);
var responseBody = response.getBody();
gs.log('BankDetailsCheck retrieveBankCheckResult responseBody:' + responseBody);
var a = JSON.parse(responseBody);
var result = a.nameMatchResult;
            
        } catch (ex) {
            var message = ex.message;
            gs.log('BankDetailsCheck retrieveBankCheckResult message:' + message);
        }
 
return result;
    },
    type: 'BankDetailsCheck'
 
REST Message.png

 

Can anyone give me any pointers?

 

Thanks,

 

Clare

14 REPLIES 14

AbinC
Tera Contributor

HI @ClareM ,

 

PLease do follow the steps mentioned in the below link for your solution 

https://help.sap.com/docs/successfactors-platform/using-integration-center/configuring-rest-based-ou...

 

if you found this to be helpful please do tag this solution as helpful.

 

Thanks,

Abin

Ankur Bawiskar
Tera Patron
Tera Patron

@ClareM 

it would be nice if you could share the actual script here rather than image

Did you see what came in logs when you debugged?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks for your feedback, I have updated my post

@ClareM 

how and from where are you triggering the script?

also what came in logs for the response body?

were you able to set the request body and print it and see if all values were replaced fine?

are you getting the token?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader