Skip to main content

Authentication

Request

action
string
required
Must be "create_purchase_custom".
lead_id
uuid
required
The lead to record the purchase against. Your company must have access to this lead’s channel.
product_name
string
A free-text product name (not linked to the product catalog).
product_description
string
A description of the product or service.
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.
trigger_ids
array of uuid
An optional list of reward trigger IDs to fire for this purchase. When provided, only these specific triggers are evaluated instead of all active purchase triggers on the channel. Each trigger must belong to the lead’s channel and have an "Active" status.

Response

Returns the created purchase record.
purchase
object

Side effects

  • Purchase event: An event record is created logging the product name and amount.
  • Reward triggers: If trigger_ids is provided, only those triggers are evaluated. Otherwise, all active purchase triggers on the channel fire. Fixed rewards use the trigger’s configured amount; percentage rewards are calculated from the purchase_amount.

Difference from create_purchase

Use create_purchase when you have a product in your Keen product catalog and want to link the purchase to it by ID. Use create_purchase_custom when you want to specify a product name as free text, or when you need to control which reward triggers fire.

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_custom",
    "lead_id": "99887766-5544-3322-1100-aabbccddeeff",
    "product_name": "Enterprise plan",
    "product_description": "12-month enterprise subscription",
    "purchase_amount": 24000,
    "trigger_ids": [
      "66778899-aabb-ccdd-eeff-001122334455"
    ]
  }'

Response

{
  "purchase": {
    "id": "55443322-1100-aabb-ccdd-eeff00112233",
    "created_at": "2025-04-01T14:35:00.000Z",
    "leads_id": "99887766-5544-3322-1100-aabbccddeeff",
    "name": "Enterprise plan",
    "description": "12-month enterprise subscription",
    "purchase_amount": 24000,
    "date": null
  }
}

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.