Using [] in a Web API post call

Hi guys,

I want to make post call with the following body:

[{“business”:{“businessName”:“test test B.V.”,“registrationNumber”:“12345678”,“country”:“Netherlands”}}]

The problem is I cant use [ x ]. Without this in the body the call wont work.

Do you have a solution for this?

Hi @kenneth.seraus,

Our forum software turned your array definition into a checkbox, but I think you mean the outer array [ … ]. I have edited your post to make it clear to anyone reading it :slight_smile:

In order to have an array in your json structure, you have to have a list to begin with. For each item in the list, you can then make an object inside the array.

Concretely, this means that you could do the following. In your flow part, create a look-up action that always finds 1 single item. It doesn’t matter which item for now. The easiest way is to have the Current user given as an input, then look up a list of users with the business rule User = Input / User:

image

Once you have that list, you can now select Property from flow part in your json structure, and select the List with one user:

image

This will create an array at the top level of your structure:
image

Normally, you would do this for a Business data item in your case, and then you can create an item in the array for each business. In this case, with our list of only one user, we can simply ignore the fact the array is linked to the user and start adding some data. We then end up with what you want:

image

Pro-tip
The API you are calling supports sending multiple items, so you could decide to send multiple businesses in 1 API call by using the above method. What you’d need to do, is use a Business list as the Property from flow part. Then, for each item in the array you can specify the name of that business from the list.

Pro-tip 2
The API probably also returns an array. You’ll have to use a repeat action to store the result, since we don’t yet have functionality to get n-th item out of an array. Simply loop through the 1 result your call returns (it will be an array or list with one item) and store it in the same place ‘every time’. Since the array is only 1 item, this will only be done once.

I hope this complicated answer helps you along! :slight_smile:

2 Likes

Hi Jesse,

Thank you for the explanation and the extra tips!

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.