Post object with sublist or child items (array)

Hi there,

I was trying out a use case posting an invoice with invoice lines. I searched this community and based on the results I watched some tutorial videos which gave me new insights but also confused me about the best approach. So I hope someone can help.

Current approach
I have two tables

Table: invoice
Table: invoice_line (reference field: invoice_id)

Instead of using separate POST API calls for first creating an invoice and then create each invoice line separately. I would like to create a invoice with associated invoice lines in one POST.

I started modifying the original POST invoice endpoint. I tried to add an object (list) named as invoice_lines as input and configured the structure to match it with the properties of the invoice line table

But then I got stuck how to expand the function stack of this call. How can I add all the invoice_lines from the request to the invoice_line table and link it to the invoice record created in the first step in the function stack. I was now thinking to use a loop operation to iterate over the invoice_lines input array to create each invoice line.

But then I saw a video that showed that you can add a reference as a list. So besides using an reference to invoice (single item) on the invoice_line table. I could (also) use a reference to invoice_line (list) on the invoice table. But it seems redundant or sub optimal from a database perspective.

Besides that I have also read something about using add-ons for this, but I only used add-ons in a GET request to add related data to the response, but I don't understand yet how to use add-ons as input on POST requests.

Can someone please guide me to the right direction/best practice performance wise?
Working with APIs
7 replies