output text in a flow designer action.

ShraddhaMore
Tera Contributor

Hi Team,

 

Use Case:

output the data returned from following public api (no auth needed) in a flow designer action.

catfact.ninja/fact

 

Any suggestions, how to achieve this?

 

Thanks!

1 ACCEPTED SOLUTION

Carlos Petrucio
Mega Sage

Hi, hope you are well.

In Flow Designer you can have an action that does this.

 

Here is a script for your Flow Designer action that makes a call to the API https://catfact.ninja/fact, gets a fact about cats and sets the output to outputs.text:

(function execute(inputs, outputs) {
    var request = new sn_ws.RESTMessageV2();
    request.setEndpoint('https://catfact.ninja/fact');
    request.setHttpMethod('GET');
    
    var response = request.execute();
    var responseBody = response.getBody();
    var responseJson = JSON.parse(responseBody);
    
    outputs.text = responseJson.fact || 'Nenhum fato encontrado';
})(inputs, outputs);

Below I ran the code snippet in the background script to test the functionality:

CarlosPetrucio_0-1739402855663.png

 

If my answer helped you, let us know by marking it as correct and useful.

Thanks !

- Carlos Petrucio

View solution in original post

2 REPLIES 2

Carlos Petrucio
Mega Sage

Hi, hope you are well.

In Flow Designer you can have an action that does this.

 

Here is a script for your Flow Designer action that makes a call to the API https://catfact.ninja/fact, gets a fact about cats and sets the output to outputs.text:

(function execute(inputs, outputs) {
    var request = new sn_ws.RESTMessageV2();
    request.setEndpoint('https://catfact.ninja/fact');
    request.setHttpMethod('GET');
    
    var response = request.execute();
    var responseBody = response.getBody();
    var responseJson = JSON.parse(responseBody);
    
    outputs.text = responseJson.fact || 'Nenhum fato encontrado';
})(inputs, outputs);

Below I ran the code snippet in the background script to test the functionality:

CarlosPetrucio_0-1739402855663.png

 

If my answer helped you, let us know by marking it as correct and useful.

Thanks !

- Carlos Petrucio

Ankur Bawiskar
Tera Patron

@ShraddhaMore 

so what did you configure so far and what's not working?

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