Use increment counter in text aggregator after HTTP request

  • Trigger webhook to make HTTP request
  • Iterate an array in the returned payload for a particular value
  • Construct a text string to be used for webhook response
  • The text string needs to use a counter that starts at and increase by 1 to match the length of the array. When I use indexOf function on the key in the array, I only get the last index.

Include screenshots of

[
    {
        "statusCode": 201,
        "data": {
            "mode": "test",      
            "**shipments**": [
                {
                    "id": "XYZ0123",       
                    "tracking_code": "12345"
                },   
                  
                {
                    "id": "XYZ1234",
                    "tracking_code": "54321",                   
                }
            ],
            "id": "order_019eeeeeeeeeeeeeee",
            "object": "Order"
        },
        "fileSize": 123
    }
]

I want to construct the following text string:

{    
    "packages":[
    {
        "name": "Package 1",        
        "tracking_url": "https://mycarrier.com/12345"
    },
   {
       "name": "Package 2",       
       "tracking_url": "https://mycarrier.com/54321"
    }
  ]
}

The name field should be Package 1, Package 2, Package 3 depending on how many objects are in the “shipments” array from HTTP request output. In the iterator, I’m using

        "name": "Package indexOf(*140.Data.shipments[].id*:1)"     
      

It returns 9 instead 1 and 2.

How should I get the counter?

You can use the Increment Function module to retrieve the counter value. The counter value will be reset after one run. Could you please share the blueprint of the scenario so that I can understand what kind of data you are using in the text aggregator?

3 Likes

This worked perfectly, thank you @RBalani

3 Likes

If you’re already using an Iterator module, why can’t you just use the “Bundle order position” variable??

2 Likes

This works and eliminates 1 step, thank you! @samliew

2 Likes