Send nested JSON with server-side API

OK now I understand what you mean :slight_smile:

Well it is a bit tricky. As you have to submit your form with JSON like structure.

So just create your form with all the fields you want to post.

Then name the fields as needed to contain the nesting with brackets in their name, like:

purchase_order[variant][vendor]

You can do that for every input in your form, just in the form input property inspector.

Or in code, resulting in:

Then it is very important that you replicate the same structure in the server action, so the easies way is to link the page and its form and import it:

image

Then you will see the form, with its nested structure, under $_POST

In your API Action, you can not bind the purchase-order with the define $_POST.purchase_order

Note I used underscore in the inputs name like purchase_order to avoid limiting of the names in $_POST to contain the minus sign. - but as the eventual assigning goes to the right purchase-order it should be all fine

So hope you can follow this, it is a bit complicated, but once you get it it is easy.

5 Likes