When executing a OneCloud Command that returns a JSON response, there is often the need to loop over the Response and extract information for use across the Chain. In this example, we explore iterating over a JSON response from an HTTP -> GET Request against a REST API.

Step 1: Supply a Sample JSON Response

After setting the REST API URL and any query parameters, a sample payload can be specified in the Response section. The Response instructs OneCloud how to interpret the JSON response.

Step 2: Enable Iteration

Often the need to iterate over a JSON response applies to multiple Commands and requires creating a Command Group. Once the Command Group is created, edit it to enable Iteration and assign the JSON Response from a prior Command.

Command Group Editor

Step 3: Assign the Iteration Value

In the Command that needs each unique value from the Iteration loop, insert the relevant key from the JSON array to the parameter that needs to utilize it.

The iteration value may have an asterisks which indicates that a variable transformation has been applied. In this instance, the value of the id key is being extracted and used to create the URL string that will be executed in a subsequent HTTP GET Request.

Variable Transformation

Step 4: Review the Execution Logs

The result of the iteration can be reviewed in the Outputs-Inputs-Log panel, where each value of the iteration is accessible from the drop-down, and the iteration value is displayed.

If you need additional help, please feel free to contact us at support@onecloud.io.

Did this answer your question?