Get your restaurant ordering system up and running with the Crave.js backend API. This guide will walk you through getting API access, creating your first location, and processing orders.

Prerequisites

  • Node.js 18.10.0 or higher (for frontend development)
  • Basic knowledge of REST APIs
  • Crave API subscription (paid plan required)

Step 1: Get API Access

Subscription Requirements

All Crave API access requires a paid subscription:
  • Storefront APIs: Available with any paid Crave subscription
  • Admin APIs: Available with Enterprise tier subscription only
  • Free trial: Contact hello@craveup.com for evaluation access

Getting Your API Key

  1. Purchase a Crave subscription or request trial access
  2. Get API keys from dashboard.craveup.com/developers
  3. Note your API base URL: https://api.cravejs.com/api/v1
The Crave API is a hosted service. You cannot run the core APIs locally - they are only available through our hosted endpoints.

Step 2: Get Your Location Information

Note: Location and menu setup is handled through the Crave merchant dashboard or by contacting hello@craveup.com for assistance.
Once your location is configured, you’ll receive:
  • Location ID: Used to identify your restaurant in API calls
  • API Key: Required for all storefront API requests
  • Location Slug: URL-friendly identifier for your restaurant
Your location information will be provided in this format:
{
  "id": "65f1a2b3c4d5e6f7a8b9c0d1",
  "name": "My Restaurant",
  "slug": "my-restaurant",
  "apiKey": "your_api_key_here",
  "status": "active"
}

Step 3: Create Your First Cart

Now use the storefront API to create a cart (what your customers will use):
Note: This uses the storefront API which requires a paid Crave subscription and your location’s API key.
curl -X POST https://api.cravejs.com/api/v1/locations/my-restaurant/carts \
  -H "X-API-Key: your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "marketplaceId": "stripe"
  }'
Response:
{
  "id": "cart_65f1a2b3c4d5e6f7a8b9c0d2",
  "locationId": "65f1a2b3c4d5e6f7a8b9c0d1",
  "items": [],
  "total": 0,
  "status": "active"
}

Step 4: Add Items to Cart

Add the burger to your cart:
curl -X POST https://api.cravejs.com/api/v1/locations/my-restaurant/carts/cart_65f1a2b3c4d5e6f7a8b9c0d2/cart-item \
  -H "X-API-Key: your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "id": "65f1a2b3c4d5e6f7a8b9c0d3",
    "quantity": 1
  }'

Step 5: Frontend Integration

Here’s how to integrate with a React frontend:
// API Configuration
const API_BASE = 'https://api.cravejs.com/api/v1';
const API_KEY = 'your_api_key_here'; // Your location's API key

// Create a new cart
const createCart = async (locationSlug) => {
  const response = await fetch(`${API_BASE}/locations/${locationSlug}/carts`, {
    method: 'POST',
    headers: {
      'X-API-Key': API_KEY,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ marketplaceId: 'stripe' })
  });
  
  if (!response.ok) {
    throw new Error('Failed to create cart');
  }
  
  return response.json();
};

// Add item to cart
const addToCart = async (locationSlug, cartId, productId, quantity = 1) => {
  const response = await fetch(`${API_BASE}/locations/${locationSlug}/carts/${cartId}/cart-item`, {
    method: 'POST',
    headers: {
      'X-API-Key': API_KEY,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ id: productId, quantity })
  });
  
  if (!response.ok) {
    throw new Error('Failed to add item to cart');
  }
  
  return response.json();
};

// Get cart contents
const getCart = async (locationSlug, cartId) => {
  const response = await fetch(`${API_BASE}/locations/${locationSlug}/carts/${cartId}`, {
    headers: {
      'X-API-Key': API_KEY
    }
  });
  
  if (!response.ok) {
    throw new Error('Failed to get cart');
  }
  
  return response.json();
};

// Get location menu
const getMenu = async (locationSlug) => {
  const response = await fetch(`${API_BASE}/locations/${locationSlug}/menus`, {
    headers: {
      'X-API-Key': API_KEY
    }
  });
  
  if (!response.ok) {
    throw new Error('Failed to get menu');
  }
  
  return response.json();
};

Next Steps

Congratulations! You’ve successfully:
  • ✅ Obtained Crave API access
  • ✅ Configured your restaurant location
  • ✅ Created and managed carts (Storefront API)
  • ✅ Integrated with a frontend application

What’s Next?

Local Development

For local development of your frontend, you can use the Crave.js React components:
# Clone the components and examples
git clone https://github.com/crave-dev/shadcn-restaurant-online-ordering-kit
cd shadcn-restaurant-online-ordering-kit

# Run the examples (includes Leclerc Bakery storefront)
npm install
npm run dev
This will start a local server at http://localhost:3000 with working examples that connect to the hosted Crave APIs.
The examples include environment configuration for connecting to the hosted Crave APIs with your API keys.

Getting Help