Added support for nested fields
Ticket: COMMERCE-2270
What Changed?
The Products, Accounts, Orders, Warehouses entities now support nested fields, which means that requests to the GET endpoints of these entities will return just the root object, instead of the root object and the nested entities.
For example the endpoint
../o/headless-commerce-admin-inventory/v1.0/warehouses/
would have previously produced a response like this:
{ "items": [ { "active": true, "city": "Borgorose", "countryISOCode": "IT", "externalReferenceCode": "380RI2021", "id": 36504, "latitude": 42.214601, "longitude": 12.796434, "name": "Italy", "regionISOCode": "RI", "street1": "Via delle Coste 24", "zip": "2021", "items": [ { "id": 36527, "quantity": 20, "reservedQuantity": 0, "sku": "MIN93015", "warehouseExternalReferenceCode": "380RI2021", "warehouseId": 36504 }, { "id": 36551, "quantity": 100, "reservedQuantity": 0, "sku": "MIN93016A", "warehouseExternalReferenceCode": "380RI2021", "warehouseId": 36504 } ] } ] }
Starting with Commerce 2.0.7, a response like this will now be produced:
{ "items": [ { "active": true, "city": "Borgorose", "countryISOCode": "IT", "externalReferenceCode": "380RI2021", "id": 36504, "latitude": 42.214601, "longitude": 12.796434, "name": "Italy", "regionISOCode": "RI", "street1": "Via delle Coste 24", "zip": "2021" } ] }
It is also now possible to make the endpoint load the nested fields with the query parameter nestedFields valorized with the name of the desired nested property.
For example the endpoint
../o/headless-commerce-admin-inventory/v1.0/warehouses/?nestedFields=items
will produce a response like this:
{ "items": [ { "active": true, "city": "Borgorose", "countryISOCode": "IT", "externalReferenceCode": "380RI2021", "id": 36504, "latitude": 42.214601, "longitude": 12.796434, "name": "Italy", "regionISOCode": "RI", "street1": "Via delle Coste 24", "zip": "2021", "items": [ { "id": 36527, "quantity": 20, "reservedQuantity": 0, "sku": "MIN93015", "warehouseExternalReferenceCode": "380RI2021", "warehouseId": 36504 }, { "id": 36551, "quantity": 100, "reservedQuantity": 0, "sku": "MIN93016A", "warehouseExternalReferenceCode": "380RI2021", "warehouseId": 36504 } ] } ] }
Finally it is also possible to request a list of desired nested properties to be loaded within the same request.
For example a request like this will now load both images and categories for the products:
../o/headless-commerce-admin-catalog/v1.0/products/?nestedFields=images,categories
Which properties are affected?
The following are the supported nested properties for each entity that supports this mechanism.
- Product: [attachments, images, categories, configuration, productOptions, shippingConfiguration, productSpecifications, subscriptionConfiguration, taxConfiguration, relatedProducts, skus]
- Account: [addresses, users, organizations]
- Order: [items, shippingAddress]
- Warehouse: [items]