Send complex request bodies with Liquid templating (Ripple)

This tutorial shows how to use Liquid templating to send more customised JSON request bodies that combine user input with data from a Data grid component.

This example shows how to configure an app where the user can:

Batch processing app

The app uses advanced Liquid templating techniques to generate dynamic JSON structures that combine Text inputs with Data grid data.

To start:

  1. Select My Apps from the Extension Kit portal main menu.
  2. Select the Create new app button and name your app.
  3. Select the Create button.

Create an app

Configure the app layout

❗ IMPORTANT: The components and resources have dependencies between them. To configure this app, you must go from the Canvas tab to the Resources tab and the Logic flow tab frequently.

Resources

Go to the Canvas tab:

App layout

App components

Configure the Text component

In this example we configure the component as follows:

Configure the Text input components

Configure the Batch ID text input

Configure the Interface text input

Configure the Data grid component

In this example we configure the component as follows:

Go to the Resources tab:

Create the Send batch data resource

To configure the resource, follow these steps:

  1. Select the Plus (+) button on top of the left panel to create a new resource.
  2. Select the new resource on the left panel.
  3. Select the Pencil icon to change the name to 'Send batch data'
  4. Select HTTP from the Type menu on the right and configure:

    1. Configuration section:

      • URL: Enter https://postman-echo.com/post
      • Method: Select POST from the dropdown.
    2. Content definition section:

      • Body Data Type: Select JSON from drop-down.
      • Content: Delete the curly braces and copy and paste the following Liquid template JSON:

      json copy [ {% for item in dataGrid1.rows %} { "header": { "batchId": "{batchId.value}", "interface": "{interface.value}" }, "transaction": { "id": { forloop.index0 }, "invoiceNumber": "{item.invoiceNumber}", "amount": {item.amount}, "currency": "{item.currency}" } } {% if forloop.last == false %},{% endif %} {% endfor %} ]

Note: This Liquid template iterates through each row in the Data grid component: dataGrid1, and creates a JSON object for each transaction. The forloop.index0 provides a zero-based index, and the conditional comma ensures proper JSON formatting. See the understanding liquid template section for more details.

Go to the Canvas tab:

Configure the Button component

In this example we configure the component as follows:

Logic map

Finally, after configuring the components and the resource, select the Save draft button and preview your app.

Note: See the Components documentation, resources and logic drawer for more details.

Example of usage

The following example shows how the end-user of the app should use the app:

  1. Text input Configuration: The user enters in the corresponding components:

    • Batch ID: BATCH-001
    • Interface: INVOICE
  2. Data Import: The user imports an Excel file with the following content:

    • Row 1:
      • Column A: INV-100
      • Column B: 500
      • Column C: USD
    • Row 2:
      • Column A: INV-101
      • Column B: 750
      • Column C: EUR
  3. Generated Request Body: After the user selects the Send data button, the following JSON will be sent: json [ { "header": { "batchId": "BATCH-001", "interface": "INVOICE" }, "transaction": { "id": 0, "invoiceNumber": "INV-100", "amount": 500, "currency": "USD" } }, { "header": { "batchId": "BATCH-001", "interface": "INVOICE" }, "transaction": { "id": 1, "invoiceNumber": "INV-101", "amount": 750, "currency": "EUR" } } ]

Understanding Liquid template

The Liquid template used in this tutorial demonstrates several key concepts:

This approach allows for dynamic generation of complex request bodies that scale with the amount of imported data.