Child pages
  • Invoking REST Services Example Flow Chart
Skip to end of metadata
Go to start of metadata

Invoking REST Services Example Flow Chart

This example illustrates how to invoke a REST service on a remote system using Flux. The Rest Action has only one required property: baseURL, which specifies the location of the HTTP service to invoke. Arguments can be passed to the REST service and the REST service can also return values which can be used in the flow chart.


To run a REST action, drag it onto the canvas and double click the action to open its dialog.

Below is an example of a populated REST Action that hits one of Flux's REST API endpoints:



The dropdown menu provides Predefined REST Hosts. These will automatically populate the fields of the dialog when selected. You can test and save REST sources by accessing the REST Source Tester page by clicking the "Test REST Call Sources" button in the upper right of the dialog. Flux also imports SWAGGER API REST endpoints, this can be accessed by clicking the "Import REST Call Sources" button in the upper right of the dialog.


Required fields for a REST Action to execute are: Action Type, Base URL, Request Content Type and Response Type.

When a REST Action is executed, data is returned and is stored in the RESULT object within the flow context, just like other Flux actions.

This RESULT object can be accessed by using the "${}" syntax to substitute the value into whichever field. This can be seen below as this Console Action is using the RESULT from the previous REST Action:



The endpoint returns a list of flowcharts in the repository, which is then outputted to stdout by the Console Action and will look like this:


RESULT.result
{
	"count": "30",
	"matched": "42",
	"repositoryElement": [{
		"creationTimestamp": "2020-03-20T11:11:30.940-06:00",
		"creationTimestampFormatted": "20 Mar 2020 @ 11:11:30 MDT-0600",
		"description": "**Not Verified**",
		"id": "252",
		"isOnEngine": "false",
		"lastModifiedTimestamp": "2020-03-20T11:11:30.940-06:00",
		"lastModifiedTimestampFormatted": "20 Mar 2020 @ 11:11:30 MDT-0600",
		"namespace": "/222",
		"owner": "admin"
	}, {
		"creationTimestamp": "2020-03-19T14:14:43.729-06:00",
		"creationTimestampFormatted": "19 Mar 2020 @ 14:14:43 MDT-0600",
		"id": "250",
		"isOnEngine": "false",
		"lastModifiedTimestamp": "2020-03-19T14:20:04.861-06:00",
		"lastModifiedTimestampFormatted": "19 Mar 2020 @ 14:20:04 MDT-0600",
		"namespace": "/ATPDaily/1001934Daily",
		"owner": "admin"
	}]
}


Parsing Technique for JSON Result from REST Actions

REST endpoints often return data in a JSON format. It is very common for users of Flux to need to parse the returned data. Here is a simple example of how a postscript can be used to utilize a JSON library for pulling out certain fields from a REST Action RESULT:


postscript
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

String result = flowContext.get("result").result;

JSONParser jsonParser=new JSONParser();

Object object = jsonParser.parse(result);

JSONObject jsonObj =  (JSONObject) object;
JSONArray elements = (JSONArray) jsonObj.get("repositoryElement");
Iterator itr = elements.iterator();
while(itr.hasNext()) {
    System.out.println(itr.next());
    System.out.println(" ------------------------------- ");
}


Output from the postscript:

