How can we help?

Transform Data action

Tal Bereznitskey
Tal Bereznitskey
  • Updated

Introduction

While working with workflows, some actions may provide data for subsequent steps that you want to transform into another form. This could be data coming from a Webhook Trigger, a Custom Action, an AI (GPT) Action or data you store in application, user or contract fields.

 

How to Use?

Start by creating a workflow in Torii from the Workflows page and add a trigger that will control when the workflow should run.

Step 1 — Add a Transform Data action

Now, add the "Transform Data" action by picking it from the list:

Step 2 — Add description (optional)

We recommend adding a short description that briefly describes what the data transformation action is supposed to do.

Step 3 — Add the Input

The input can be any valid JSON you can create. It can be simply @Trigger.Webhook-Response if you are using a webhook trigger, or build your own JSON. This is how to use the webhook response:

In this example we create an array ([]) with values from the contract

Step 4 — Add output mapping

Using the output mapping you can transform the data. This supports advanced data transformations using JMESPath.

JMESPath is a query language for working with JSON data. It is helpful when you need to extract values from arrays or nested objects. With it, you can pick specific fields from API responses, work with lists, join text, and more. To learn more about JMESPath, head over to our Advanced data transformations using JSON path queries (JMESPath) article, which walks you step by step from the basics of JMESPath to advanced concepts.
 

Example

For this Webhook Response from a Webhook Trigger:

{
  "profile": {
    "data": [
      {
        "items": 50,
        "name": "Dan"
      },
      {
        "items": 60,
        "name": "Joe"
      }
    ]
  }
}
 
You can use the following mapping to get the sum of all items (50 + 60) into a new token sumOfItems.

The above will:
  1. Extract profile.data array
  2. Pick items from each object in the data array (data[])  -> this will produce [50, 60]
  3. sum(...) the result -> this will produce 110
 
And use it in another action as a placeholder:

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request