Understanding the fundamental concepts of the Crave Storefront API
64a7b8c9d1e2f3a4b5c6d7e8
downtown-pizza
// Example: Get location information const location = await fetch(`https://api.cravejs.com/api/v1/locations/downtown-pizza`, { headers: { 'X-API-Key': 'your_api_key' } }); // Location contains: // - Basic info (name, address, contact) // - Operating hours and timezone // - Fulfillment methods available // - Delivery radius and fees // - Ordering capabilities
// Example: Get menu with products const menu = await fetch(`https://api.cravejs.com/api/v1/locations/downtown-pizza/menus`, { headers: { 'X-API-Key': 'your_api_key' } }); // Structure: // menu.categories[] → category.products[] → product.modifiers[]
// Example: Cart lifecycle const cart = await fetch(`https://api.cravejs.com/api/v1/locations/downtown-pizza/carts`, { method: 'POST', headers: { 'X-API-Key': 'your_api_key' }, body: JSON.stringify({ marketplaceId: 'downtown-pizza', currentCartId: '' }) }); // Cart automatically calculates: // - Subtotal (sum of all items) // - Tax (based on location tax rates) // - Delivery fee (if applicable) // - Total (subtotal + tax + tip + fees)
const headers = { 'X-API-Key': 'your_api_key_here', 'Content-Type': 'application/json' };
// All endpoints follow this pattern: // https://api.cravejs.com/api/v1/locations/{locationId}/... // Examples: GET https://api.cravejs.com/api/v1/locations/downtown-pizza/menus POST https://api.cravejs.com/api/v1/locations/downtown-pizza/carts GET https://api.cravejs.com/api/v1/locations/downtown-pizza/products
// Error response format: { "error": "validation_error", "message": "Invalid location ID", "details": { "field": "locationId", "code": "invalid_format" } } // Common HTTP status codes: // 200 - Success // 400 - Bad Request (validation errors) // 401 - Unauthorized (invalid API key) // 403 - Forbidden (merchant subscription required) // 404 - Not Found // 429 - Rate limited // 500 - Internal server error
X-RateLimit-Remaining
X-RateLimit-Reset
// $12.99 is stored as 1299 const price = 1299; const displayPrice = (price / 100).toFixed(2); // "12.99"
// 1. Load location information const location = await fetchLocation(locationId); // 2. Load menu and products const menu = await fetchMenu(locationId); // 3. Create cart when customer starts ordering const cart = await createCart(locationId); // 4. Add items to cart await addItemToCart(locationId, cartId, { productId: 'prod_123', quantity: 2, modifiers: [...] }); // 5. Configure cart (delivery, tip, etc.) await setCartDelivery(locationId, cartId, deliveryAddress); await setCartTip(locationId, cartId, tipAmount); // 6. Validate cart before checkout await validateCart(locationId, cartId); // 7. Create payment intent const paymentIntent = await createPaymentIntent(locationId, cartId); // 8. Process payment with Stripe // 9. Order is created automatically via webhook