Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to send with rest message a form-urlencoded body?

fabrizio95360
Tera Expert

Hi, how can I send these values ​​via rest message? key: client_id, value: 1234 ||

key: client_secret, value: 5678?

I'm trying to do this via a fix script in servicenow: 

 

var r = new sn_ws.RESTMessageV2('rest goSign token', 'GETTOKEN');
var response = r.execute();
        var responseBody = response.getBody();
        var httpStatus = response.getStatusCode();

        if (httpStatus === 200) {
			gs.info('http status: ' + httpStatus);
            gs.info('token: ' + responseBody);
            
        } else {
            gs.info('Error Assertion: ' + responseBody);
            gs.error(' http status: ' + httpStatus);
        }

 

 

1 REPLY 1

Tushar
Kilo Sage
Kilo Sage

Hi @fabrizio95360 

 

Please try below -

 

var r = new sn_ws.RESTMessageV2('rest goSign token', 'GETTOKEN');
r.setAuthentication('basic', '1234', '5678'); // Replace '1234' and '5678' with your actual client_id and client_secret values
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();

if (httpStatus === 200) {
  gs.info('http status: ' + httpStatus);
  gs.info('token: ' + responseBody);
} else {
  gs.info('Error Assertion: ' + responseBody);
  gs.error('http status: ' + httpStatus);
}

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar