Nested Related Objects

Some entities, such as “inventory”, allow for the creation and association of some related objects within the request to create the inventory object. This allows for the creation of multiple related objects using a single API call instead of multiple requests.

The currently supported related objects are “batch_number” and “inventory_attribute”. Instead of passing in the “id” value of the related objects as the field definition’s value, you may alternatively insert a nested object representation. If the nested object does not exist, it will be created. If it does exist, no creation for that object takes place but in both cases it will be associated to the inventory object being created.

For example, when making a POST request to create an inventory object, it is valid to associate an existing batch using its “id” value:

{

“batch_number_id”: 1,

}

It is also possible to send a nested representation of the batch object which will functionally act as “get or create”. The nested object must still pass all of the same validations as if it were being created independently and its “id” value passed in:

{

“batch_number_id”: {

“batch_nbr”: “BATCH001”,

“item_id”: 1,

“expiry_date”: “2019-01-01”

},

}