1. Home
  2. REST API

REST API

◷ Reading Time: 5 minutes

In Flow Call REST command allows you to call into a REST endpoint.

Build a Flow

  1. Add a new Generic Flow document
  2. Add a new parameter called orders
  3. Use the toolbox to add a REST API client

Sample Call

Get Customer Data

Select the node in the flow and set the below properties

As the above result shows, the returned object has some other information that you might not be interested in. You may want to select the list of orders only that is available in the value part of the object.

And if you set blow property, you can get the list part of it directly:

  • Results
    • Result Path: value

Set Properties

Below is a list of properties on a REST Client:

  • REST
    • Address:
      • Url: Address to the endpoint, which can include static value arguments in the URL. The Url also can have {expression} which will be resolved and evaluated against the context
      • Parameters: List of parameters that a Url might have if they are not constant static values.
  • Selector: List of Name and Result Data Field that is read from the service endpoint to create new properties map on the retrieved object.
  • Headers: List of Name and Value that REST call header.
  • Verb: Method of the call to the endpoint
  • Authorization
    • Username:
    • Password:
    • Token: To set authorization token on the service call
  • Results:
    • Multiple: Returns the result as a list, when set to true(default) otherwise a single value or object is returned
    • Result Path: Whet part (property) of a returned result should be selected.
    • Copy Value To: Sets the result of a call into the parameter specified here

Discount Decision Table

After pulling down all orders from an API call, now we can apply our rules. We need to apply 25% discounts for any orders which have greater than 40Kg Freight and Ship City is “Berlin”. Otherwise just a 10% discount needs to be applied(if the order’s Fright is greater than 40 and the order’s ShipCity is Berlin, then apply 25%. Otherwise apply 10%).

Generate Bearer Token

The following example shows how to generate the bearer token from a project hosted in FlexRule Server.

  • Address
    • URL: <Public IP/ address/ masterAddress of the FlexRule Server>/oauth2/token
      (e.g. http://13.90.102.104:9000/oauth2/token or 
      http://frs-test.eastus.cloudapp.azure.com:9000/oauth2/token or
      http://localhost:9000/oauth2/token)
  • Headers
    Content-Type: application/x-www-form-urlencoded
  • Verb: POST
  • Content
    • Body: client_id=< client_id >&client_secret=< client_id >&grant_type=password
      (e.g. client_id=admin&client_secret=123123&grant_type=password)
  • Results
    • Copy Value To: token (token is defined as a parameter in the flow)

access token is received as follows.

It can be accessed using {token.access_token} when you want to call your project service URL.

See Execute in Postman to see how to receive the token in postman.

Download Project

Use the attachment at the end of the page to download the sample projects.

  • Get Customer Data: REST-API-DT2.zip
  • Generate Bearer Token: Get Token.zip
Updated on April 11, 2022

Article Attachments

Was this article helpful?