output
{"owner":"admin","lastModifiedTimestampFormatted":"20 Mar 2020 @ 11:11:30 MDT-0600","creationTimestampFormatted":"20 Mar 2020 @ 11:11:30 MDT-0600","creationTimestamp":"2020-03-20T11:11:30.940-06:00","namespace":"\/222","description":"**Not Verified**","id":"252","lastModifiedTimestamp":"2020-03-20T11:11:30.940-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"19 Mar 2020 @ 14:20:04 MDT-0600","creationTimestampFormatted":"19 Mar 2020 @ 14:14:43 MDT-0600","creationTimestamp":"2020-03-19T14:14:43.729-06:00","namespace":"\/ATPDaily\/1001934Daily","id":"250","lastModifiedTimestamp":"2020-03-19T14:20:04.861-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:50 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:50 MDT-0600","creationTimestamp":"2020-03-10T09:18:50.029-06:00","namespace":"\/Demo\/Audit Start of Run","description":"Listen for \/Demo\/Console Action Hello World to start.","id":"238","lastModifiedTimestamp":"2020-03-10T09:18:50.029-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.982-06:00","namespace":"\/Demo\/Audit Trail Trigger Initiating Event","description":"Execute an action for an audit trail trigger to detect","id":"233","lastModifiedTimestamp":"2020-03-10T09:18:49.982-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.982-06:00","namespace":"\/Demo\/Audit Trail Trigger Listener to Initiating Event","description":"Listen for initiating event in another workflow.","id":"234","lastModifiedTimestamp":"2020-03-10T09:18:49.982-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.980-06:00","namespace":"\/Demo\/Audit Trail Trigger Listener to Next Event","description":"Audit trail trigger listening to the next event in a chain of events.","id":"232","lastModifiedTimestamp":"2020-03-10T09:18:49.980-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:50 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:50 MDT-0600","creationTimestamp":"2020-03-10T09:18:50.029-06:00","namespace":"\/Demo\/Console Hello World","description":"**Not Verified**","id":"239","lastModifiedTimestamp":"2020-03-10T09:18:50.029-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:50 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:50 MDT-0600","creationTimestamp":"2020-03-10T09:18:50.028-06:00","namespace":"\/Demo\/Create Business Calendars excluding weekends and Federal Holidays","id":"237","lastModifiedTimestamp":"2020-03-10T09:18:50.028-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:50 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:50 MDT-0600","creationTimestamp":"2020-03-10T09:18:50.014-06:00","namespace":"\/Demo\/Create Simple Process Action Workflow With Form","description":"**Not Verified**","id":"235","lastModifiedTimestamp":"2020-03-10T09:18:50.014-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:50 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:50 MDT-0600","creationTimestamp":"2020-03-10T09:18:50.071-06:00","namespace":"\/Demo\/Database Condition","description":"Query Flux Ready Table","id":"240","lastModifiedTimestamp":"2020-03-10T09:18:50.071-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:50 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:50 MDT-0600","creationTimestamp":"2020-03-10T09:18:50.014-06:00","namespace":"\/Demo\/Deadline Test","description":"Demo a Deadline within 1 minute","id":"236","lastModifiedTimestamp":"2020-03-10T09:18:50.014-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.961-06:00","namespace":"\/Demo\/Divide By Zero","description":"**Not Verified**","id":"231","lastModifiedTimestamp":"2020-03-10T09:18:49.961-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.956-06:00","namespace":"\/Demo\/Embedded Form Request","description":"Embedded Form","id":"229","lastModifiedTimestamp":"2020-03-10T09:18:49.956-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.896-06:00","namespace":"\/Demo\/Error Handler calling Remove","description":"Error Handler to Restart Failed Workflow","id":"225","lastModifiedTimestamp":"2020-03-10T09:18:49.896-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.914-06:00","namespace":"\/Demo\/FECEA with Datamap for File Move","description":"Test for existence then move files from SFTP Server","id":"228","lastModifiedTimestamp":"2020-03-10T09:18:49.914-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.908-06:00","namespace":"\/Demo\/File Copy using SFTP","id":"226","lastModifiedTimestamp":"2020-03-10T09:18:49.908-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.880-06:00","namespace":"\/Demo\/File Exist to FECEA to List File Names","description":"**Not Verified**","id":"224","lastModifiedTimestamp":"2020-03-10T09:18:49.880-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.910-06:00","namespace":"\/Demo\/Java Action","description":"Demonstrate calling a Java Action","id":"227","lastModifiedTimestamp":"2020-03-10T09:18:49.910-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.957-06:00","namespace":"\/Demo\/MFT Example","id":"230","lastModifiedTimestamp":"2020-03-10T09:18:49.957-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.703-06:00","namespace":"\/Demo\/Mail Action","description":"Example Mail Action","id":"210","lastModifiedTimestamp":"2020-03-10T09:18:49.703-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.839-06:00","namespace":"\/Demo\/Process Action with Simulated Tail","description":"Print Last 800 Characters of stdout","id":"222","lastModifiedTimestamp":"2020-03-10T09:18:49.839-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.844-06:00","namespace":"\/Demo\/Provision Timed Command","description":"Provision a Timed Command","id":"223","lastModifiedTimestamp":"2020-03-10T09:18:49.844-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.806-06:00","namespace":"\/Demo\/Provision a Process Action","description":"Adhoc run an OS Command","id":"218","lastModifiedTimestamp":"2020-03-10T09:18:49.806-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.814-06:00","namespace":"\/Demo\/REST Get Stock Quote","id":"220","lastModifiedTimestamp":"2020-03-10T09:18:49.814-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.785-06:00","namespace":"\/Demo\/Remove Completed Workflows","description":"Remove Completed Workflows using Prescript","id":"217","lastModifiedTimestamp":"2020-03-10T09:18:49.785-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.834-06:00","namespace":"\/Demo\/SFTP-File-Fetch","id":"221","lastModifiedTimestamp":"2020-03-10T09:18:49.835-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.763-06:00","namespace":"\/Demo\/SSH Upload","description":"","id":"214","lastModifiedTimestamp":"2020-03-10T09:18:49.763-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.782-06:00","namespace":"\/Demo\/SSH Upload and Download","description":"","id":"216","lastModifiedTimestamp":"2020-03-10T09:18:49.782-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.809-06:00","namespace":"\/Demo\/Show Status Message Example","description":"","id":"219","lastModifiedTimestamp":"2020-03-10T09:18:49.809-06:00","isOnEngine":"false"}
 ------------------------------- 
{"owner":"admin","lastModifiedTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestampFormatted":"10 Mar 2020 @ 09:18:49 MDT-0600","creationTimestamp":"2020-03-10T09:18:49.764-06:00","namespace":"\/Demo\/Timed Command","description":"Run a Timed Command","id":"215","lastModifiedTimestamp":"2020-03-10T09:18:49.764-06:00","isOnEngine":"false"}
 ------------------------------- 


Both examples can be downloaded here:

RESTtoConsoleAction.ffcRESTWithPostScript.ffc

Summary

The Rest Action is especially useful when integrating Flux with systems that are not Java based. You can use Flux to communicate with these systems easily using the Rest Action.

  • No labels