{
  "openapi": "3.1.0",
  "info": {
    "title": "ClickCaravan API",
    "version": "1.0.0",
    "description": "Record conversions and refunds from your server, fire thank-you-page conversions from the browser tag, count impressions, and receive signed webhooks. Money is always integer cents. The tenant comes from the key, never from the request body."
  },
  "servers": [{ "url": "https://clickcaravan.com" }],
  "components": {
    "securitySchemes": {
      "SignedKey": {
        "type": "apiKey", "in": "header", "name": "X-CC-Key",
        "description": "Server key cck_<prefix>_<secret> from Back office → API & tracking (shown once). Send X-CC-Key: <prefix>, X-CC-Timestamp: unix seconds (within 5 minutes of the server clock), X-CC-Signature: hex HMAC-SHA256(secret, `${timestamp}.${rawBody}`). The key must carry the route's permission (conversions:write, refunds:write, partners:read, rewards:write), else 403 insufficient_scope. Outbound webhooks are signed the same way with the endpoint's ccwh_ secret."
      },
      "PostbackKey": {
        "type": "apiKey", "in": "query", "name": "key",
        "description": "The full server key cck_<prefix>_<secret> in the URL, for platforms that can only fire a URL. Needs the postback permission. Prefer the signed Conversion API whenever you can."
      },
      "WidgetToken": {
        "type": "apiKey", "in": "query", "name": "t",
        "description": "Widget token (B-19), made by your server for the partner signed in to your app: \"ccw1.\" + key_prefix + \".\" + payload + \".\" + hex(HMAC-SHA256(key_secret, \"ccw1.\" + key_prefix + \".\" + payload)), where payload = base64url(JSON {sub, iat, exp, jti, widget?}). sub = the partner's email, or their partner id, coupon code or link code in the key's network. iat/exp in unix seconds, exp - iat <= 600, refused after exp (60 s skew allowed on iat). jti = 16-64 characters [A-Za-z0-9_-], one page load per jti (a second use is refused as a replay). widget (optional) = dashboard | referral, binding the token to that widget. The key must have the widgets permission and belong to the network in the URL. /embed.js puts it in the iframe URL for you (data-token)."
      }
    },
    "schemas": {
      "ConversionInput": {
        "type": "object",
        "required": ["goal", "order_id"],
        "description": "A click_id or a coupon is required to credit a partner.",
        "properties": {
          "click_id": { "type": "string", "format": "uuid", "description": "From ?cc_click_id= on your landing page." },
          "click_ids": { "type": "array", "maxItems": 20, "items": { "type": "string", "format": "uuid" }, "description": "Optional: the visitor's other click ids you kept, in any order. Programs on first_click credit the earliest one inside the cookie window, last-click programs the latest. Without it, first_click programs look for an earlier click from the same visitor (IP hash and browser) in the program. Only clicks of approved partners can take the credit." },
          "coupon": { "type": "string", "maxLength": 40 },
          "goal": { "type": "string", "pattern": "^[a-z0-9_]{2,40}$", "description": "A goal on the offer, e.g. sale, signup, lead. Keys starting cc_ are reserved." },
          "order_id": { "type": "string", "maxLength": 120, "description": "Idempotency key with goal: the same order is never booked twice." },
          "amount": { "type": "string", "pattern": "^\\d+(\\.\\d{1,2})?$", "example": "49.00" },
          "amount_cents": { "type": "integer", "minimum": 0 },
          "currency": { "type": "string", "minLength": 3, "maxLength": 3, "default": "USD" },
          "customer_ref": { "type": "string", "maxLength": 120, "description": "Your customer id (e.g. the Stripe customer id). Needed for duration windows, tier months, credit programs and one reward per customer: windows count from this customer's first paid conversion in the program." },
          "customer_email": { "type": "string", "description": "Used only to detect self-referrals (compared as a hash); not stored." },
          "event_at": { "type": "string", "format": "date-time", "description": "Defaults to now; may not be in the future. Payout rules are applied as of this date." },
          "offer_id": { "type": "string", "format": "uuid" },
          "dry_run": { "type": "boolean", "description": "Run every check and rule but book nothing." },
          "signals": { "$ref": "#/components/schemas/Signals" },
          "customer_country": { "type": "string", "pattern": "^[A-Za-z]{2}$", "example": "US", "description": "Optional: the customer's country (ISO 3166-1 alpha-2). When it differs from the click's country the fraud score gets the geo_mismatch signal." },
          "ship_state": { "type": "string", "pattern": "^[A-Za-z]{2}$", "example": "CA", "description": "Optional: the US state the order ships to (two-letter USPS code, e.g. CA). For an alcohol program with a ship-to list (where ship-to-state checks are switched on), a state outside the list books the conversion but holds it for review (held: ship_state)." },
          "items": { "type": "array", "maxItems": 100, "description": "Optional order lines, for SKU and category commission rules. Each line is priced by the most specific rule naming its SKU, else its category (percent of the line amount, flat amount per unit); the rest of the order and the main rule's flat fee go through the main rule. Lines may not add up to more than the order amount. Not available on the URL postback.", "items": { "$ref": "#/components/schemas/ConversionItem" } },
          "lead": { "type": "object", "description": "Optional (lead distribution, when the network uses it): the person behind a lead conversion. Stored in the network's Leads and offered to its buyers by its routing rules. Ignored while lead distribution is off; an invalid lead never refuses the conversion (the answer carries lead_error).", "required": ["name", "email"], "properties": { "name": { "type": "string", "maxLength": 120 }, "email": { "type": "string", "format": "email" }, "phone": { "type": "string", "maxLength": 40 }, "company": { "type": "string", "maxLength": 200 }, "state": { "type": "string", "pattern": "^[A-Za-z0-9-]{1,10}$", "example": "CA" }, "country": { "type": "string", "pattern": "^[A-Za-z]{2}$", "example": "US" }, "note": { "type": "string", "maxLength": 1000 } } }
        }
      },
      "ConversionItem": {
        "type": "object",
        "description": "One order line. Needs a sku or a category, and its line total (amount or amount_cents).",
        "properties": {
          "sku": { "type": "string", "maxLength": 80, "description": "Matched case-insensitively." },
          "category": { "type": "string", "maxLength": 80, "description": "Matched case-insensitively." },
          "quantity": { "type": "integer", "minimum": 1, "maximum": 100000, "default": 1 },
          "amount": { "type": "string", "pattern": "^\\d+(\\.\\d{1,2})?$", "example": "40.00", "description": "The line total (all units)." },
          "amount_cents": { "type": "integer", "minimum": 0 }
        }
      },
      "Signals": {
        "type": "object", "additionalProperties": false,
        "description": "Optional anti-abuse signals. Hashed on arrival, never stored raw. A match with a value known to be the partner's own (from their own purchases, or marked with POST /v1/partners/{ref}/signals) holds the conversion for review.",
        "properties": {
          "card_fingerprint_hash": { "type": "string", "minLength": 4, "maxLength": 200, "description": "e.g. a hash of the card fingerprint from your payment provider" },
          "signup_ip": { "type": "string", "description": "IPv4 or IPv6" },
          "device_id": { "type": "string", "minLength": 4, "maxLength": 200 },
          "email_domain": { "type": "string", "example": "example.com", "description": "Free mailbox domains (gmail.com …) never match." }
        }
      },
      "ConversionResult": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "conversion_id": { "type": ["string", "null"], "format": "uuid" },
          "status": { "type": "string", "enum": ["pending", "approved", "held", "available", "paid", "rejected", "reversed"] },
          "duplicate": { "type": "boolean", "description": "true when this order_id + goal was already booked; nothing new was booked." },
          "payout_cents": { "type": "integer" },
          "revenue_cents": { "type": "integer" },
          "fraud_score": { "type": "integer", "minimum": 0, "maximum": 100, "description": "0–100. At or above the program's hold line (default 50) the conversion waits for review; it is rejected automatically only if the program set a reject line. A self-referral scores 100 and is held for review." },
          "fraud_signals": { "type": "array", "items": { "type": "object", "properties": { "signal": { "type": "string" }, "detail": { "type": "string" } } } },
          "held": { "type": "string", "enum": ["plan_limit", "cap", "ship_state"], "description": "Booked but waiting for review: over the plan's monthly limit, over one of the program's monthly caps or budgets (cap), or shipped to a state the program can't ship to (ship_state)." },
          "cap": { "type": "string", "description": "Dry run only: the cap or budget this conversion would go over." },
          "customer_type": { "type": "string", "enum": ["new", "returning"], "description": "Dry run only: how the customer counted for new / returning rules." },
          "message": { "type": "string" },
          "dry_run": { "type": "boolean" },
          "booked": { "type": "boolean" },
          "would_be_status": { "type": "string" },
          "would_be_duplicate": { "type": "boolean" },
          "commission_reason": { "type": "string", "enum": ["outside_window", "customer_already_referred", "reward_cap", "customer_ref_required"],
            "description": "Present when the conversion was booked but pays 0: outside the rule's months or once-per-customer, the customer was already referred in another of your programs (credit programs), the partner's yearly reward cap was reached, or a window applies and customer_ref was missing." }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "success": { "const": false },
          "code": { "type": "string", "enum": ["invalid", "unattributed", "program_not_live", "unknown_goal", "partner_not_approved", "outside_window", "no_payout_rule", "insufficient_scope", "module_not_enabled", "plan_limit", "not_found", "pixel_off", "not_recorded", "pay_per_review", "coupon_only"] },
          "error": { "type": "string", "description": "Plain-English reason." }
        }
      },
      "RefundInput": {
        "type": "object",
        "required": ["order_id"],
        "properties": {
          "order_id": { "type": "string" },
          "goal": { "type": "string", "description": "Omit to reverse every goal booked for this order." },
          "reason": { "type": "string" }
        }
      },
      "RefundResult": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "results": { "type": "array", "items": { "type": "object", "properties": {
            "conversion_id": { "type": "string", "format": "uuid" },
            "status": { "type": "string", "description": "rejected (was pending/approved) or reversed (was held/available/paid)." },
            "already": { "type": "boolean" },
            "error": { "type": "string" } } } }
        }
      },
      "PixelInput": {
        "type": "object",
        "required": ["key", "click_id", "sig", "order_id"],
        "properties": {
          "key": { "type": "string", "pattern": "^ccpk_[0-9a-f]{12}$", "description": "Publishable key (pixel permission only)." },
          "click_id": { "type": "string", "format": "uuid" },
          "sig": { "type": "string", "pattern": "^[0-9a-f]{32}$", "description": "The cc_sig the tracking redirect added next to cc_click_id." },
          "goal": { "type": "string", "default": "sale" },
          "order_id": { "type": "string" },
          "amount": { "type": "string" },
          "amount_cents": { "type": "integer" },
          "currency": { "type": "string" }
        }
      },
      "WebhookEnvelope": {
        "type": "object",
        "required": ["id", "event", "created_at", "network_id", "data"],
        "properties": {
          "id": { "type": "string", "format": "uuid", "description": "Delivery id, same as X-CC-Delivery; stable across retries." },
          "event": { "type": "string" },
          "created_at": { "type": "string", "format": "date-time" },
          "network_id": { "type": "string", "format": "uuid" },
          "data": { "type": "object" }
        }
      },
      "ConversionEventData": {
        "type": "object",
        "properties": {
          "conversion_id": { "type": "string", "format": "uuid" },
          "order_id": { "type": "string" },
          "goal": { "type": ["string", "null"] },
          "program_id": { "type": "string", "format": "uuid" },
          "offer_id": { "type": "string", "format": "uuid" },
          "partner_id": { "type": "string", "format": "uuid" },
          "click_id": { "type": ["string", "null"] },
          "coupon": { "type": ["string", "null"] },
          "amount_cents": { "type": "integer" },
          "payout_cents": { "type": "integer" },
          "currency": { "type": "string" },
          "source": { "type": "string", "enum": ["postback", "api", "csv", "js_tag", "coupon_sync", "click_accrual", "impression_accrual", "landing_page"] },
          "event_at": { "type": "string", "format": "date-time" },
          "status": { "type": "string" },
          "reason": { "type": ["string", "null"] }
        }
      },
      "LeadEventData": {
        "type": "object",
        "properties": {
          "page": { "type": "string", "description": "Slug of the landing page the form was on" },
          "lead": { "type": "object", "properties": {
            "id": { "type": "string", "format": "uuid" },
            "program_id": { "type": "string", "format": "uuid" },
            "program_name": { "type": "string" },
            "name": { "type": "string" },
            "email": { "type": "string", "format": "email" },
            "company": { "type": ["string", "null"] },
            "note": { "type": ["string", "null"] },
            "partner_id": { "type": ["string", "null"], "format": "uuid", "description": "The partner whose click brought the lead; null without one" },
            "click_id": { "type": ["string", "null"], "format": "uuid" },
            "created_at": { "type": "string", "format": "date-time" } } }
        }
      },
      "PayoutEventData": {
        "type": "object",
        "properties": {
          "payout_id": { "type": "string", "format": "uuid" },
          "batch_id": { "type": "string", "format": "uuid" },
          "partner_id": { "type": "string", "format": "uuid" },
          "amount_cents": { "type": "integer" },
          "fee_cents": { "type": "integer", "description": "payout.paid through a rail: the rail fee deducted from this payout (above what the advertiser absorbs)" },
          "currency": { "type": "string" },
          "reason": { "type": "string", "description": "payout.failed: why the provider refused or returned the payment" }
        }
      },
      "CommissionEventData": {
        "allOf": [{ "$ref": "#/components/schemas/ConversionEventData" }, { "type": "object", "properties": {
          "reward_id": { "type": "string", "format": "uuid", "description": "The id to confirm with POST /v1/rewards/{id}/redeemed (credit programs)." },
          "reward_mode": { "type": "string", "enum": ["cash", "advertiser_credit"] },
          "customer_ref": { "type": ["string", "null"] } } }]
      },
      "PartnerSummary": {
        "type": "object",
        "description": "Counted: clicks excl. bots; sign-ups = distinct referred customers (or orders without a customer_ref) excl. rejected; earned excl. rejected and reversed, incl. milestone bonuses. Balances are the partner's whole balance in your network.",
        "properties": {
          "success": { "type": "boolean" },
          "partner_id": { "type": "string", "format": "uuid" },
          "currency": { "type": "string" },
          "clicks": { "type": "integer" }, "clicks_30d": { "type": "integer" }, "signups": { "type": "integer" }, "active_referrals": { "type": "integer" },
          "tier": { "type": ["object", "null"], "description": "Only when the summary covers one program (?program_id= or a single membership).", "properties": { "name": { "type": "string" }, "threshold": { "type": "integer" } } },
          "earned_cents": { "type": "integer" },
          "pending_cents": { "type": "integer", "description": "In review or in the hold period." },
          "available_cents": { "type": "integer", "description": "Cleared, waiting for a cash payout run." },
          "credit_available_cents": { "type": "integer", "description": "Cleared advertiser-credit rewards not yet redeemed." },
          "paid_cents": { "type": "integer" }, "credit_redeemed_cents": { "type": "integer" },
          "next_payout_date": { "type": ["string", "null"], "format": "date", "description": "From the program's payout day (UTC). Payout runs are approved by people; this is the planned date." },
          "payout_method": { "type": ["object", "null"], "description": "Masked payout method; null until partners can add one (payout rails are a later release)." },
          "programs": { "type": "array", "items": { "type": "object", "properties": {
            "program_id": { "type": "string", "format": "uuid" }, "name": { "type": "string" }, "membership": { "type": "string" },
            "reward_mode": { "type": "string", "enum": ["cash", "advertiser_credit"] }, "paid_ads_approved": { "type": "boolean" },
            "active_referrals": { "type": "integer" }, "active_days": { "type": "integer" },
            "tier": { "type": "object", "properties": { "name": { "type": "string" }, "threshold": { "type": "integer" } } },
            "next_tier": { "type": ["object", "null"] }, "next_payout_date": { "type": ["string", "null"], "format": "date" } } } }
        }
      },
      "RewardRedeemed": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" }, "reward_id": { "type": "string", "format": "uuid" }, "status": { "type": "string", "enum": ["paid"] },
          "amount_cents": { "type": "integer" }, "currency": { "type": "string" },
          "already": { "type": "boolean", "description": "true when this reward was already confirmed; nothing new was booked." }
        }
      }
    },
    "headers": {
      "X-CC-Event": { "schema": { "type": "string" } },
      "X-CC-Delivery": { "schema": { "type": "string", "format": "uuid" } },
      "X-CC-Timestamp": { "schema": { "type": "integer" } },
      "X-CC-Signature": { "description": "hex HMAC-SHA256(endpoint secret, `${X-CC-Timestamp}.${rawBody}`)", "schema": { "type": "string" } }
    },
    "responses": {
      "Error": { "description": "Refused, with a code and a plain-English reason.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
    }
  },
  "paths": {
    "/embed.js": {"get": {"summary": "Widget loader script", "description": "Embeddable partner widgets (B-19). Put <script src=\"https://clickcaravan.com/embed.js\" data-network=\"…\" data-widget=\"signup|dashboard|referral\" [data-program] [data-token] [data-target] [data-theme] async></script> on your page; it adds an iframe of /w/{network}/{widget}. 404 while widgets are switched off.", "responses": {"200": {"description": "JavaScript.", "content": {"application/javascript": {"schema": {"type": "string"}}}}, "404": {"description": "Widgets are switched off."}}}},
    "/w/{network}/signup": {"get": {"summary": "Widget: join the partner program", "description": "Anonymous sign-up form for one live program. Frameable only by the websites the network lists in API & tracking; 404 when widgets are off or the list is empty.", "parameters": [{"name": "network", "in": "path", "required": true, "schema": {"type": "string", "pattern": "^[a-z0-9-]{1,80}$"}, "description": "Your network's slug (shown in API & tracking)."}, {"name": "program", "in": "query", "required": false, "schema": {"type": "string"}, "description": "Program slug; may be omitted when the network has exactly one live program."}, {"name": "theme", "in": "query", "required": false, "schema": {"type": "string", "enum": ["dark", "system"]}, "description": "Default light."}], "responses": {"200": {"description": "The widget page (HTML), frameable only by the network's listed websites (Content-Security-Policy frame-ancestors).", "content": {"text/html": {"schema": {"type": "string"}}}}, "404": {"description": "A small HTML page in the network's brand saying why (\"Reason: expired | replay | signature | key | scope | network | widget | lifetime | malformed | partner\").", "content": {"text/html": {"schema": {"type": "string"}}}}}}},
    "/w/{network}/dashboard": {"get": {"summary": "Widget: the partner's balances, link and recent conversions", "description": "Needs a widget token (one page load) signed with a key of this network that has the widgets permission, and the network's API module.", "security": [{"WidgetToken": []}], "parameters": [{"name": "network", "in": "path", "required": true, "schema": {"type": "string", "pattern": "^[a-z0-9-]{1,80}$"}, "description": "Your network's slug (shown in API & tracking)."}, {"name": "theme", "in": "query", "required": false, "schema": {"type": "string", "enum": ["dark", "system"]}, "description": "Default light."}], "responses": {"200": {"description": "The widget page (HTML), frameable only by the network's listed websites (Content-Security-Policy frame-ancestors).", "content": {"text/html": {"schema": {"type": "string"}}}}, "401": {"description": "A small HTML page in the network's brand saying why (\"Reason: expired | replay | signature | key | scope | network | widget | lifetime | malformed | partner\").", "content": {"text/html": {"schema": {"type": "string"}}}}, "403": {"description": "A small HTML page in the network's brand saying why (\"Reason: expired | replay | signature | key | scope | network | widget | lifetime | malformed | partner\").", "content": {"text/html": {"schema": {"type": "string"}}}}, "404": {"description": "A small HTML page in the network's brand saying why (\"Reason: expired | replay | signature | key | scope | network | widget | lifetime | malformed | partner\").", "content": {"text/html": {"schema": {"type": "string"}}}}}}},
    "/w/{network}/referral": {"get": {"summary": "Widget: the partner's tracking link(s); a partner approved in a live program who has none gets one", "description": "Needs a widget token (one page load) signed with a key of this network that has the widgets permission, and the network's API module.", "security": [{"WidgetToken": []}], "parameters": [{"name": "network", "in": "path", "required": true, "schema": {"type": "string", "pattern": "^[a-z0-9-]{1,80}$"}, "description": "Your network's slug (shown in API & tracking)."}, {"name": "theme", "in": "query", "required": false, "schema": {"type": "string", "enum": ["dark", "system"]}, "description": "Default light."}], "responses": {"200": {"description": "The widget page (HTML), frameable only by the network's listed websites (Content-Security-Policy frame-ancestors).", "content": {"text/html": {"schema": {"type": "string"}}}}, "401": {"description": "A small HTML page in the network's brand saying why (\"Reason: expired | replay | signature | key | scope | network | widget | lifetime | malformed | partner\").", "content": {"text/html": {"schema": {"type": "string"}}}}, "403": {"description": "A small HTML page in the network's brand saying why (\"Reason: expired | replay | signature | key | scope | network | widget | lifetime | malformed | partner\").", "content": {"text/html": {"schema": {"type": "string"}}}}, "404": {"description": "A small HTML page in the network's brand saying why (\"Reason: expired | replay | signature | key | scope | network | widget | lifetime | malformed | partner\").", "content": {"text/html": {"schema": {"type": "string"}}}}}}},
    "/api/w/{network}/signup": {"post": {"summary": "Widget sign-up form submit", "description": "Called by the sign-up widget itself (same origin as the widget frame; cross-origin requests are refused). Creates the partner account (or uses an existing one with its password; accounts with two-factor sign-in apply from the portal) and applies to the program (pending review).", "parameters": [{"name": "network", "in": "path", "required": true, "schema": {"type": "string", "pattern": "^[a-z0-9-]{1,80}$"}, "description": "Your network's slug (shown in API & tracking)."}], "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["program", "name", "email", "password", "age_ok", "terms_ok"], "properties": {"program": {"type": "string"}, "name": {"type": "string", "maxLength": 120}, "email": {"type": "string", "format": "email"}, "password": {"type": "string", "minLength": 12}, "website": {"type": "string"}, "age_ok": {"const": "yes"}, "terms_ok": {"const": "yes"}}}}}}, "responses": {"200": {"description": "{ success: true, status: \"pending\" }"}, "400": {"$ref": "#/components/responses/Error"}, "401": {"$ref": "#/components/responses/Error"}, "403": {"$ref": "#/components/responses/Error"}, "404": {"$ref": "#/components/responses/Error"}, "409": {"$ref": "#/components/responses/Error"}}}},
    "/v1/conversions": {
      "post": {
        "summary": "Record a conversion (signed Conversion API)",
        "security": [{ "SignedKey": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ConversionInput" } } } },
        "responses": {
          "200": { "description": "Booked, a duplicate of a booked order, or a dry-run result.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ConversionResult" } } } },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "description": "Rate limit (600 a minute)." }
        }
      }
    },
    "/v1/partners/{ref}/summary": {
      "get": {
        "summary": "A partner's numbers, to show inside your own app",
        "description": "Signed like the Conversion API; a GET signs an empty body (`${timestamp}.`). Needs the partners:read permission. Only partners of the key's network; any other id or code is 404.",
        "security": [{ "SignedKey": [] }],
        "parameters": [
          { "name": "ref", "in": "path", "required": true, "schema": { "type": "string", "maxLength": 64 }, "description": "The partner's id, coupon code or tracking-link code in your network." },
          { "name": "program_id", "in": "query", "required": false, "schema": { "type": "string", "format": "uuid" }, "description": "Narrow to one program." }
        ],
        "responses": {
          "200": { "description": "The summary.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PartnerSummary" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/v1/partners/{ref}/signals": {
      "post": {
        "summary": "Mark values as the partner's own (self-referral detection)",
        "description": "For example when the affiliate is also your customer. Needs conversions:write. Values are hashed; later conversions for this partner with a matching signal are held for review.",
        "security": [{ "SignedKey": [] }],
        "parameters": [{ "name": "ref", "in": "path", "required": true, "schema": { "type": "string", "maxLength": 64 }, "description": "The partner's id, coupon code or tracking-link code in your network." }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["signals"], "properties": { "signals": { "$ref": "#/components/schemas/Signals" } } } } } },
        "responses": {
          "200": { "description": "How many values were new.", "content": { "application/json": { "schema": { "type": "object", "properties": { "success": { "type": "boolean" }, "partner_id": { "type": "string", "format": "uuid" }, "added": { "type": "integer" } } } } } },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/v1/rewards/{id}/redeemed": {
      "post": {
        "summary": "Confirm you applied an advertiser-credit reward",
        "description": "In a program that pays rewards as your own account credit: after the commission.available webhook, apply the credit in your billing, then call this. Books the redemption and marks the reward paid. Safe to retry. Needs rewards:write.",
        "security": [{ "SignedKey": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" }, "description": "reward_id from the webhook (the conversion id)." }],
        "requestBody": { "required": false, "content": { "application/json": { "schema": { "type": "object", "properties": { "reference": { "type": "string", "maxLength": 120, "description": "Your own reference, e.g. the customer balance transaction id." } } } } } },
        "responses": {
          "200": { "description": "Redeemed, or already redeemed.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RewardRedeemed" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/v1/refunds": {
      "post": {
        "summary": "Report a refund, chargeback or cancellation",
        "security": [{ "SignedKey": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RefundInput" } } } },
        "responses": {
          "200": { "description": "Each conversion of the order and what became of it.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/RefundResult" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/v1/payout-webhooks/{rail}": {
      "post": {
        "summary": "Payout provider notifications (Stripe, PayPal, Wise). For the payment providers only, not for customers",
        "description": "rail = stripe | paypal | wise. Stripe's notification must carry a valid Stripe-Signature. For every rail the body only names which payment to look at; its state is read back from the provider's own API, so a repeated or forged notification changes nothing. A rail that is switched off answers 404.",
        "parameters": [{ "name": "rail", "in": "path", "required": true, "schema": { "type": "string", "enum": ["stripe", "paypal", "wise"] } }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": {
          "200": { "description": "Received." },
          "401": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/postback": {
      "get": {
        "summary": "S2S postback (key in the URL)",
        "security": [{ "PostbackKey": [] }],
        "parameters": [
          { "name": "click_id", "in": "query", "schema": { "type": "string" } },
          { "name": "coupon", "in": "query", "schema": { "type": "string" } },
          { "name": "goal", "in": "query", "required": true, "schema": { "type": "string" } },
          { "name": "order_id", "in": "query", "required": true, "schema": { "type": "string" } },
          { "name": "amount", "in": "query", "schema": { "type": "string" } },
          { "name": "currency", "in": "query", "schema": { "type": "string" } },
          { "name": "event_at", "in": "query", "schema": { "type": "string", "format": "date-time" } },
          { "name": "dry_run", "in": "query", "schema": { "type": "boolean" } }
        ],
        "responses": {
          "200": { "description": "Same result as POST /v1/conversions.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ConversionResult" } } } },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/v1/pixel/conversions": {
      "post": {
        "summary": "Thank-you-page conversion from the browser tag",
        "description": "Sent by /t.js (ClickCaravan.conversion or data- attributes) with navigator.sendBeacon. Accepted only while platform staff have pixel conversions switched on, only from a page on one of the network's live offer domains (Origin, else Referer), and only for a click signed by this network's redirect. Coupons, emails, dates and dry runs are ignored. Every pixel conversion waits for an operator to approve it (status_reason browser_reported). Rate-limited per visitor IP.",
        "requestBody": { "required": true, "content": {
          "text/plain": { "schema": { "type": "string", "description": "JSON text of PixelInput (text/plain avoids a CORS preflight)." } },
          "application/json": { "schema": { "$ref": "#/components/schemas/PixelInput" } } } },
        "responses": {
          "200": { "description": "Recorded (or a duplicate of a recorded order). No amounts are returned to the browser.", "content": { "application/json": { "schema": { "type": "object", "properties": {
            "success": { "type": "boolean" }, "duplicate": { "type": "boolean" }, "status": { "type": "string" } } } } } },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "description": "Unknown, revoked or malformed publishable key.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "403": { "description": "pixel_off or module_not_enabled.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "422": { "description": "not_recorded: one generic answer for every other refusal (unsigned or forged click, another site, a second conversion from the same click and goal, partner not approved, outside the window …). The browser is never told which.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "429": { "description": "Too many from this visitor." }
        }
      }
    },
    "/i/{code}.gif": {
      "get": {
        "summary": "Impression pixel (CPM)",
        "description": "Put <img src=\"https://clickcaravan.com/i/<link code>.gif\" width=\"1\" height=\"1\" alt=\"\"> where the partner shows the offer. Counted once per link and visitor in 24 hours; bots and prefetches are never counted. Counting happens only while platform staff have the impression pixel switched on. The response is always the same 1×1 GIF.",
        "parameters": [{ "name": "code", "in": "path", "required": true, "schema": { "type": "string", "pattern": "^[A-Za-z0-9_-]{6,40}$" } }],
        "responses": { "200": { "description": "1×1 transparent GIF, never cached.", "content": { "image/gif": { "schema": { "type": "string", "format": "binary" } } } } }
      }
    },
    "/v1/openapi.json": {
      "get": {
        "summary": "This document",
        "responses": { "200": { "description": "OpenAPI 3.1", "content": { "application/json": { "schema": { "type": "object" } } } } }
      }
    }
  },
  "webhooks": {
    "conversion.created": { "post": { "summary": "A conversion was recorded (Pending)", "parameters": [
      { "name": "X-CC-Event", "in": "header", "schema": { "type": "string" } }, { "name": "X-CC-Delivery", "in": "header", "schema": { "type": "string" } },
      { "name": "X-CC-Timestamp", "in": "header", "schema": { "type": "integer" } }, { "name": "X-CC-Signature", "in": "header", "schema": { "type": "string" } }],
      "requestBody": { "content": { "application/json": { "schema": { "allOf": [{ "$ref": "#/components/schemas/WebhookEnvelope" }, { "properties": { "data": { "$ref": "#/components/schemas/ConversionEventData" } } }] } } } },
      "responses": { "2XX": { "description": "Delivered. Anything else is retried with backoff (1, 5, 30 min, 2, 6, 12, 24 h) for up to 72 hours." } } } },
    "conversion.approved": { "post": { "summary": "A conversion was approved",
      "requestBody": { "content": { "application/json": { "schema": { "allOf": [{ "$ref": "#/components/schemas/WebhookEnvelope" }, { "properties": { "data": { "$ref": "#/components/schemas/ConversionEventData" } } }] } } } },
      "responses": { "2XX": { "description": "Delivered." } } } },
    "conversion.rejected": { "post": { "summary": "A conversion was rejected (fraud, refund before approval, or by staff)",
      "requestBody": { "content": { "application/json": { "schema": { "allOf": [{ "$ref": "#/components/schemas/WebhookEnvelope" }, { "properties": { "data": { "$ref": "#/components/schemas/ConversionEventData" } } }] } } } },
      "responses": { "2XX": { "description": "Delivered." } } } },
    "conversion.reversed": { "post": { "summary": "An approved or paid conversion was reversed (refund, chargeback)",
      "requestBody": { "content": { "application/json": { "schema": { "allOf": [{ "$ref": "#/components/schemas/WebhookEnvelope" }, { "properties": { "data": { "$ref": "#/components/schemas/ConversionEventData" } } }] } } } },
      "responses": { "2XX": { "description": "Delivered." } } } },
    "commission.available": { "post": { "summary": "A commission cleared its hold and is owed. In a credit program: issue the credit, then call POST /v1/rewards/{id}/redeemed",
      "requestBody": { "content": { "application/json": { "schema": { "allOf": [{ "$ref": "#/components/schemas/WebhookEnvelope" }, { "properties": { "data": { "$ref": "#/components/schemas/CommissionEventData" } } }] } } } },
      "responses": { "2XX": { "description": "Delivered." } } } },
    "payout.paid": { "post": { "summary": "A partner payout was marked paid",
      "requestBody": { "content": { "application/json": { "schema": { "allOf": [{ "$ref": "#/components/schemas/WebhookEnvelope" }, { "properties": { "data": { "$ref": "#/components/schemas/PayoutEventData" } } }] } } } },
      "responses": { "2XX": { "description": "Delivered." } } } },
    "payout.failed": { "post": { "summary": "A payout sent through a rail failed; the money is back in the partner’s balance",
      "requestBody": { "content": { "application/json": { "schema": { "allOf": [{ "$ref": "#/components/schemas/WebhookEnvelope" }, { "properties": { "data": { "$ref": "#/components/schemas/PayoutEventData" } } }] } } } },
      "responses": { "2XX": { "description": "Delivered." } } } },
    "lead.created": { "post": { "summary": "A lead came in from a landing page ClickCaravan built for your program (B-7). Sent once per person per program.",
      "requestBody": { "content": { "application/json": { "schema": { "allOf": [{ "$ref": "#/components/schemas/WebhookEnvelope" }, { "properties": { "data": { "$ref": "#/components/schemas/LeadEventData" } } }] } } } },
      "responses": { "2XX": { "description": "Delivered." } } } },
    "ping": { "post": { "summary": "Test event from the back office (Send test event)",
      "requestBody": { "content": { "application/json": { "schema": { "allOf": [{ "$ref": "#/components/schemas/WebhookEnvelope" }, { "properties": { "data": { "type": "object", "properties": { "message": { "type": "string" } } } } }] } } } },
      "responses": { "2XX": { "description": "Delivered." } } } }
  }
}
