Rest Message (POST outbound api) from workflow

Dashing
Tera Contributor

Hello ,

I am looking to call Rest Message (outbound api) from workflow,i want to use Run Script  and pass user from catalog item to the rest message in query parameter.

Actually i am looking to use POST rest message api and pass parameter from workflow or if you have any  any other simple solution would be welcome.

am using workflow because i have some condition like sending notification after success(200) message or update ritm if not successful.

i saw some suggestions like using only client script calling  script include but i am not sure how it would work for other conditions like sending notification because i am good at coding if its possible let me know i am looking for urgent solution.

Thanks in advance.

1 ACCEPTED SOLUTION

Vikram Reddy
Giga Guru

Hi Dashing,

 

The best practice is to use Run script activity to achieve this

 

Step 1: create a script include to initiate POST rest call and return the response 

Step 2: create a run script activity in catalog item workflow, call the created script include

something like this by passing your current object, so that you can access and send variable values in the payload

var a = new scriptinclude().integration(current);

step 3: In the same run script activity, Write validations for returned value from script include stored in var a

something like

if (a == 200){

activity.result = 'success', //configure the output in conditions

current.work_notes = 'success';

}

if(a == 400){

activity.result = 'failure';

current.work_notes = 'failed';

}

 

Please mark helpful/correct if this helped

 

Thank you,

Vikram

View solution in original post

7 REPLIES 7

Vikram Reddy
Giga Guru

Hi Dashing,

 

The best practice is to use Run script activity to achieve this

 

Step 1: create a script include to initiate POST rest call and return the response 

Step 2: create a run script activity in catalog item workflow, call the created script include

something like this by passing your current object, so that you can access and send variable values in the payload

var a = new scriptinclude().integration(current);

step 3: In the same run script activity, Write validations for returned value from script include stored in var a

something like

if (a == 200){

activity.result = 'success', //configure the output in conditions

current.work_notes = 'success';

}

if(a == 400){

activity.result = 'failure';

current.work_notes = 'failed';

}

 

Please mark helpful/correct if this helped

 

Thank you,

Vikram

Good explanation but i have a question why we need to call through script include?because if we are calling directly  "Rest Message" from run script and we pass variable in function.

 

My Workflow Run Script code:

try {
var r = new sn_ws.RESTMessageV2('REST API', 'Addmyfunction');

//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);

//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');

//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);

var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}

 

Thanks fie good suggestion but i have a question why we need to call script include?

could we directly call Rest Message from Run Script and pass variable?

 

This is my Run Script:

try {
var r = new sn_ws.RESTMessageV2('REST API', 'Addfuntiion');

//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);

//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');

//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);

var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;

Thanks

Hi Vikram, That is a very good solution, I just want to understand where to configure the 3rd party tool recipient to which the response needs to be sent???