Execute REST Connector Calls in Events

Executing a REST call in an event enables you to store the call’s response and use it in an event action or condition.

Examples

  • Configure a web form that prompts users to enter a zip code. Add an event that calls a weather site to query weather values. Store the response data, then add actions to the event that display temperature-related values.

  • Configure a web form that prompts users to enter a company name and click a Get Quote button. Add an event to the button that calls a stock service site to query stock values for the specified company. Store the response data, then add event actions that display read only stock value fields.

    Description of connector-call-example.png follows
    Description of the illustration connector-call-example.png

Before configuring a REST connector call, create the REST connector you want the event to call. See Configure REST Connectors in Designer.
To add and configure the connector call:
  1. In the web form editor, select a control, add an event, and select its type.
    For example, include an On Change event for a text input control or an On Click event for a button control. See Configure Events.
  2. Click the event’s Edit icon to display the Events window.
  3. Click +Connector to add the connector call.
  4. Configure the connector call.
    1. In the Connector field, select a REST connector from those defined for the application.
    2. In the Resource and Operation fields, select the resource to access and operation to perform as configured in the REST connection.

      Note:

      You can also perform a POST operation from the event window. Currently, for POST operations, arrays aren’t supported for requests but can be successfully received and handled in responses.
    3. Complete the connector call parameters (query, header, or body) that display based on the operation you choose. For example, the illustration below shows a connector call with a GET operation and a template parameter called message.

      You can configure query parameters either from static texts or from form expressions (as shown in the example). Use Form Expressions to specify complex values in query parameters based on functions, payload data, and control values. Get values from payload data directly without dependency on controls by using Data Definition type. Configure functions by using the Function type, for example, specify a concat function to combine two or more values.

    4. Enter a variable name in which to store the response data (for example, quoteResult or weatherInfo).
  5. Optionally, configure error handling. You can set actions to address all errors or a selected error detected in the call.
    1. Click +Error Handler to add an error handler.
    2. In the Run on Error field, select an error (or all errors) to detect.
    3. In the Control Name field, select the control on which to identify the error. In the Action field, select the control or style action to take.
  6. Collapse the connector call.
  7. Below the connector call, configure actions, conditions, or additional connectors, and click OK.
    A common use case is to add an action to display response data from the connector call. Click +Action, select a control, specify Value as its action, Connector Data as its type, and the response variable data to display in the Value field.

    Note:

    • If the connector data is an array of elements, you can specify a particular array item in the response Value field by entering the corresponding array index, for example, quoteResult[0].lastPrice[1].price.

    • If the REST response consists of a complex data object, you cannot map the data object directly into a control (such as Input Text or Text Area) through an event. Instead, you must specify which details of the complex data object should be mapped to the control, along with an appropriate function such as Concat (if required), in the event window. For example in a REST response, if a complex data object called name contains two elements, firstname and lastname, you must specify which one of these elements should be populated into the control. If you require both of these elements to be populated, use a function such as Concat with a suitable separator in the event window.