Rest Message OUTBOUND

ican
Tera Contributor

Use Case:

I want to use Rest Message Endpoint with Parameters and HTTP Query Parameters:

 

Endpoint: https://test.com/${id}

 

HTTP Query Parameters:

api_username: testapiusername

api_key: testapikey

 

is this possible?

6 REPLIES 6

Community Alums
Not applicable

Hi @ican ,

Okay now may be below you can use below script

var r = new sn_ws.RESTMessageV2('ServiceNowMobileApp Push', 'post');
 r.setStringParameter('api_username', testapiusername);
 r.setStringParameter('api_key', testapikey);
 r.setStringParameterNoEscape('id', <Value>);
 var response = r.execute();
 var responseBody = response.getBody();
 var httpStatus = response.getStatusCode()

Please reach me out if you need anything. 

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

 

Hi @ican 

 

The query params get appended in URL like below-

 

Endpoint: www.test.com/${id}?api_username=testapiusername&api_key=testapikey

You can do this with the help of BR dynamically. I have done it for different purpose. You can use it as reference-

 

var client_id = '3**2';
        var client_secret = 'A**E';
        var grant_type = 'client_credentials';
        var token_endpoint = 'https://test.my.salesforce.com/services/oauth2/token';
        var token_grant_url = token_endpoint + "?grant_type=" + grant_type + "&client_id=" + client_id + "&client_secret=" + client_secret;

        var token_request = new sn_ws.RESTMessageV2();
        token_request.setEndpoint(token_grant_url);
        token_request.setHttpMethod("post");

        var token_response = token_request.execute();
        var response_body = token_response.getBody();
        var response_obj = JSON.parse(response_body);
        var access_token = response_obj.access_token;

        gs.info('Token request response: ' + response_body);

 

 

Please mark my answer helpful and correct.

 

Regards,

Amit