Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Insert excerpt
_Banners
_Banners
nameactionflow
nopaneltrue

What is a HTTP Action?

Image Added

HTTP actions performs perform HTTP(S) requests to external APIs and returns return the response.

A HTTP action has two outputs. One input request will generate one output record, which will be sent on either the out or error output. A HTTP request will be triggered for each input record and generate one output record.

The response from the server (headers and body) will be treated as the result record, with the input attributes added as passthrough fields.

  • URL: A template the computes to the URL of the request (including protocol).

  • Method:


    Expand
    titleWhat is an API?

    Iframe
    allowfullscreentrue
    srchttps://www.youtube.com/embed/-sDFQV47nDU?si=-gsTkv-OJ8ki4uLM?&rel=0&ytp-pause-overlay
    width680
    alignmiddle
    height400

    Creating HTTP Actions

    Iframe
    allowfullscreentrue
    srchttps://www.youtube.com/embed/zSu7S7vpvwE?si=FAEwf0kAkmIYirVA?&rel=0&ytp-pause-overlay
    width680
    alignmiddle
    height400

    1. Click and drag the 
      Insert excerpt
      _http
      _http
      nopaneltrue
       icon from the toolbar onto the canvas
    2. Enter a name for the HTTP action, then select Create Action
    3. In the HTTP action 
      Insert excerpt
      _property_settings
      _property_settings
      nopaneltrue
       on the right, populate the following details:
    Excerpt
    nameBasicSettings


    FieldDescriptionExample Value
    NameName given to the HTTP Node. This will be displayed on the Actionflow canvas.BankHolidays
    HTTP MethodThe HTTP method. A drop-down field containing
    [
    : GET, POST, GET or POST
    , HEAD, PUT
    , DELETE,
    other]. If other is specified a text box will allow entering of custom, none empty, uppercase letters only.
  • Headers: A table of name, value pairs. The name will be treated as a case insensitive string, the value will be treated as a template expression. Duplicate names are permitted and should result in each value being sent in the request.

  • Body: An optional template expression. If this evaluates to only whitespace then it is not include in the request

  • Error expression: An optional
    OPTIONS, PUT, PATCH.Get
    URL Template

    A template that computes the URL of the request.

    If using the URL to pass across parameters, care should be taken to ensure that the values are appropriately URL encoded.  

    https://www.gov.uk/bank-holidays.json


    https://server/phixflow/api/1/action/App/Api/trigger?field=abc

    Body Template

    Optional.

    If this is provided then it is used to carry the HTTP request data. If a body is provided then usually Content-Type and Content-Length headers lines specify the nature of the body associated.

    In PhixFlow if this evaluates to whitespace only then it is not included in the request.

    The body expects literal values, or expressions encapsulated within ${} syntax, for example ${in.MyValue}.

    //JSON Example
    {
        "Industry": "${in.Industry}"
    }
    Error Expression

    Optional.

    A JEP expression to determine if the response is an error and if so

    sent

    , send on the

    error output.

    An Output Attributes section will be available on the http action editor. This will work the same way as the calculate and extractor nodes operation.

    The attribute

    Error Output Connection Point. The expression will have access to the input record (in) and

    an

    the mapped output response (_result

    record

    ).

    The result record will be structured equivalently to the following JSON document (there is no requirement to actually generate a JSON string to produce the document, just conceptually this is what the string would look like and JEP should operate as if it had come from the equivalent string.

    • Result fields

      • body: the response body as a string (string)

      • url: the url the request was sent to (string)

      • status: the returned status code as an in (getCode()) (int)

      • status message: the returns status message (getReasonPhase()) (string)

      • status family: the returned status code family (100, 200, 300, 400, 500) (int)

      • error: true if internalError is true, or the error expression (or default expression) returned true (TrueFalse)

      • transmissionError: true if the error was generated internally by PhixFlow (e.g. a pseudo response for connection timed out etc) (TrueFalse)

      • headers: a map of header names → array of values ( headerName : [value1, value2]} (Structured Data)

    The output attributes will default to have:

    • status: _result.status

    • status_message : _result.status_message

    • contentType: _result.headers.”Content-Type”

    • body _ result.body

    Worked Example

    Here is a worked example using the Shop
    _result.isError
    Log Traffic

    Toggle on 

    Insert excerpt
    _toggle_on
    _toggle_on
    nopaneltrue
    to log the response of the HTTP request in the System Console, e.g. see an error returned, or see the output before specifying a path.

    Use this when testing but switch off once testing is completed.

    Insert excerpt
    _toggle_on
    _toggle_on
    nopaneltrue
    Maximum HTTP Log Length

    Available if Log Traffic is toggled on 

    Insert excerpt
    _toggle_on
    _toggle_on
    nopaneltrue
    .

    Restricts the size of the log traffic.

    1000
    Use Raw URL

    Toggle on 

    Insert excerpt
    _toggle_on
    _toggle_on
    nopaneltrue
     to send the URL Template value in exactly the format it is provided to the HTTP Node.

    If toggled off 

    Insert excerpt
    _toggle_off
    _toggle_off
    nopaneltrue
    PhixFlow will transpose values to form a valid URL, such as replacing spaces with %20.

    Insert excerpt
    _toggle_on
    _toggle_on
    nopaneltrue
    HTTP ConfigurationSee HTTP Configuration


    4. 

    Insert excerpt
    _finish
    _finish
    nopaneltrue
     all settings

    5. Hover over the 

    Insert excerpt
    _http
    _http
    nopaneltrue
     action on the canvas to see the output connection points

    Output Connection Points

    A HTTP action has two outputs. A HTTP request will be triggered for each input record and generate one output record, which will be sent on either the out or error output. 

    The response from the server (headers and body) will be treated as the result record.

    Output Connection PointDescription
    OutContains the resulting record of the request. 
    ErrorContains the resulting record of the request where it satisfies the error expression specified on the HTTP Node. 

    The output records contain the attributes specified by the output connection point. Successful records are passed down the out connection point and records containing an error are passed down the error connection point. The structure of the records by default are as follows:

    Excerpt
    nameOutputAttributes
    • body: The content returned by a successful request, for example, JSON content

    • contentType: The type of response provided by the target HTTP request, for example, application/json; charset=utf-8
    • status: The returned status code, for example, 200
    • statusMessage: The returned status message, for example, OK
    • cookies: Returns an array of cookie name, domain, etc.
    • isError: Returns true if the response contains a 400+ error code
    • headers: Returns an array of header values
    • statusFamily: Returns the status family code, for example if status returns 202, then statusFamily will return 200
    • transmissionError: Returns true if the request failed, e.g. timed out

    Image Added



    Excerpt
    nameParameters

    Parameters

    Insert excerpt
    _http_parameter
    _http_parameter
    nopaneltrue
    s are used to transmit values within a URL. They are automatically added to the end of the URL the HTTP action is calling, with the format: ?param1Name=param1Value&param2Name=param2Value

    • The Parameter values are automatically encoded into a format suitable for passing via a URL
    • Refer to attributes mapped into the HTTP action using the syntax: ${ConnectorName.AttributeName} in the Expression
    • The parameter names must match those set on the API
      • See below example where an Actionflow HTTP action is calling a PhixFlow API Endpoint
    Section


    Column

    Insert excerpt
    _http
    _http
    nopaneltrue
     Action

    Image Added


    Column

    Insert excerpt
    _actionflow_api_endpoint
    _actionflow_api_endpoint
    nametext
    nopaneltrue
     Input Parameters

    Image Added



    Note

    If a “timeout” parameter is required, this can be set on the HTTP action but is not needed as an Input Parameter on the API Endpoint. This is because it is a reserved value. See API Endpoint Properties and Setting up an API Endpoint.

    Headers

    Headers are typically used to specify information for the request, such as character sets, session tokens or passwords. Headers can reference Secret Key Details, see below, using the syntax ${_datasource.SecretKey}

    For example,

    • Name: Authorization
    • Expression: ${_datasource.MyKey}


    Tip

    When sending an authorisation header to a PhixFlow API Endpoint, the Name must be Authorization. See Setting up an API Endpoint.


    Secret Key Details

    Secret Keys allow sensitive data, such as passwords or security tokens, to be encrypted and stored in the PhixFlow Database. See Secret Key and Local Secret.

    Image Added

    Running HTTP Actions

    Individual

    Insert excerpt
    _http
    _http
    nopaneltrue
    action nodes can be run in isolation from the rest of the Actionflow, using the
    Insert excerpt
    _run_action
    _run_action
    nopaneltrue
    option, found under the
    Insert excerpt
    _more_options
    _more_options
    nopaneltrue
    menu on the HTTP action's Properties. See Running Actions and Actionflows.

    HTML Comment
    hiddentrue

    Insert excerpt
    HTTP Node
    HTTP Node
    nopaneltrue

    Worked Example

    Excerpt
    nameExample

    Here is a worked example using the Retail Data (available from the Learning Centre) and JSON data from the UK government website (https://www.gov.uk/bank-holidays.json).

    In this example, we are using:  

    • Shop Shipping screen containing a grid of Orders data, a grid of Order Lines data, an area containing a Date form field and buttons  - this screen was created using the Multi-Tile template
    • A Shop Shipping Popup screen containing a grid of the bank holiday data  - this screen was created using the Tile no Buttons template
    Tip

    If you are completing this chapter as part of the Actionflow course and using a training instance, the data and screens have already been pre-loaded into the Actionflow Intermediate Application. For these example, we'll be working on the Search button on the Shop Shipping screen, and the Shop Shipping Popup screen.

     
    GIF/SCREENSHOT OF FINISHED RESULT 

     

    Identify Bank Holiday Dates

    In this example, we'll create an Actionflow that

    checks if a new customer's name matches any existing customers, then shows this information in a pop up.

    Example

    Bank Holidays

    retrieves bank holiday dates in the UK from the government website in JSON format and map this onto a screen in a grid. 

    Image Added

    HTML Comment
    hiddentrue

    Select shipment date date field (date picker), then press Ship Date which changes the status of the order and order lines to completed.
    Area underneath showing upcoming bank holidays

    Shop Shipping Screen

    Shop Shipping Popup Screen

    Table Setup

    1. Create a new
      Insert excerpt
      _tables
      _tables
      nopaneltrue
       on your
      Insert excerpt
      _erd
      _erd
      nopaneltrue
       to save the bank holiday data to, and ensure it contains the following attributes:
      1. Name: UID
        1. Type: String
        2. Length: 50
        3. Expression: _NULL
      2. Name: Name
        1. Type: String
        2. Length: 200
        3. Expression: _NULL
      3. Name: Date
        1. Type: Date
          1. Leave the Expression field blank
      4. Name: Country
        1. Type: String
        2. Length: 50 
          1. Leave the Expression field blank
    Initial Configuration

    HTTP Action Setup

    1. On the Shop Shipping screen, add an Actionflow to the Image Modified

     button
    1.  ("GetDates")

    Add an Actionflow to the button that is triggered by the button click

    Expand
    titleHow?

    You may notice that right-clicking the button does not display the option to add an Actionflow. The Actionflow must be created using an event handler. See 2.01 Connecting Actionflows to Events.

    Open the  Insert excerpt_property_settings_property_settingsnopaneltrue for the button and click on the  Insert excerpt_property_tabs_property_tabsnameactionnopaneltrue
  • In the Action Settings section, choose an Action Method of Actionflow
  • Create a new Actionflow

    HTTP Action Setup

    Select Click to Connect and
    1. button 

    2. Select Click to Connect and choose On Click

    3. Drag a 

      Insert excerpt
      _http
      _http
      nopaneltrue
       action onto the canvas and give it a suitable name - this will be used to retrieve the bank holidays from the government JSON URL

    4. Drag the 

      Insert excerpt
      _input
      _input
      nopaneltrue
       connection point node onto the
      Insert excerpt
      _http
      _http
      nopaneltrue
       action

    5. Click on the 

      Insert excerpt
      _http
      _http
      nopaneltrue
       action to open its Properties

      1. HTTP Method: GET
      2. URL: https://www.gov.uk/bank-holidays.json
    Log Traffic:  Insert excerpt_toggle_on_toggle_onnopanel
    true
  • Maximum HTTP Log Length: 100000

    1. Drag a 
      Insert excerpt
      _action_json
      _action_json
      nopaneltrue
       action onto the canvas and give it a suitable name - this will be used to convert the JSON data into data suitable for our bank holiday table
    2. Connect the out connector from the HTTP node to the JSON node
      Click on the connector between the  Insert excerpt_http_httpnopaneltrue action and the Insert excerpt_action_json_action_jsonnopaneltrue action
      1. Map across all attributes
        1. Map across attribute, body

          Expand
          titleCheckpoint

          Image Added


      JSON Action Setup

      1. Click on the 
        Insert excerpt
        _action_json
        _action_json
        nopaneltrue
         action to open its Properties
        1. Input Expression: in.body
        2. Path: $..events
        3. Output Attributes:

          Code Block
          themeEmacs
          titleName: Country, Type: String
          _result.^.^.division


          Code Block
          themeEmacs
          titleName: Date, Type: Date
          toDate(_result.date, "yyyy-MM-dd")


          Code Block
          themeEmacs
          titleName: ID, Type: String
          toString(_result.date, "yyyyMMdd") + substring(_result.^.^.division, 1,1)


          Code Block
          themeEmacs
          titleName: Title, Type: String
          _result.title


      2. Hover over the JSON action and select out
      3. Create a
        Insert excerpt
        _action_save
        _action_save
        nopaneltrue
         action
        1. Primary Table:
      Shop
        1. The Bank Holidays

      Save Action and Open Screen Action Setup

    3. Click on the connector between the JSON action and the Save action
        1. table you created earlier
        2. Map across the JSON attributes to their relevant attributes on the Save action


          Expand
          titleHow?

          Image Modified


      1. Hover over the Save action and choose out
      2. Create an 

        Insert excerpt
        _action_screen
        _action_screen
        nopaneltrue
         action to open the Shop Shipping Popup screen

        Expand
        titleCheckpoint

        Image Added


      Screen Setup

      1. Open the Shop Shipping Popup screen
      2. Click on 
        Insert excerpt
        _attributes
        _attributes
        nopaneltrue
         in the toolbar, then select the Bank Holidays table you created earlier
      3. In the Available Attributes selector, select all attributes and drag them onto the screen, then choose to display the data as a 
        Insert excerpt
        _grid
        _grid
        nopaneltrue

      Testing

      1. Close all open screens and reopen the Shop Shipping screen
      2. Click the Image Modified button to run the Actionflow
      3. If the Actionflow is working, the Shop Shipping Popup screen should open containing all of the bank holiday data from the government website

      Background Filter and Default Sort Order

      Tidy up

      your popup

      your Shop Shipping Popup screen by

      adding a background filter

      hiding the UID column on the grid, adding a Default Filter to show only bank holidays in the future, and Default Sort Order to show the most recent bank holidays first.

      On the Shop Shipping Popup screen, configure a Background Filter on the


      Expand
      titleHow?
      1. Right-click on the grid and choose,
        Insert excerpt
      _action
      1. _view_show_config
        _view
      1. _
      action
      1. show_
      view
      1. config
        nopaneltrue
       Configuration to only show future dates 
      Expand
      titleHow?
    4. Right-click on the grid and choose, Show the View Configuration
      1. In the Data Retrieval Options section of the Properties:
        1. For Background Filter, select the 
          Insert excerpt
          _addIcon
          _addIcon
          nopaneltrue
           icon to create a new background filter
        2. Image Modified
      1.02 Actionflow Principles
        1. For Default Sort Order, select the 
          Insert excerpt
          _addIcon
          _addIcon
          nopaneltrue
           icon to create a new sort order
        2. Image Added


      Image Added