Wait for API response before proceeding

I wasn’t sure what title to put to make this post seem interesting. Here’s my scenario I am seeking some pointers on:

Using an API I want to post data that is structured as

  • Package 1 (package ID 1)
    ** Item 1 (Item ID 1)
    ** Item 2 (Item ID 2)

  • Package 2 (package ID 2)
    ** Item 3 (Item ID 3)
    ** Item 4 (Item ID 4)

Basically I have to submit the packages to the API then receive the Package ID generated, then submit the items, with the correct package ID.

I hope that makes sense.

I know how to submit the package and receive the package ID back, but I want to user to be able to create the packages and Items in the user interface all at once, then have a workflow post the packages and then the items behind the scenes.

Has anybody had to do something like this?