Skip to main content

Authentication

Request

action
string
required
Must be "create_purchase".
lead_id
uuid
required
The lead to record the purchase against. Your company must have access to this lead’s channel.
product_id
uuid
A product ID from your company’s product catalog. The product must belong to your company.
purchase_amount
number
The purchase amount in the channel’s currency.
date
timestamp
The date of the purchase. Defaults to the current time if omitted.
description
string
A description of the purchase.

Response

Returns the created purchase record.
purchase
object

Side effects

  • Purchase event: An event record is created logging the purchase amount.
  • Reward triggers: If the channel has active reward triggers for purchase, reward events are calculated automatically. Fixed rewards use the trigger’s configured amount; percentage rewards are calculated from the purchase_amount.

Example

Request

curl -X POST https://amwezouylooonljdehou.supabase.co/functions/v1/openapi-operations \
  -H "Content-Type: application/json" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -d '{
    "action": "create_purchase",
    "lead_id": "99887766-5544-3322-1100-aabbccddeeff",
    "product_id": "44332211-aabb-ccdd-eeff-001122334455",
    "purchase_amount": 12500,
    "date": "2025-04-01T00:00:00.000Z",
    "description": "Annual subscription"
  }'

Response

{
  "purchase": {
    "id": "55443322-1100-aabb-ccdd-eeff00112233",
    "created_at": "2025-04-01T14:30:00.000Z",
    "leads_id": "99887766-5544-3322-1100-aabbccddeeff",
    "products_id": "44332211-aabb-ccdd-eeff-001122334455",
    "purchase_amount": 12500,
    "date": "2025-04-01T00:00:00.000Z",
    "description": "Annual subscription"
  }
}

Errors

StatusErrorCause
400"lead_id required"The lead_id field is missing.
401"Invalid API key"Missing or invalid X-Api-Key header.
403"Lead not accessible"Your company does not have access to this lead’s channel.
403"Product not found or not owned by your company"The product_id does not exist or belongs to a different company.