ServerAPI:Execution commands

From FlexRule Wiki
Jump to: navigation, search

Once you deploy your package on the FlexRule Server, you can call it from your web application through a REST API.

Testing the package in FlexRule server

After deploying the package on the FlexRule Server, you should first ensure that it runs successfully.

EC server testrun.png

Service URL

After a 'Test Run', Service URL will be shown at the beginning of the Test Run page. This is the URL you should use in your application to call the deployed package.

EC service url.png

http://{your server address}/api/services/execute/{package name}/{package version}/{service name}

The URL is based on the following sections:

  • {package name}: This is the identifier of the package that is stored on the server
  • {package version}: The version string (e.g., number, string, etc.) that is stored for a package
  • {service name}: Name of the decision inside a package


http://localhost:9000/api/services/execute/agepackage/1/person growing state

You can view and edit those sections under Info of the Test Run page

EC server info.png

Testing the URL in an API development environment

It requires an API development environment to test the API. In this example, Postman was used.


The request should have the following properties:

  • Method
  • Service URL
  • Authorization (Type, Token)
  • Body (Input text/ object, Content-Type)
  • Header (Authorization, Content-Type)

Now let's discuss these in detail.

'Method:' POST

'Service URL:' <Working Service Url of the package>

The token is taken from the Test Run result of the FlexRule Server workbench.


  • Type: 'Bearer Token'
  • Token: <Access Token>

EC pm auth.png

'Body:' <Your input JSON object>

EC pm body.png

Inputs are a set of name-value pairs. Name is the name of the parameter, and Value is the value of the parameter. Inputs must be provided in a name/value format as the above Request specification indicates.

  "inputs": [
              "name": "person",
              "value": {


  • Authorization: <Type and Token> (This will be autofilled in Postman, after adding Authorization Type and Token)
  • Content-Type: application/json (This will be autofilled in Postman, after adding Body by selecting JSON (application/json))

EC pm headers.png


Once you send the Request, the Response can be seen as follows:

EC pm output.png

Asynchronous Method

FlexRule Server v3 supports long-running execution of a task using the Asynchronous method. You just need to add ?async=true to the service Url and follow the steps below:

  1. Get the Authorization Token
  2. Call the service endpoint with ?async=true in the Url. When the call is async, the server will return code 202 (Accepted) which means the task is created to process the client request.
  3. Follow the Location service provided in order to retrieve the result once it is ready. If the result is not yet ready, the service will return a 503 (Service Unavailable) code, which means you need to try later, until you retrieve the result.


Let's deploy some logic as a service and then start calling it.

In the first step, we call the service with ?async=true:

http://localhost:9000/api/services/execute/agepackage/1/person growing state?async=true

As a result, the location indicating where the result can be retrieved is returned. Please note the result code is 202, rather than 200 for a normal call.

Now we can post a request to the location and retrieve the result:

EC pm asy.png


Below is the package you can Upload to service and test.