Sending API POST data as a repeat

Some APIs like stripe take Form POST data and others like Rezdy take JSON POST data, in both cases some of the data that can be sent is array data.
In the case of Stripe you can specify many products using their

Name Value
line_items[0][amount] {{Price}}
line_items[0][name] {{Product}}
line_items[0][quantity] {{Quantity}}

However being a form data post API, im trying to work out how to send an array as input parameters so I land up with.

Name Value
line_items[0][amount] 7
line_items[0][name] Red Widget
line_items[0][quantity] 6
line_items[1][amount] 3
line_items[1][name] Green Widget
line_items[1][quantity] 4
line_items[2][amount] 1
line_items[2][name] Blue Widget
line_items[2][quantity] 3

This type of data that can be manually input, but obviously some customers could have 1 product and others have 10, so it needs to be array type data i assume.

In my case the data comes from a multi database query just before the API POST, is there any way to send an array purely server side like this and get the above type of result?

In the case of JSON POST type APIs I manage to get a little closer but still not quite. So same question there.

Here is Rezdy, it uses POST method and takes a data type of JSON

{
"customer": {
    "firstName": "Hugo",
    "lastName": "Sterin",
    "email": "noreply@rezdy.com",
    "phone": "0282443060"
},
"items": [ 
   {
      "productCode": "PF6B25",
      "startTime": "2014-11-02T22:00:00Z",
      "amount": 200,
      "quantities": [
    {
      "optionLabel": "Adult",
      "value": "3"
    },
    {
      "optionLabel": "Child",
      "value": "1"
    },
    {
      "optionLabel": "Student",
      "value": "1"
    }
      ],
       "participants": [
    {
        "fields": [
        {
            "label": "First Name",
            "value": "Hugo"
        },
        {
            "label": "Last Name",
            "value": "Sterin"
        }
        ]
    },
    {
        "fields": [
        {
            "label": "First Name",
            "value": "Simon"
        },
        {
            "label": "Last Name",
            "value": "Lenoir"
        }
        ]
    }
      ]
   }
],
"fields": [
   {
      "label": "Do you have any dietary requirements?",
      "value": "No, I have no requirements. "
   }
],
"comments": "Special requirements go here",
"resellerComments": "Your Agent voucher/redemption code should go here",
"payments": [
    {
      "type": "CREDITCARD",
      "amount": "200",
      "currency": "USD",
      "date": "2014-11-01T10:26:00Z",
      "label": "Payment processed by RezdyDemoAgent"
    }
  ]
}

I need to use array data for the quantities, and again for the participants, which i actually thought was going to be a little simpler.

I made a multi database query of just the 2 fields needed for quantities, used the alias database method to change the names of the 2 database fields to optionLabel and value and if I use a SetValue step of {{myquery1.values()}} it returns almost exactly what I want like this in the Chrome dev tools pane.

{"optionLabel":"Adult","value":"3"},{"optionLabel":"Child","value":"1"},{"optionLabel":"Student","value":"1"}

So its already identically formatted to what the JSON expects. I add the exact same {{myquery1.values()}} inside my JSON POST API and it returns [object Object],[object Object],[object Object] instead of what the setValue step shows.

I am a little stuck now wondering how I am meant to pass array data to an API if all i have is server side data to work with.

If any of this has made sense, is it possible to do, and can someone guide me a little how.

Community Page
Last updated: