Built-in Modules > enrichLocationDetails Function
enrichLocationDetails Function
Overview
The enrichLocationDetails function is an asynchronous utility that enriches each cart item with Shopify inventory location data.
It augments items in DATA.items by attaching a normalized inventoryItem object containing inventory levels per Shopify location. The function returns the same DATA object after enrichment.
Function Signature
async function enrichLocationDetails(DATA, size = 15)
Arguments
DATA (Object)
The standard JsRates DATA object provided to calculateShippingRates.
Required structure:
{
"items": [
{
"variant_id": "number|string"
}
]
}
DATA.itemsmust exist- Each item must include
variant_id - All other item fields are preserved
size (Number, optional)
Specifies how many inventory location records are retrieved per item.
- Default:
15 - Minimum:
1 - Maximum: subject to Shopify API limits
Usage Example
import { enrichLocationDetails } from "./modules.js";
export async function calculateShippingRates(DATA) {
DATA = await enrichLocationDetails(DATA);
// inventory location data is now available on each item
}
Output
The function returns the same DATA object with additional inventory data attached to each item.
Item-Level Output
Each entry in DATA.items is enriched with the following field:
item.inventoryItem
inventoryItem Structure
{
"inventoryItem": {
"id": "string",
"unitCost": {
"amount": "string",
"currencyCode": "string"
},
"locationsCount": {
"count": "number"
},
"inventoryLevels": [
{
"location": {
"id": "string",
"name": "string",
"isActive": "boolean",
"addressVerified": "boolean",
"address": {
"address1": "string|null",
"address2": "string|null",
"city": "string|null",
"zip": "string|null",
"province": "string|null",
"country": "string|null",
"latitude": "number|null",
"longitude": "number|null"
}
},
"quantity": "number"
}
]
}
}
Error Handling
If inventory location data cannot be retrieved, the function does not throw an error.
The original DATA object is still returned and can continue to be used.
Notes
enrichLocationDetailsperforms data enrichment only- It does not select a fulfillment location
- It does not calculate shipping costs
- Ordering of
inventoryLevelsis not guaranteed - Consumers must explicitly implement any location selection or business logic
