Working with Iteration in iHub cloud

In iHub Cloud, you can use iterations to process each individual item within a payload. A payload is the data that an action receives, which can originate from a trigger or a parent action in the chain. Iterations are configured on web actions and use JSON Path syntax to specify the data to iterate over.

The payload is shown in the Payload tab of the Log.

Basic Iteration Setup

  1. Create a web action: This will be the action where the iteration will occur.

  2. Configure the action: Set the appropriate URL, method, headers, and body for your request.

  3. Enable iteration: In the advanced settings, enable the iteration option.

  4. Specify the iteration path: Use JSON Path syntax to define the part of the payload you want to iterate over.

Example:

If your payload is a list of objects with a name property, you would iterate over it like this:

{ "data": [{"name": "John"}, {"name": "Jane"}] }
$.payload.data

Special Case: Arrays

When the payload is directly an array (e.g., [obj, obj]), iHub automatically names it _values. To iterate over it, you would use:

[item1, item2]

 

Example:

If your payload is [{"name": "John"}, {"name": "Jane"}], you would iterate over it like this:

 

Iteration Context

The iteration context has access to the full scope, which includes all payloads from previous actions in the chain. This allows you to iterate over data from earlier actions or use it to construct the iteration path.

Additional Considerations

  • Dynamic iteration paths: You can use expressions or variables to construct dynamic iteration paths based on other data in the payload.

  • Nested iterations: If your payload contains nested arrays or objects, you can create nested iterations to process each level.

  • Conditional iterations: You can use conditions to control when the iteration is triggered or to skip certain items based on their values.

By effectively using iterations in iHub Cloud, you can automate repetitive tasks and process large datasets more efficiently.

Â