Step 1: Create a customer

curl -X POST https://app.kapso.ai/api/v1/customers \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "customer": {
      "name": "Acme Corporation",
      "external_customer_id": "CUS-12345"
    }
  }'
Response:
{
  "data": {
    "id": "customer-abc123",
    "name": "Acme Corporation",
    "external_customer_id": "CUS-12345"
  }
}
curl -X POST https://app.kapso.ai/api/v1/customers/customer-abc123/setup_links \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "setup_link": {
      "success_redirect_url": "https://your-app.com/success",
      "failure_redirect_url": "https://your-app.com/error"
    }
  }'
Response:
{
  "data": {
    "id": "link-xyz789",
    "url": "https://app.kapso.ai/whatsapp/setup/aBcD123...",
    "expires_at": "2024-03-15T10:00:00Z"
  }
}
Share the url with your customer. They’ll:
  1. Click the link
  2. Log in with Facebook
  3. Connect their WhatsApp
  4. Get redirected to your success URL

Step 3: Send messages

Once connected, send messages from their WhatsApp:
curl -X POST https://app.kapso.ai/api/v1/whatsapp_messages \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "customer_id": "customer-abc123",
    "message": {
      "phone_number": "+1234567890",
      "content": "Your order has been shipped!",
      "message_type": "text"
    }
  }'

JavaScript/TypeScript example

const KAPSO_API_KEY = 'YOUR_API_KEY';
const KAPSO_API_URL = 'https://app.kapso.ai/api/v1';

async function onboardCustomer(customerData) {
  // 1. Create customer
  const customer = await fetch(`${KAPSO_API_URL}/customers`, {
    method: 'POST',
    headers: {
      'X-API-Key': KAPSO_API_KEY,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ customer: customerData })
  }).then(r => r.json());

  // 2. Generate setup link
  const setupLink = await fetch(
    `${KAPSO_API_URL}/customers/${customer.data.id}/setup_links`,
    {
      method: 'POST',
      headers: { 'X-API-Key': KAPSO_API_KEY }
    }
  ).then(r => r.json());

  return setupLink.data.url;
}

async function sendMessage(customerId, phoneNumber, message) {
  return fetch(`${KAPSO_API_URL}/whatsapp_messages`, {
    method: 'POST',
    headers: {
      'X-API-Key': KAPSO_API_KEY,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      customer_id: customerId,
      message: {
        phone_number: phoneNumber,
        content: message,
        message_type: 'text'
      }
    })
  });
}

Python example

import requests

KAPSO_API_KEY = 'YOUR_API_KEY'
KAPSO_API_URL = 'https://app.kapso.ai/api/v1'

def onboard_customer(name, external_id):
    # Create customer
    customer = requests.post(
        f'{KAPSO_API_URL}/customers',
        headers={'X-API-Key': KAPSO_API_KEY},
        json={'customer': {'name': name, 'external_customer_id': external_id}}
    ).json()
    
    # Generate setup link
    setup_link = requests.post(
        f'{KAPSO_API_URL}/customers/{customer["data"]["id"]}/setup_links',
        headers={'X-API-Key': KAPSO_API_KEY}
    ).json()
    
    return setup_link['data']['url']

def send_whatsapp_message(customer_id, phone, message):
    return requests.post(
        f'{KAPSO_API_URL}/whatsapp_messages',
        headers={'X-API-Key': KAPSO_API_KEY},
        json={
            'customer_id': customer_id,
            'message': {
                'phone_number': phone,
                'content': message,
                'message_type': 'text'
            }
        }
    )

Next steps