This guide shows how to sync inventory between your system and Karma, including fetching current inventory, updating items, and handling availability changes.
Overview
Inventory sync is essential for:
Keeping POS systems in sync with Karma
Managing stock levels from external inventory systems
Updating prices from your ERP
Syncing menu changes across platforms
API Endpoints
Method
Endpoint
Description
GET
/api/v1/inventory
List all inventory items
GET
/api/v1/inventory/:id
Get single item details
PUT
/api/v1/inventory/:id
Update an inventory item
POST
/api/v1/inventory/commit
Commit items to an order
Pulling Inventory (Fetch from Karma)
TypeScript Implementation
Code
import { createKarmaClient } from '@karmalicious/karma-api-js'interface InventoryItem { id: number title: string basePrice: number // in cents vatRateBasisPoints: number available: boolean categoryId: number categoryName: string variants: VariantGroup[]}interface VariantGroup { id: number name: string required: boolean options: VariantOption[]}interface VariantOption { id: number name: string priceAdjustment: number // in cents available: boolean}async function pullInventory( apiKey: string, locationId: number): Promise<InventoryItem[]> { const client = createKarmaClient({ apiKey, baseUrl: 'https://common-api.karma.life' }) const allItems: InventoryItem[] = [] let page = 1 let hasMore = true while (hasMore) { const response = await client.inventory.getInventoryItems({ locationId, includeVariants: true, includeUnavailable: true, // Include out-of-stock items page, limit: 100 }) const items = response.data.items.map(item => ({ id: item.id, title: item.title, basePrice: item.basePrice, vatRateBasisPoints: item.vatRateBasisPoints, available: item.available, categoryId: item.categoryId, categoryName: item.categoryName, variants: item.variantGroups || [] })) allItems.push(...items) hasMore = response.data.pagination.hasMore page++ } return allItems}// Example: Sync to external POSasync function syncToPOS(apiKey: string, locationId: number) { console.log('Pulling inventory from Karma...') const inventory = await pullInventory(apiKey, locationId) console.log(`Found ${inventory.length} items`) for (const item of inventory) { // Transform to your POS format const posItem = { externalId: `karma_${item.id}`, name: item.title, price: item.basePrice / 100, // Convert cents to currency taxRate: item.vatRateBasisPoints / 10000, // Convert basis points to decimal inStock: item.available, modifiers: item.variants.map(vg => ({ name: vg.name, required: vg.required, options: vg.options.map(opt => ({ name: opt.name, priceAdjustment: opt.priceAdjustment / 100, available: opt.available })) })) } // Send to your POS system await yourPOSAPI.upsertItem(posItem) } console.log('Sync complete!')}
cURL Example
Code
# Fetch all inventory itemscurl -X GET "https://common-api.karma.life/api/v1/inventory?locationId=100&includeVariants=true&limit=100" \ -H "X-API-Key: karma_live_your_api_key_here" \ -H "Content-Type: application/json"
Pushing Inventory (Update in Karma)
Update Item Availability
Code
async function updateItemAvailability( apiKey: string, locationId: number, itemId: number, available: boolean): Promise<void> { const client = createKarmaClient({ apiKey, baseUrl: 'https://common-api.karma.life' }) await client.inventory.updateInventoryItem(itemId, { locationId, available }) console.log(`Item ${itemId} availability set to ${available}`)}// Bulk availability updateasync function bulkUpdateAvailability( apiKey: string, locationId: number, updates: Array<{ itemId: number; available: boolean }>): Promise<void> { const client = createKarmaClient({ apiKey, baseUrl: 'https://common-api.karma.life' }) // Process in batches to respect rate limits const batchSize = 10 for (let i = 0; i < updates.length; i += batchSize) { const batch = updates.slice(i, i + batchSize) await Promise.all( batch.map(update => client.inventory.updateInventoryItem(update.itemId, { locationId, available: update.available }) ) ) // Small delay between batches if (i + batchSize < updates.length) { await new Promise(resolve => setTimeout(resolve, 200)) } }}