POST /api/v1/inventory/items/batch • HTTP 200 OK
Batch Bulk Operations API Example — Request & Response Example
Shows how enterprise APIs handle bulk imports: sending an array of items in one request and receiving itemized success and failure statuses.
1. HTTP Client Request (POST)
POST /api/v1/inventory/items/batch HTTP/1.1
{
"Content-Type": "application/json"
}
{
"items": [
{
"sku": "SKU-001",
"name": "USB-C Cable 2M",
"quantity": 50
},
{
"sku": "SKU-002",
"name": "65W GaN Charger",
"quantity": 25
},
{
"sku": "SKU-003",
"name": "HDMI 2.1 Braided Cable",
"quantity": 80
}
]
}
2. Server JSON Response (HTTP 200 OK)
{
"total_processed": 3,
"successful": 3,
"failed": 0,
"created_records": [
{
"id": "inv-101",
"sku": "SKU-001",
"status": "created"
},
{
"id": "inv-102",
"sku": "SKU-002",
"status": "created"
},
{
"id": "inv-103",
"sku": "SKU-003",
"status": "created"
}
]
}
Copy-Paste Code Snippets (cURL, JavaScript Fetch, Python, Node.js)
curl -X POST "https://cometflow.space/api/v1/inventory/items/batch" \
-H "Content-Type: application/json" \
-d '{"items": [{"sku": "SKU-001", "quantity": 50}, {"sku": "SKU-002", "quantity": 25}]}'
fetch('https://cometflow.space/api/v1/inventory/items/batch', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
items: [
{ sku: 'SKU-001', quantity: 50 },
{ sku: 'SKU-002', quantity: 25 }
]
})
}).then(res => res.json()).then(console.log);
import requests
payload = {"items": [{"sku": "SKU-001", "quantity": 50}]}
res = requests.post("https://cometflow.space/api/v1/inventory/items/batch", json=payload)
print(res.json())
How This API Call Works Step-by-Step
- 1. Client submits an array of objects in JSON body.
- 2. Server opens a database transaction.
- 3. All rows are inserted or rolled back on failure.
- 4. Server summarizes count and returns individual IDs.
Backend API Functions: The API function batchInsertInventory(req, res) uses database bulk insert (e.g. INSERT INTO ... VALUES (...), (...)) within a transaction.
Frequently Asked Questions
What is the maximum limit for a batch API request?
Most production APIs limit bulk endpoints to between 50 and 500 items per request to prevent timeouts and database lock contention.