In the third tutorial on flows™, we will again create a contract between a transport company and a producer of fragile goods for the transportation of said fragile goods.

This time the cargo will include multiple accelerometers to be polled upon arrival.

The contract will then again deduct an agreed-upon amount for every reading that exceeds an agreed-upon threshold.

1.Contract, Signatory & Clause

Let's start by creating a contract, adding a signatory (other than yourself), and adding the fragile-goods clause to the contract:

  • Contracts -> New Contract
  • Edit Title -> Enter Contract Title
  • Add Signatory
  • Add Clause -> fragile-goods

2. Create Trigger flow

Next, we'll create a trigger flow that, when triggered, will poll three accelerometers for their readings, and transform it, as in the first example, into a clause trigger payload using JSONata.

To simulate each of the accelerometers, we will poll this test service, which creates a single random sample meter reading every time it is queried:

We will use three HTTP steps to make a GET request each to the above url, and then use the following JSONata expression in a JSONata step to transform it into a clause payload:

    "$class": "io.clause.demo.fragileGoods.DeliveryUpdate",
    "startTime": $now(),
    "finishTime": $now(),
    "status": "ARRIVED",
    "accelerometerReadings": [
  • Edit Clause
  • Add additional trigger flow
  • Flow Name
  • Trigger Type -> HTTP
  • Add Step -> HTTP
  • HTTP input attributes
  • Trigger Type -> HTTP
  • Add Step -> HTTP
  • HTTP input attributes
  • Trigger Type -> HTTP
  • Add Step -> HTTP
  • HTTP input attributes
  • Add Step -> JSONata
  • JSONata Expression
  • Save

As before, take note of the trigger url and the authentication token in the flow dialog (viewed by editing the trigger flow)

  • Edit Flow

Trigger the flow by making an HTTP POST request to the trigger url retrieved above, with the token set as Bearer token in the Authorization header. This time, the payload is of no consequence, so we won't set one (and since we're not sending any payload, we don't need to define a Content-Type header):


This should result in a response similar to this (the amount will vary depending on the exact random meter readings generated):

  "response": {
    "$class": "io.clause.demo.fragileGoods.PayOut",
    "amount": {
      "$class": "",
      "doubleValue": 990,
      "currencyCode": "USD"
    "transactionId": "9bf0b153-99e8-42eb-b41d-f0d30f5817cb",
    "timestamp": "2019-10-21T12:13:22.567Z",
    "test": true,
    "message": "Contract 'untitled' (5dad837799b2a6001b8aa35a) has not been signed by all signatories.\nThis response should only be used for testing your API.\n\nOnce the contract has been signed by all signatories:\n- Obligations emitted by clauses will be processed\n- Clauses will maintain state between requests"

This is enough to demonstrate that the flow works. To complete this contract, you can complete all the steps from "Create Action Flow" onwards in the first tutorial.

3. Conclusion

In this tutorial we have referenced the outputs of three user-defined step in the trigger flow using step[n].output where n > 0.

Next, we will create a recurring flow which doesn't need to be triggered, but will completely by itself poll the accelerometer on a user-defined schedule.