{
  "openapi": "3.1.0",
  "info": {
    "title": "Experi API",
    "version": "1.0",
    "description": "# Introduction\n\nThe **Experi API** allows you to integrate the gamification and loyalty platform\ninto your systems. With it, you can manage users, challenges, rewards,\nbadges and much more.\n\n## Authentication\n\nAll API requests must include an API key in the `Authorization` header:\n\n```\nAuthorization: Bearer sk_live_xxxxxxxx\n```\n\n### Key Types\n\n| Type | Prefix | Usage |\n|------|--------|-------|\n| **Secret Key** | `sk_live_` | Full access (create, update, delete) |\n| **Public Key** | `pk_live_` | Read-only (GET endpoints) |\n\n> ⚠️ **Never expose your Secret Key** in client-side code or public repositories.\n\n## Pagination\n\nEndpoints that return lists use cursor-based pagination:\n\n```json\n{\n  \"data\": [...],\n  \"has_more\": true,\n  \"next_cursor\": \"abc123\"\n}\n```\n\n### Parameters\n\n| Parameter | Type | Description |\n|-----------|------|-------------|\n| `limit` | integer | Maximum number of items (1-100, default: 20) |\n| `starting_after` | string | ID of the item after which to start |\n\n## Error Codes\n\n| Code | Type | Description |\n|------|------|-------------|\n| 400 | `validation_error` | Invalid data in the request |\n| 401 | `invalid_api_key` | Invalid or missing API key |\n| 403 | `public_key_not_allowed` | Endpoint requires Secret Key |\n| 404 | `not_found` | Resource not found |\n| 409 | `conflict` | Conflict (e.g., badge already awarded) |\n\n## Rate Limiting\n\nRate limits are enforced per API key and depend on the active Engine plan.\nResponse headers include information about the limit:\n\n- `RateLimit-Limit` and `X-RateLimit-Limit`: Total limit\n- `RateLimit-Remaining` and `X-RateLimit-Remaining`: Remaining requests\n- `RateLimit-Reset` and `X-RateLimit-Reset`: Reset timestamp\n- `Retry-After`: Seconds before retrying a `429` response\n\n## Idempotency\n\nMutation endpoints that can award points document support for\n`Idempotency-Key`. For `/actions/track`, send one stable key per logical\nevent. Successful responses are retained for 24 hours and can be replayed\nsafely without applying the event twice.\n\n## Webhooks\n\nExperi can notify your server in real time when events occur.\nConfigure endpoints via API or through the dashboard to receive signed `POST` requests.\n\n### Available Events\n\n| Event | Description |\n|-------|-------------|\n| `user.created` | New user registered |\n| `user.updated` | User data changed |\n| `user.deleted` | User removed |\n| `user.at_risk` | User identified as churn risk |\n| `user.reactivated` | Previously at-risk user re-engaged |\n| `challenge.completed` | Challenge completed |\n| `badge.earned` | Badge earned |\n| `badge.revoked` | Badge revoked |\n| `reward.redeemed` | Reward redeemed |\n| `points.added` | Points added |\n| `points.deducted` | Points deducted |\n| `guild.level_up` | Guild reached a new level |\n| `season.level_up` | User leveled up in the active season pass |\n| `referral.converted` | Referral turned into a rewarded conversion |\n| `winback.dispatched` | Win-back campaign dispatch recorded |\n| `survey.answered` | Survey answered |\n| `action.tracked` | Action tracked via API |\n| `tier.changed` | User moved up or down a tier (`direction`: `up` or `down`) |\n| `streak.broken` | A streak deadline passed without a new completion |\n| `season.reward_claimed` | User claimed a season pass level reward |\n| `community_goal.completed` | A community goal reached its target |\n| `*` | Wildcard — all events |\n\nEvents caused by an automation carry an `automation` object\n(`rule_id`, `rule_ids`, `depth`) so receivers can tell them apart.\n\n### Payload Format\n\n```json\n{\n  \"id\": \"evt_abc123\",\n  \"type\": \"user.created\",\n  \"created_at\": \"2026-02-21T10:30:00Z\",\n  \"data\": { ... }\n}\n```\n\n### Signature Verification\n\nEach request includes security headers:\n\n- `X-Experi-Signature`: `sha256={hmac}` — HMAC-SHA256 signature\n- `X-Experi-Timestamp`: Unix timestamp of the signature\n- `X-Experi-Event`: Event type\n- `X-Experi-Delivery`: Unique delivery ID\n\nThe signature is calculated over `{timestamp}.{payload}` using the webhook's\nsigning secret (`whsec_xxx`). Verify the signature to ensure authenticity.\n\n### Retries\n\nFailures are retried up to 3 times with progressive backoff (1min → 10min → 1h).\nAfter 50 consecutive failures, the webhook is automatically disabled.\n",
    "contact": {
      "name": "Experi Support",
      "email": "suporte@experi.com.br"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://experi.com.br/terms"
    }
  },
  "servers": [
    {
      "url": "https://api.experi.com.br/v1",
      "description": "Production"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Users",
      "description": "Manage your loyalty program users.\n\nUsers accumulate points, complete challenges, and redeem rewards.\n"
    },
    {
      "name": "Badges",
      "description": "Badges are visual achievements that users can unlock.\n\nUse badges to recognize important milestones and engage your users.\n"
    },
    {
      "name": "Challenges",
      "description": "Challenges are activities that users can complete to earn points.\n\nSupports QR codes, staff validation, and surveys.\n"
    },
    {
      "name": "QR Codes",
      "description": "Branded, trackable QR codes for challenges, URLs, app pages and guilds.\n\nGenerate the image through the API and read scans aggregated by day,\nchannel, device, browser and operating system.\n"
    },
    {
      "name": "Rewards",
      "description": "Rewards that users can redeem using their points.\n\nConfigure price, availability, requirements, and limits.\n"
    },
    {
      "name": "Actions",
      "description": "Record custom user actions.\n\nUse for event tracking and automatically completing challenges.\n"
    },
    {
      "name": "Leaderboards",
      "description": "User rankings by points.\n\nIdeal for creating healthy competition among participants.\n"
    },
    {
      "name": "Guilds",
      "description": "User groups, guilds, or clans.\n\nAllows users to join together to accumulate XP collectively and compete in group leaderboards.\n"
    },
    {
      "name": "Community Goals",
      "description": "Shared goals tracked across the tenant community.\n\nUseful for collaborative campaigns such as total challenge completions\nor total points earned during a promotion.\n"
    },
    {
      "name": "Countdowns",
      "description": "Public timers that linked challenges extend or shorten on every completion.\n\nEach countdown also has a public screen at `/public-countdown/{id}` on the\nproject's portal host, suitable for a TV or kiosk.\n"
    },
    {
      "name": "Referrals",
      "description": "Referral program validation and user referral performance.\n\nUse these endpoints to validate referral codes and inspect a user's\nreferral stats and converted invites.\n"
    },
    {
      "name": "Tiers",
      "description": "Tier configuration by qualifying XP, with rolling, calendar or lifetime\nwindows, a grace period before demotion and a points multiplier.\n"
    },
    {
      "name": "Streaks",
      "description": "Daily, weekly or monthly habits fed by linked challenges, with tolerance\nand automatic breaking (`streak.broken`).\n"
    },
    {
      "name": "Season Passes",
      "description": "Active season pass definitions and per-user season progress.\n\nUseful for showing the current pass, its levels, and a user's\naccumulated XP and claimed rewards.\n"
    },
    {
      "name": "Surveys",
      "description": "Surveys and questionnaires that users can answer.\n\nIdeal for collecting feedback, conducting NPS, or creating quizzes.\n"
    },
    {
      "name": "Campaigns",
      "description": "Composed return, feedback and referral loops: one call provisions the\nchallenge, reward and channel QR codes, then visits, responses,\nredemptions and referrals run through the same endpoints.\n"
    },
    {
      "name": "Analytics",
      "description": "Project-wide participation, completions, redemptions and points economy\nfor a period, with a daily series in the project time zone.\n"
    },
    {
      "name": "Win-back",
      "description": "Daily churn-risk classification by inactivity, with configurable\nthresholds, at-risk user lists and recorded win-back invitations.\n"
    },
    {
      "name": "Automations",
      "description": "Event-driven rules: when an event happens and the conditions match,\naward points or badges, log the event or call a webhook. Rules never\nreact to events they caused and chains stop at depth 3.\n"
    },
    {
      "name": "Events",
      "description": "Log of tracked actions received by the API, kept for 30 days.\n"
    },
    {
      "name": "Wallet",
      "description": "Signed links for adding a user's Apple Wallet or Google Wallet pass.\n"
    },
    {
      "name": "Webhooks",
      "description": "Receive real-time HTTP notifications when events occur.\n\nConfigure endpoints to receive `POST` requests with payloads\nsigned via HMAC-SHA256 when users are created, challenges\ncompleted, rewards redeemed, and other events.\n\n## How It Works\n\n1. You create a webhook via API or through the dashboard, providing your server's URL\n2. When an event occurs in Experi, we send a `POST` to your URL\n3. Your server verifies the signature and processes the event\n4. If delivery fails, we retry up to 3 times with progressive backoff\n\n## Payload\n\nAll webhook requests have the following envelope:\n\n```json\n{\n  \"id\": \"evt_abc123def456\",\n  \"type\": \"user.created\",\n  \"created_at\": \"2026-02-21T10:30:00.000Z\",\n  \"data\": { ... }\n}\n```\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `id` | string | Unique event ID (`evt_` prefix) |\n| `type` | string | Event type (e.g., `user.created`) |\n| `created_at` | string | ISO 8601 timestamp of when the event occurred |\n| `data` | object | Event-specific data (varies by type) |\n\n## Headers\n\nEach request includes the following headers:\n\n| Header | Example | Description |\n|--------|---------|-------------|\n| `Content-Type` | `application/json` | Always JSON |\n| `User-Agent` | `Experi-Webhooks/1.0` | System identifier |\n| `X-Experi-Event` | `user.created` | Event type |\n| `X-Experi-Signature` | `sha256=abc123...` | HMAC-SHA256 signature |\n| `X-Experi-Timestamp` | `1740130200` | Unix timestamp of the signature |\n| `X-Experi-Delivery` | `evt_abc123def456` | Unique delivery ID |\n\n## Signature Verification\n\nTo ensure the request came from Experi, verify the HMAC-SHA256 signature.\n\nThe signature is calculated over the string `{timestamp}.{payload}` using the\nwebhook's signing secret (`whsec_xxx`).\n\n### Node.js\n\n```javascript\nconst crypto = require('crypto');\n\nfunction verifySignature(rawBody, signature, timestamp, secret) {\n  const signedPayload = `${timestamp}.${rawBody}`;\n  const expected = crypto\n    .createHmac('sha256', secret)\n    .update(signedPayload)\n    .digest('hex');\n  return signature === `sha256=${expected}`;\n}\n\n// Express middleware\napp.post('/webhooks/experi', express.raw({ type: 'application/json' }), (req, res) => {\n  const sig = req.headers['x-experi-signature'];\n  const ts = req.headers['x-experi-timestamp'];\n  \n  if (!verifySignature(req.body.toString(), sig, ts, process.env.WEBHOOK_SECRET)) {\n    return res.status(401).json({ error: 'Invalid signature' });\n  }\n\n  const event = JSON.parse(req.body);\n  \n  switch (event.type) {\n    case 'user.created':\n      console.log('New user:', event.data.name);\n      break;\n    case 'challenge.completed':\n      console.log('Challenge completed:', event.data.challenge_id);\n      break;\n    case 'reward.redeemed':\n      console.log('Reward redeemed:', event.data.reward_id);\n      break;\n  }\n  \n  res.status(200).json({ received: true });\n});\n```\n\n### Python\n\n```python\nimport hmac\nimport hashlib\n\ndef verify_signature(payload: bytes, signature: str, timestamp: str, secret: str) -> bool:\n    signed_payload = f\"{timestamp}.{payload.decode()}\"\n    expected = hmac.new(\n        secret.encode(),\n        signed_payload.encode(),\n        hashlib.sha256\n    ).hexdigest()\n    return signature == f\"sha256={expected}\"\n```\n\n> ⚠️ **Important:** Always verify the signature before processing the event.\n> Respond with a `2xx` status within **10 seconds** to avoid timeout.\n\n## Event Reference\n\nBelow is the format of the `data` field for each event type.\n\n---\n\n### `user.created`\n\nFired when a new user is registered (via API or dashboard).\n\n```json\n{\n  \"id\": \"evt_abc123\",\n  \"type\": \"user.created\",\n  \"created_at\": \"2026-02-21T10:30:00.000Z\",\n  \"data\": {\n    \"user_id\": \"507f1f77bcf86cd799439011\",\n    \"name\": \"John Smith\",\n    \"email\": \"john@example.com\",\n    \"external_id\": \"cust_abc123\"\n  }\n}\n```\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `user_id` | string | ID of the created user |\n| `name` | string | User name |\n| `email` | string \\| null | User email |\n| `external_id` | string \\| null | Linked external ID |\n\n---\n\n### `user.updated`\n\nFired when a user's data is changed.\n\n```json\n{\n  \"id\": \"evt_abc123\",\n  \"type\": \"user.updated\",\n  \"created_at\": \"2026-02-21T10:30:00.000Z\",\n  \"data\": {\n    \"user_id\": \"507f1f77bcf86cd799439011\",\n    \"changes\": [\"name\", \"email\", \"metadata\"]\n  }\n}\n```\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `user_id` | string | ID of the updated user |\n| `changes` | string[] | List of fields that were modified |\n\n---\n\n### `user.deleted`\n\nFired when a user is removed (soft delete).\n\n```json\n{\n  \"id\": \"evt_abc123\",\n  \"type\": \"user.deleted\",\n  \"created_at\": \"2026-02-21T10:30:00.000Z\",\n  \"data\": {\n    \"user_id\": \"507f1f77bcf86cd799439011\"\n  }\n}\n```\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `user_id` | string | ID of the removed user |\n\n---\n\n### `challenge.completed`\n\nFired when a user completes a challenge (via QR code, staff, survey, or API).\n\n```json\n{\n  \"id\": \"evt_abc123\",\n  \"type\": \"challenge.completed\",\n  \"created_at\": \"2026-02-21T10:30:00.000Z\",\n  \"data\": {\n    \"user_id\": \"507f1f77bcf86cd799439011\",\n    \"challenge_id\": \"507f1f77bcf86cd799439020\",\n    \"completion_id\": \"507f1f77bcf86cd799439030\",\n    \"points_earned\": 20,\n    \"new_badges\": [\"loyal-customer\"]\n  }\n}\n```\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `user_id` | string | User ID |\n| `challenge_id` | string | ID of the completed challenge |\n| `completion_id` | string | ID of the completion record |\n| `points_earned` | integer | Points earned by the user |\n| `new_badges` | string[] | Slugs of unlocked badges (may be empty). Only present in API completions. |\n\n---\n\n### `badge.earned`\n\nFired when a user earns a badge (automatic or via API).\n\n```json\n{\n  \"id\": \"evt_abc123\",\n  \"type\": \"badge.earned\",\n  \"created_at\": \"2026-02-21T10:30:00.000Z\",\n  \"data\": {\n    \"user_id\": \"507f1f77bcf86cd799439011\",\n    \"badge_id\": \"507f1f77bcf86cd799439012\",\n    \"badge_slug\": \"first-challenge\",\n    \"badge_name\": \"First Step\"\n  }\n}\n```\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `user_id` | string | User ID |\n| `badge_id` | string | Badge ID |\n| `badge_slug` | string | Badge slug (unique identifier) |\n| `badge_name` | string | Badge name |\n\n---\n\n### `badge.revoked`\n\nFired when a badge is revoked from a user.\n\n```json\n{\n  \"id\": \"evt_abc123\",\n  \"type\": \"badge.revoked\",\n  \"created_at\": \"2026-02-21T10:30:00.000Z\",\n  \"data\": {\n    \"user_id\": \"507f1f77bcf86cd799439011\",\n    \"badge_id\": \"507f1f77bcf86cd799439012\"\n  }\n}\n```\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `user_id` | string | User ID |\n| `badge_id` | string | ID of the revoked badge |\n\n---\n\n### `reward.redeemed`\n\nFired when a user redeems a reward.\n\n```json\n{\n  \"id\": \"evt_abc123\",\n  \"type\": \"reward.redeemed\",\n  \"created_at\": \"2026-02-21T10:30:00.000Z\",\n  \"data\": {\n    \"user_id\": \"507f1f77bcf86cd799439011\",\n    \"reward_id\": \"507f1f77bcf86cd799439040\",\n    \"claim_id\": \"507f1f77bcf86cd799439050\",\n    \"points_spent\": 500,\n    \"user_balance_after\": 1000\n  }\n}\n```\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `user_id` | string | User ID |\n| `reward_id` | string | Reward ID |\n| `claim_id` | string | ID of the redemption record |\n| `points_spent` | integer | Points spent on redemption |\n| `user_balance_after` | integer | Points balance after redemption |\n\n---\n\n### `points.added`\n\nFired when points are added to a user (via API or admin).\n\n```json\n{\n  \"id\": \"evt_abc123\",\n  \"type\": \"points.added\",\n  \"created_at\": \"2026-02-21T10:30:00.000Z\",\n  \"data\": {\n    \"user_id\": \"507f1f77bcf86cd799439011\",\n    \"amount\": 100,\n    \"new_balance\": 1600,\n    \"reason\": \"Referral bonus\"\n  }\n}\n```\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `user_id` | string | User ID |\n| `amount` | integer | Amount of points added |\n| `new_balance` | integer | User's new points balance |\n| `reason` | string \\| null | Reason for addition (if provided) |\n\n---\n\n### `points.deducted`\n\nFired when points are deducted from a user (via API or admin).\n\n```json\n{\n  \"id\": \"evt_abc123\",\n  \"type\": \"points.deducted\",\n  \"created_at\": \"2026-02-21T10:30:00.000Z\",\n  \"data\": {\n    \"user_id\": \"507f1f77bcf86cd799439011\",\n    \"amount\": 50,\n    \"new_balance\": 1550,\n    \"reason\": \"Manual adjustment\"\n  }\n}\n```\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `user_id` | string | User ID |\n| `amount` | integer | Amount of points deducted |\n| `new_balance` | integer | User's new points balance |\n| `reason` | string \\| null | Reason for deduction (if provided) |\n\n---\n\n### `survey.answered`\n\nFired when a user answers a survey.\n\n```json\n{\n  \"id\": \"evt_abc123\",\n  \"type\": \"survey.answered\",\n  \"created_at\": \"2026-02-21T10:30:00.000Z\",\n  \"data\": {\n    \"user_id\": \"507f1f77bcf86cd799439011\",\n    \"survey_id\": \"507f1f77bcf86cd799439060\",\n    \"answer_id\": \"507f1f77bcf86cd799439070\",\n    \"challenge_id\": \"507f1f77bcf86cd799439020\"\n  }\n}\n```\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `user_id` | string | User ID |\n| `survey_id` | string | Survey ID |\n| `answer_id` | string | ID of the answer record |\n| `challenge_id` | string \\| undefined | ID of the linked challenge (if any) |\n\n---\n\n### `action.tracked`\n\nFired when an action is recorded via the `/actions/track` endpoint.\n\n```json\n{\n  \"id\": \"evt_abc123\",\n  \"type\": \"action.tracked\",\n  \"created_at\": \"2026-02-21T10:30:00.000Z\",\n  \"data\": {\n    \"user_id\": \"507f1f77bcf86cd799439011\",\n    \"action_type\": \"purchase_completed\",\n    \"properties\": {\n      \"order_id\": \"ORD-123\",\n      \"amount\": 150.00\n    },\n    \"challenges_completed\": 1,\n    \"badges_earned\": 0,\n    \"points_earned\": 20\n  }\n}\n```\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `user_id` | string | User ID |\n| `action_type` | string | Type of the recorded action |\n| `properties` | object | Custom properties sent with the action |\n| `challenges_completed` | integer | Number of challenges automatically completed |\n| `badges_earned` | integer | Number of badges unlocked |\n| `points_earned` | integer | Total points earned |\n\n---\n\n### `webhook.test`\n\nTest event sent manually from the dashboard or API. Use to verify\nthat your integration is working.\n\n```json\n{\n  \"id\": \"evt_abc123\",\n  \"type\": \"webhook.test\",\n  \"created_at\": \"2026-02-21T10:30:00.000Z\",\n  \"data\": {\n    \"webhook_id\": \"507f1f77bcf86cd799439012\",\n    \"message\": \"This is a test event from Experi\",\n    \"timestamp\": \"2026-02-21T10:30:00.000Z\"\n  }\n}\n```\n\n| Field | Type | Description |\n|-------|------|-------------|\n| `webhook_id` | string | ID of the webhook that received the test |\n| `message` | string | Default test message |\n| `timestamp` | string | ISO 8601 timestamp of the delivery |\n\n## Retries\n\nWhen a delivery fails, Experi automatically retries:\n\n| Attempt | Delay | Example |\n|---------|-------|---------|\n| 1st retry | 1 minute | Failure at 10:00 → retry at 10:01 |\n| 2nd retry | 10 minutes | Failure at 10:01 → retry at 10:11 |\n| 3rd retry | 1 hour | Failure at 10:11 → retry at 11:11 |\n\nAfter 3 attempts, the event is permanently marked as `failed`.\n\nIf the webhook accumulates **50 consecutive failures**, it is automatically\ndisabled (status `disabled`). In that case, create a new webhook.\n\nA successful delivery (`2xx` response) resets the failure counter.\n\n## Best Practices\n\n- **Respond quickly** — return `2xx` within 10 seconds. Process the event asynchronously.\n- **Idempotency** — use the event's `id` field for deduplication. The same event may be delivered more than once in case of a retry.\n- **Verify the signature** — always validate `X-Experi-Signature` before processing.\n- **Use HTTPS** — configure URLs with TLS to protect data in transit.\n- **Monitor failures** — track the webhook's `failure_count` and `last_delivery_status` through the dashboard or API.\n"
    }
  ],
  "paths": {
    "/users": {
      "get": {
        "operationId": "listUsers",
        "summary": "List users",
        "description": "Returns a paginated list of all users for the tenant.\n\n### Metadata Filters\n\nYou can filter users by metadata fields using query params:\n\n| Format | Example |\n|--------|----------|\n| `metadata[key]=value` | `?metadata[tier]=gold` |\n| `metadata.key=value` | `?metadata.tier=gold` |\n\n**Multiple filters:** `?metadata[tier]=gold&metadata[region]=south`\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Users"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/QueryLimit"
          },
          {
            "$ref": "#/components/parameters/QueryStartingAfter"
          },
          {
            "$ref": "#/components/parameters/QueryMetadata"
          }
        ],
        "responses": {
          "200": {
            "description": "List of users",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/User"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "507f1f77bcf86cd799439011",
                      "name": "John Smith",
                      "email": "john@example.com",
                      "points": 1500,
                      "badges": [
                        "507f1f77bcf86cd799439012"
                      ],
                      "challenges_count": 15,
                      "rewards_count": 3,
                      "created_at": "2024-01-15T10:30:00Z",
                      "updated_at": "2024-01-20T14:45:00Z"
                    }
                  ],
                  "has_more": true,
                  "next_cursor": "507f1f77bcf86cd799439011"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "operationId": "createUser",
        "summary": "Create user",
        "description": "Creates a new user in the loyalty program.\n\nThe user starts with 0 points and can begin completing challenges\nimmediately.\n\nSend an `Idempotency-Key` when a network retry could repeat the request.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Users"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UserCreate"
              },
              "examples": {
                "minimal": {
                  "summary": "Minimal data",
                  "value": {
                    "name": "John Smith"
                  }
                },
                "complete": {
                  "summary": "Complete data",
                  "value": {
                    "name": "John Smith",
                    "email": "john@example.com",
                    "phone": "5511999999999",
                    "external_id": "cust_abc123",
                    "referral_code": "FRIEND01",
                    "metadata": {
                      "tier": "gold",
                      "signup_source": "mobile_app"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "User created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/User"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/users/{id}": {
      "get": {
        "operationId": "getUser",
        "summary": "Get user",
        "description": "Returns the details of a specific user.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Users"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "User details",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/User"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "operationId": "updateUser",
        "summary": "Update user",
        "description": "Updates the data of an existing user.\n\nOnly the provided fields will be updated.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Users"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UserUpdate"
              },
              "example": {
                "name": "John Santos",
                "metadata": {
                  "tier": "platinum"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "User updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/User"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "delete": {
        "operationId": "deleteUser",
        "summary": "Delete user",
        "description": "Deletes a user (soft delete).\n\nThe user will be marked as deleted and will no longer appear\nin listings, but the data is preserved.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Users"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "User deleted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeleteResponse"
                },
                "example": {
                  "data": {
                    "id": "507f1f77bcf86cd799439011",
                    "deleted": true
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/users/{id}/badges": {
      "get": {
        "operationId": "listUserBadges",
        "summary": "List user badges",
        "description": "Returns all badges earned by the user. Each entry tells how the badge\nwas granted (`source`: `automatic`, `api`, `console`, `studio` or\n`automation`), who granted it (`granted_by`) and the `metadata` sent\nwhen it was awarded.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Users"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "$ref": "#/components/parameters/QueryLimit"
          },
          {
            "$ref": "#/components/parameters/QueryStartingAfter"
          }
        ],
        "responses": {
          "200": {
            "description": "List of user badges",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/UserBadgeGrant"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "507f1f77bcf86cd799439099",
                      "badge_id": "507f1f77bcf86cd799439012",
                      "badge": {
                        "id": "507f1f77bcf86cd799439012",
                        "slug": "first-challenge",
                        "name": "First Step",
                        "description": "Complete your first challenge",
                        "rarity": "common"
                      },
                      "awarded_at": "2024-01-16T09:00:00Z",
                      "source": "api",
                      "granted_by": "api_key:65f0c0ffee0000000000abcd",
                      "metadata": {
                        "campaign": "launch-week"
                      }
                    }
                  ],
                  "has_more": false
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "delete": {
        "operationId": "revokeUserBadge",
        "summary": "Revoke user badge",
        "description": "Removes a badge previously granted to a user.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Users"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "badge_id"
                ],
                "properties": {
                  "badge_id": {
                    "type": "string",
                    "description": "ID of the badge to be revoked"
                  }
                }
              },
              "example": {
                "badge_id": "507f1f77bcf86cd799439012"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Badge revoked",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "deleted": {
                          "type": "boolean"
                        },
                        "user_id": {
                          "type": "string"
                        },
                        "badge_id": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/users/{id}/rewards": {
      "get": {
        "operationId": "listUserRewards",
        "summary": "List user reward claims",
        "description": "Returns the history of rewards claimed by the user.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Users"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "$ref": "#/components/parameters/QueryLimit"
          },
          {
            "$ref": "#/components/parameters/QueryStartingAfter"
          }
        ],
        "responses": {
          "200": {
            "description": "List of reward claims",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/UserRewardClaim"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/users/{id}/referral/stats": {
      "get": {
        "operationId": "getUserReferralStats",
        "summary": "Get user referral stats",
        "description": "Returns the referral code, share link, aggregate stats, and referred users\nfor a specific user.\n\nThis is useful for showing a referral dashboard in your app.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Users",
          "Referrals"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Referral stats",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ReferralStatsResponse"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/users/{id}/season-pass": {
      "get": {
        "operationId": "getUserSeasonPassProgress",
        "summary": "Get user season pass progress",
        "description": "Returns the currently active season pass together with the selected user's\nprogress in that pass: season XP, current level (0 before the first\nlevel), premium status (`premium_granted_via`) and, per level, whether\nthe free and premium rewards are claimed or claimable.\n\nClaim a reached level with `POST /v1/users/{id}/season-pass/claim` and\nunlock premium with `POST /v1/users/{id}/season-pass/premium`.\n\nIf there is no active pass, the endpoint returns `404`.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Users",
          "Season Passes"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "User season pass progress",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/UserSeasonPass"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/users/{id}/season-pass/claim": {
      "post": {
        "operationId": "claimSeasonPassLevel",
        "summary": "Claim a season level reward",
        "description": "Claims the reward of a reached level on the `free` or `premium` track\nof the active pass. The linked reward is delivered for real: a reward\nclaim with price 0 is recorded (it appears in\n`GET /v1/users/{id}/rewards`), the level is marked as claimed and\n`season.reward_claimed` is emitted.\n\nEach level can be claimed once per track: a unique key protects the\nclaim, so retries return the existing claim with `created: false`\n(status 200). Send an `Idempotency-Key` header to make retries safe\nacross failures.\n\n| Error `type` | Status | Meaning |\n|---|---|---|\n| `level_not_found` | 404 | No such level in the active pass |\n| `level_locked` | 409 | The user's season XP has not reached the level |\n| `premium_required` | 409 | Premium track not unlocked for the user |\n| `no_reward` | 409 | The level has no reward on this track |\n| `reward_unavailable` | 409 | The linked reward is inactive or deleted |\n| `out_of_stock` | 409 | The linked reward has no stock left |\n| `season_pass_not_found` | 404 | No active season pass |\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Season Passes",
          "Users"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Retries with the same key replay the first result for 24 hours.",
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 255
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "level"
                ],
                "properties": {
                  "level": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "track": {
                    "type": "string",
                    "enum": [
                      "free",
                      "premium"
                    ],
                    "default": "free"
                  }
                }
              },
              "example": {
                "level": 2,
                "track": "premium"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Already claimed (replay, `created` is false)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SeasonClaim"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Reward claimed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SeasonClaim"
                    }
                  }
                },
                "example": {
                  "data": {
                    "claim_id": "6600f77bcf86cd799439abc",
                    "created": true,
                    "user_id": "507f1f77bcf86cd799439011",
                    "pass_id": "507f1f77bcf86cd799439050",
                    "level": 2,
                    "track": "premium",
                    "reward": {
                      "id": "507f1f77bcf86cd799439032",
                      "title": "Free dessert",
                      "description": "Any dessert of the day"
                    },
                    "claimed_at": "2026-12-14T19:02:11.000Z"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "`level_not_found`, `season_pass_not_found` or user not found"
          },
          "409": {
            "description": "See the table above."
          }
        }
      }
    },
    "/users/{id}/season-pass/premium": {
      "post": {
        "operationId": "upgradeSeasonPassPremium",
        "summary": "Unlock the premium track",
        "description": "Unlocks the premium track of the active pass for the user and records\nhow it was granted in `granted_via`:\n\n| `granted_via` | What happens |\n|---|---|\n| `points` (default when `premium_currency` is `points`) | Debits `premium_price` points atomically (balance check and debit in one operation) and emits `points.deducted` |\n| `external_payment` (default when `premium_currency` is `BRL`) | Records a payment your backend already confirmed; `payment_reference` is required. Experi never charges BRL. |\n| `complimentary` | Grants premium without charging |\n\nSend an `Idempotency-Key` header to make retries safe.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Season Passes",
          "Users"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Retries with the same key replay the first result for 24 hours.",
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 255
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "granted_via": {
                    "type": "string",
                    "enum": [
                      "points",
                      "external_payment",
                      "complimentary"
                    ]
                  },
                  "payment_reference": {
                    "type": "string",
                    "maxLength": 200,
                    "description": "Your payment id (required for `external_payment`)."
                  }
                }
              },
              "examples": {
                "points": {
                  "summary": "Pay with points",
                  "value": {}
                },
                "brl": {
                  "summary": "Confirmed external payment",
                  "value": {
                    "granted_via": "external_payment",
                    "payment_reference": "pi_3PqLtq2eZvKYlo2C"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Premium unlocked",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "user_id": {
                          "type": "string"
                        },
                        "pass_id": {
                          "type": "string"
                        },
                        "is_premium": {
                          "type": "boolean"
                        },
                        "granted_via": {
                          "type": "string",
                          "enum": [
                            "points",
                            "external_payment",
                            "complimentary"
                          ]
                        },
                        "points_spent": {
                          "type": "integer"
                        },
                        "payment_reference": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "new_balance": {
                          "type": "integer"
                        },
                        "granted_at": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`validation_error` or `payment_reference_required`"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "`season_pass_not_found` or user not found"
          },
          "409": {
            "description": "`already_premium`, `insufficient_points` (details: balance, price) or `premium_not_configured`"
          }
        }
      }
    },
    "/users/{id}/tier": {
      "get": {
        "operationId": "getUserTier",
        "summary": "Get user tier",
        "description": "Returns the user's current tier, qualifying XP, progress to the next\ntier and demotion risk. When `at_risk` is true, the user falls to\n`demotion_tier` at `demotion_at` unless they earn `xp_to_keep_tier`\nmore qualifying XP before that.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Tiers",
          "Users"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "User tier status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/UserTier"
                    }
                  }
                },
                "example": {
                  "data": {
                    "user_id": "507f1f77bcf86cd799439011",
                    "enabled": true,
                    "tier": {
                      "slug": "gold",
                      "name": "Gold",
                      "min_xp": 1000,
                      "multiplier": 1.2,
                      "color": "#CA8A04",
                      "icon": "crown",
                      "benefits": [
                        "Priority support"
                      ]
                    },
                    "next_tier": null,
                    "qualifying_xp": 940,
                    "lifetime_xp": 2300,
                    "xp_to_next_tier": null,
                    "progress_percent": 100,
                    "tier_qualified_at": "2026-03-02T14:00:00.000Z",
                    "at_risk": true,
                    "at_risk_since": "2026-10-10T03:00:00.000Z",
                    "demotion_at": "2026-11-09T03:00:00.000Z",
                    "demotion_tier": "silver",
                    "xp_to_keep_tier": 60,
                    "qualification_window": {
                      "type": "rolling",
                      "days": 365,
                      "starts_at": "2025-10-18T03:00:00.000Z"
                    },
                    "grace_period_days": 30
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/users/{id}/streaks": {
      "get": {
        "operationId": "listUserStreaks",
        "summary": "List user streaks",
        "description": "Returns the user's streaks with the value that counts **now**: a\nstreak whose deadline passed is reported (and marked) as `broken`\nwith `current_streak: 0`, which is also the value used by the\n`min-streak` requirement.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Streaks",
          "Users"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "User streaks",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/UserStreak"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "65f1f77bcf86cd7994390a1",
                      "streak_id": "65f1f77bcf86cd7994390b2",
                      "name": "Daily practice",
                      "frequency": {
                        "type": "daily",
                        "interval": 1
                      },
                      "current_streak": 12,
                      "best_streak": 30,
                      "status": "active",
                      "last_completion_at": "2026-10-18T11:20:00.000Z",
                      "next_deadline": "2026-10-20T08:59:59.999Z",
                      "broken_at": null
                    }
                  ],
                  "has_more": false
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/users/{id}/points/balance": {
      "get": {
        "operationId": "getUserPointsBalance",
        "summary": "Get points balance",
        "description": "Returns the user's current points balance and the total\npoints earned since registration.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Users"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Points balance",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PointsBalance"
                    }
                  }
                },
                "example": {
                  "data": {
                    "user_id": "507f1f77bcf86cd799439011",
                    "balance": 1500,
                    "lifetime_earned": 3500
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/users/{id}/points/add": {
      "post": {
        "operationId": "addUserPoints",
        "summary": "Add points",
        "description": "Adds points to the user's balance.\n\nUse this endpoint to grant points manually,\nsuch as bonuses or compensations.\n\nSend an `Idempotency-Key` to prevent a retry from adding points twice.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Users"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AddPointsRequest"
              },
              "example": {
                "amount": 200,
                "reason": "Referral bonus",
                "metadata": {
                  "referred_user_id": "507f1f77bcf86cd799439022"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Points added",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PointsOperation"
                    }
                  }
                },
                "example": {
                  "data": {
                    "user_id": "507f1f77bcf86cd799439011",
                    "previous_balance": 1500,
                    "new_balance": 1700,
                    "amount": 200
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/users/{id}/points/deduct": {
      "post": {
        "operationId": "deductUserPoints",
        "summary": "Deduct points",
        "description": "Deducts points from the user's balance.\n\nBy default, negative balance is not allowed. Use `allow_negative: true`\nto allow it.\n\nSend an `Idempotency-Key` to prevent a retry from deducting points twice.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Users"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DeductPointsRequest"
              },
              "example": {
                "amount": 100,
                "reason": "Reward reversal"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Points deducted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PointsOperation"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Insufficient balance",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "example": "insufficient_points"
                        },
                        "message": {
                          "type": "string",
                          "example": "User has 50 points, cannot deduct 100"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/users/{id}/wallet": {
      "get": {
        "operationId": "getUserWallet",
        "summary": "Get wallet links for a user",
        "description": "Returns, for each provider, whether the project can issue a loyalty\ncard, the user's existing pass and a signed **add to wallet** link that\nyour app can open for this user (no Experi login needed; valid for one\nhour — request a new one when it expires).\n\n- **Apple** (`add_url`): downloads the signed `.pkpass`; Safari on iOS\n  opens the \"Add to Apple Wallet\" sheet.\n- **Google** (`add_url`): redirects to Google's \"Save to Google Wallet\"\n  page.\n\nThe card shows the user's points, tier, XP, completed challenges and\nredeemed rewards, plus a QR code that identifies the user. Saved cards\nupdate automatically when points, badges, tiers, challenges or\nredemptions change.\n\nA provider is unavailable when the project disabled Wallet passes\n(`wallet_disabled`) or when its credentials are not configured\n(`provider_not_configured`).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Wallet"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Wallet state and links",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/UserWallet"
                    }
                  }
                },
                "example": {
                  "data": {
                    "user_id": "507f1f77bcf86cd799439011",
                    "enabled": true,
                    "providers": {
                      "apple": {
                        "available": true,
                        "unavailable_reason": null,
                        "add_url": "https://console.experi.com.br/api/wallets/apple/pass?token=eyJhbGciOi...",
                        "add_url_expires_at": "2026-10-18T15:40:00.000Z",
                        "pass": {
                          "id": "6712f0c2a1b2c3d4e5f60901",
                          "serial_number": "3f2a9c0e7b1d4a55b8c6e0f1a2b3c4d5",
                          "pass_type_identifier": "pass.br.com.experi.loyalty",
                          "device_registered": true,
                          "last_updated_at": "2026-10-18T14:00:00.000Z",
                          "created_at": "2026-10-01T12:00:00.000Z"
                        }
                      },
                      "google": {
                        "available": false,
                        "unavailable_reason": "provider_not_configured",
                        "add_url": null,
                        "add_url_expires_at": null,
                        "pass": null
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/badges": {
      "get": {
        "operationId": "listBadges",
        "summary": "List badges",
        "description": "Returns all badges available in the tenant.\n\nWith a **Public Key** (client apps), secret badges (`is_hidden: true`)\nare returned without name, description, criteria or style, so they\ncannot be discovered from the network traffic. Secret Keys see every\nfield.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Badges"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/QueryLimit"
          },
          {
            "$ref": "#/components/parameters/QueryStartingAfter"
          },
          {
            "name": "active",
            "in": "query",
            "description": "Filter by active status",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "metadata[key]",
            "in": "query",
            "description": "Filter by metadata fields. Use `metadata[field]=value` to filter \nby specific fields. Example: `metadata[tier]=gold` filters badges \nwhere `metadata.tier == 'gold'`. Multiple filters can be combined.\n",
            "schema": {
              "type": "string"
            },
            "style": "deepObject",
            "explode": true
          }
        ],
        "responses": {
          "200": {
            "description": "List of badges",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Badge"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "507f1f77bcf86cd799439012",
                      "slug": "first-challenge",
                      "name": "First Step",
                      "description": "Complete your first challenge",
                      "rarity": "common",
                      "style": {
                        "variant": "metallic",
                        "background_color": "#FFD700",
                        "icon_name": "trophy"
                      },
                      "criteria": {
                        "type": "count_challenges",
                        "threshold": 1
                      },
                      "is_hidden": false,
                      "active": true,
                      "created_at": "2024-01-01T00:00:00Z",
                      "updated_at": "2024-01-01T00:00:00Z"
                    }
                  ],
                  "has_more": false
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "operationId": "createBadge",
        "summary": "Create badge",
        "description": "Creates a new badge.\n\n### Criteria Types\n\n| Type | Description |\n|------|-------------|\n| `count_challenges` | Unlocks after N challenge completions (repetitions count); requires `threshold` >= 1 |\n| `streak_weeks` | Unlocks after N consecutive ISO weeks with a completion; requires `threshold` >= 1 |\n| `specific_challenges` | Unlocks after completing every listed challenge; requires `challenge_ids` |\n| `manual` | Only via the award endpoint (never evaluated automatically) |\n\nA counting criterion without a threshold is rejected with\n`validation_error`, so a badge can never be granted to every user on\nthe next evaluation. Automatic badges are evaluated after every\nchallenge completion (QR, action tracking, direct completion, surveys).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Badges"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BadgeCreate"
              },
              "examples": {
                "automatic": {
                  "summary": "Automatic badge (by challenges)",
                  "value": {
                    "slug": "veteran",
                    "name": "Veteran",
                    "description": "Complete 50 challenges",
                    "rarity": "epic",
                    "criteria": {
                      "type": "count_challenges",
                      "threshold": 50
                    },
                    "style": {
                      "variant": "holographic",
                      "icon_name": "award"
                    }
                  }
                },
                "manual": {
                  "summary": "Manual badge",
                  "value": {
                    "slug": "vip-member",
                    "name": "VIP Member",
                    "description": "Exclusive badge for VIP members",
                    "rarity": "legendary",
                    "criteria": {
                      "type": "manual"
                    },
                    "is_hidden": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Badge created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Badge"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "description": "Slug already exists",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "example": "duplicate_slug"
                        },
                        "message": {
                          "type": "string",
                          "example": "A badge with this slug already exists"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/badges/{id}": {
      "get": {
        "operationId": "getBadge",
        "summary": "Retrieve badge",
        "description": "Returns the details of a specific badge.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Badges"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Badge details",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Badge"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "operationId": "updateBadge",
        "summary": "Update badge",
        "description": "Updates an existing badge.\n\n> ⚠️ **Caution:** Changing criteria does not affect users who have\n> already unlocked the badge. When `criteria` is sent, the same rules\n> as creation apply (`threshold` >= 1 for counting criteria).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Badges"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BadgeUpdate"
              },
              "example": {
                "name": "Super Veteran",
                "criteria": {
                  "threshold": 100
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Badge updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Badge"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "delete": {
        "operationId": "deleteBadge",
        "summary": "Delete badge",
        "description": "Permanently deletes a badge.\n\n> ⚠️ **Warning:** This action cannot be undone.\n> The badge is removed from every user who earned it (no orphan\n> records are left). To stop granting a badge but keep it for those\n> who earned it, set `active: false` instead.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Badges"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Badge deleted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeleteResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/badges/{id}/award": {
      "post": {
        "operationId": "awardBadge",
        "summary": "Award badge manually",
        "description": "Manually awards a badge to a user.\n\nUse this endpoint for badges with `manual` criteria or to\naward any badge to a specific user.\n\nThe `metadata` you send is stored with the grant and returned by\n`GET /v1/users/{id}/badges` (with `source: api`); it is also included\nin the `badge.earned` event.\n\nIf the user already has the badge, returns error 409 (Conflict).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Badges"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AwardBadgeRequest"
              },
              "example": {
                "user_id": "507f1f77bcf86cd799439011",
                "metadata": {
                  "awarded_by": "admin",
                  "reason": "Participation in special event"
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Badge awarded successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/AwardBadgeResponse"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "source": {
                              "type": "string",
                              "enum": [
                                "api"
                              ]
                            },
                            "metadata": {
                              "type": [
                                "object",
                                "null"
                              ],
                              "additionalProperties": true
                            }
                          }
                        }
                      ]
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "507f1f77bcf86cd799439099",
                    "user_id": "507f1f77bcf86cd799439011",
                    "badge_id": "507f1f77bcf86cd799439012",
                    "badge": {
                      "id": "507f1f77bcf86cd799439012",
                      "slug": "vip-member",
                      "name": "VIP Member",
                      "description": "Exclusive badge for VIP members",
                      "rarity": "legendary"
                    },
                    "awarded_at": "2024-01-20T15:00:00Z",
                    "source": "api",
                    "metadata": {
                      "awarded_by": "admin",
                      "reason": "Participation in special event"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "Badge or user not found",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "enum": [
                            "badge_not_found",
                            "user_not_found"
                          ]
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "User already has this badge",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "example": "badge_already_awarded"
                        },
                        "message": {
                          "type": "string",
                          "example": "User already has this badge"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/challenges": {
      "get": {
        "operationId": "listChallenges",
        "summary": "List challenges",
        "description": "Returns all available challenges in the tenant.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Challenges"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/QueryLimit"
          },
          {
            "$ref": "#/components/parameters/QueryStartingAfter"
          },
          {
            "name": "active",
            "in": "query",
            "description": "Filter by active status",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "type",
            "in": "query",
            "description": "Filter by challenge type",
            "schema": {
              "type": "string",
              "enum": [
                "qrcode",
                "action",
                "survey"
              ]
            }
          },
          {
            "name": "metadata[key]",
            "in": "query",
            "description": "Filter by metadata fields. Use `metadata[field]=value` to filter \nby specific fields. Example: `metadata[category]=promo` filters \nchallenges where `metadata.category == 'promo'`. Multiple filters can \nbe combined.\n",
            "schema": {
              "type": "string"
            },
            "style": "deepObject",
            "explode": true
          }
        ],
        "responses": {
          "200": {
            "description": "List of challenges",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Challenge"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "507f1f77bcf86cd799439020",
                      "title": "First Purchase",
                      "description": "Make your first purchase and earn points",
                      "points": 100,
                      "type": "action",
                      "action_key": "purchase_completed",
                      "frequency": {
                        "unit": "once",
                        "interval": 1
                      },
                      "requirements": [],
                      "active": true,
                      "hidden": false,
                      "created_at": "2024-01-01T00:00:00Z",
                      "updated_at": "2024-01-01T00:00:00Z"
                    }
                  ],
                  "has_more": false
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "operationId": "createChallenge",
        "summary": "Create challenge",
        "description": "Creates a new challenge.\n\n### Challenge Types\n\n| Type | Description | How to complete |\n|------|-------------|----------------|\n| `qrcode` | QR Code | User scans the QR code |\n| `action` | Action | Via action tracking or staff validation |\n| `survey` | Survey | User answers a questionnaire |\n\n### Survey challenges\n\n`type: survey` requires `survey_id`: a published, non-archived survey\n(create it with `POST /surveys`). A survey accepts one answer per user, so\nsurvey challenges use `frequency.unit: once`. Complete them by sending the\nanswer with `POST /surveys/{id}/answers` and `challenge_id`. The response\nincludes `survey_id`. `survey_id` is rejected for other types.\n\n### Frequencies\n\n| Unit | Behavior |\n|------|----------|\n| `once` | Can be completed only once |\n| `always-available` | Can always be completed |\n| `days`, `weeks`, `months` | Cooldown after completion |\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Challenges"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/ChallengeCreate"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "survey_id": {
                        "type": "string",
                        "description": "Survey answered by the challenge. Required when `type` is\n`survey`; not allowed for other types.\n",
                        "example": "507f1f77bcf86cd799439050"
                      }
                    }
                  }
                ]
              },
              "examples": {
                "survey": {
                  "summary": "Survey challenge",
                  "value": {
                    "title": "Share your feedback",
                    "description": "Answer our 1-minute survey",
                    "points": 20,
                    "type": "survey",
                    "survey_id": "507f1f77bcf86cd799439050",
                    "frequency": {
                      "unit": "once",
                      "interval": 1
                    }
                  }
                },
                "qrcode": {
                  "summary": "QR Code challenge",
                  "value": {
                    "title": "Event Check-in",
                    "description": "Check in at the event by scanning the QR code",
                    "points": 50,
                    "type": "qrcode",
                    "frequency": {
                      "unit": "once",
                      "interval": 1
                    }
                  }
                },
                "action_recurring": {
                  "summary": "Recurring action challenge",
                  "value": {
                    "title": "Weekly Purchase",
                    "description": "Make one purchase per week",
                    "points": 20,
                    "type": "action",
                    "action_key": "purchase_completed",
                    "frequency": {
                      "unit": "weeks",
                      "interval": 1
                    }
                  }
                },
                "with_requirements": {
                  "summary": "Challenge with requirement",
                  "value": {
                    "title": "VIP Challenge",
                    "description": "Exclusive for VIP members",
                    "points": 200,
                    "type": "action",
                    "requirements": [
                      {
                        "type": "has-badge",
                        "badge_id": "507f1f77bcf86cd799439012"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Challenge created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/Challenge"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "survey_id": {
                              "type": "string",
                              "description": "Linked survey (only for `survey` challenges)"
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "The survey in `survey_id` was not found, is unpublished or archived",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "example": "survey_not_found"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/challenges/{id}": {
      "get": {
        "operationId": "getChallenge",
        "summary": "Get challenge",
        "description": "Returns the details of a specific challenge.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Challenges"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Challenge details",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Challenge"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "operationId": "updateChallenge",
        "summary": "Update challenge",
        "description": "Updates an existing challenge.\n\nFor `survey` challenges, `survey_id` points the challenge to another\npublished survey (useful after a survey's questions lock), and\n`frequency.unit` must stay `once`. `survey_id` is rejected for other types.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Challenges"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/ChallengeUpdate"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "survey_id": {
                        "type": "string",
                        "description": "New survey for a `survey` challenge"
                      }
                    }
                  }
                ]
              },
              "example": {
                "points": 150,
                "active": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Challenge updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Challenge"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "delete": {
        "operationId": "deleteChallenge",
        "summary": "Delete challenge",
        "description": "Deletes a challenge (soft delete).\n\nThe challenge will be marked as deleted and will no longer appear\nin listings. Completion history is preserved.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Challenges"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Challenge deleted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeleteResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/challenges/{id}/complete": {
      "post": {
        "operationId": "completeChallenge",
        "summary": "Complete challenge for user",
        "description": "Records the completion of a challenge for a user.\n\nThis endpoint:\n1. Validates whether the challenge is available for the user\n2. Adds the points to the user's balance\n3. Records the completion\n4. Evaluates and awards unlocked badges\n\n### Common Errors\n\n| Code | Type | Description |\n|------|------|-------------|\n| 400 | `challenge_not_available` | Not available; `details.reason` is `inactive`, `not_started`, `ended`, `frequency` or `requirements` (with `details.unmet_requirements`) |\n| 404 | `not_found` | Challenge or user not found |\n\nA successful completion emits `challenge.completed`, which also feeds\nstreaks, season XP, guild XP, community goals and referrals.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Challenges"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompleteChallengeRequest"
              },
              "example": {
                "user_id": "507f1f77bcf86cd799439011",
                "metadata": {
                  "validated_by": "staff_123"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Challenge completed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CompleteChallengeResponse"
                    }
                  }
                },
                "example": {
                  "data": {
                    "completion_id": "507f1f77bcf86cd799439088",
                    "user_id": "507f1f77bcf86cd799439011",
                    "challenge_id": "507f1f77bcf86cd799439020",
                    "points_earned": 100,
                    "new_balance": 1600,
                    "badges_awarded": [
                      {
                        "id": "507f1f77bcf86cd799439012",
                        "slug": "first-challenge",
                        "name": "First Step"
                      }
                    ],
                    "completed_at": "2024-01-20T15:30:00Z"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Challenge not available",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "example": "challenge_not_available"
                        },
                        "message": {
                          "type": "string",
                          "example": "User has already completed this challenge within the allowed frequency"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/challenges/{id}/availability": {
      "get": {
        "operationId": "checkChallengeAvailability",
        "summary": "Check availability",
        "description": "Checks whether a challenge is available for a specific user: active,\ninside its dates, allowed by its frequency and with every unlock\nrequirement met. Every completion path (QR, `actions/track`,\n`complete`, surveys) applies the same four checks.\n\nUseful for showing the challenge status in the user interface\nbefore attempting to complete it.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Challenges"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "name": "user_id",
            "in": "query",
            "required": true,
            "description": "User ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Availability status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ChallengeAvailabilityChecks"
                    }
                  }
                },
                "examples": {
                  "available": {
                    "summary": "Available",
                    "value": {
                      "data": {
                        "available": true,
                        "reasons": {
                          "is_active": true,
                          "within_time_window": true,
                          "frequency_allows": true,
                          "requirements_met": true
                        },
                        "unmet_requirements": []
                      }
                    }
                  },
                  "requirements": {
                    "summary": "Requirements not met",
                    "value": {
                      "data": {
                        "available": false,
                        "reasons": {
                          "is_active": true,
                          "within_time_window": true,
                          "frequency_allows": true,
                          "requirements_met": false
                        },
                        "unmet_requirements": [
                          "Você precisa de 200 pontos (tem 120)."
                        ]
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "user_id not provided",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "example": "validation_error"
                        },
                        "message": {
                          "type": "string",
                          "example": "user_id query parameter is required"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/challenges/{id}/qrcode-url": {
      "get": {
        "operationId": "getChallengeQrcodeUrl",
        "summary": "Get QR Code URL",
        "description": "Returns the public URLs to complete a QR Code type challenge.\n\nThis endpoint returns:\n- `public_url`: Traditional URL that requires Experi login\n- `api_url_template`: URL for external integrations (append `?user={user_id}`)\n- `redirect_url`: Redirect URL after completion (if configured)\n\nOnly `qrcode` type challenges can use this endpoint.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Challenges"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "QR Code URLs",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "challenge_id": {
                          "type": "string",
                          "description": "Challenge ID"
                        },
                        "token": {
                          "type": "string",
                          "description": "Unique QR code token"
                        },
                        "public_url": {
                          "type": "string",
                          "format": "uri",
                          "description": "Traditional URL (requires Experi login)"
                        },
                        "api_url_template": {
                          "type": "string",
                          "format": "uri",
                          "description": "URL for external integrations"
                        },
                        "api_url_usage": {
                          "type": "string",
                          "description": "API URL usage example"
                        },
                        "redirect_url": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "uri",
                          "description": "Redirect URL after completion"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": {
                    "challenge_id": "507f1f77bcf86cd799439020",
                    "token": "abc123xyz",
                    "public_url": "https://demo.experi.com.br/api/challenges/token/abc123xyz",
                    "api_url_template": "https://api.experi.com.br/v1/qr/abc123xyz?tenant=demo",
                    "api_url_usage": "https://api.experi.com.br/v1/qr/abc123xyz?tenant=demo&user={user_id}",
                    "redirect_url": "https://example.com/thanks"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid challenge type",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "example": "invalid_challenge_type"
                        },
                        "message": {
                          "type": "string",
                          "example": "Only QR code challenges have a public URL"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/qr/{token}": {
      "get": {
        "operationId": "completeQrCodeChallenge",
        "summary": "Complete challenge via QR Code",
        "description": "Public endpoint to complete a QR Code challenge.\n\nThis endpoint **does not require authentication** (API key). It is designed to be\nused when a user scans a QR code and is redirected to this URL.\n\n### Flow\n\n1. User scans a QR code containing the workspace slug, token, and user_id\n2. System validates the token and the user\n3. Challenge is completed and points are credited\n4. User is redirected to `redirect_url` (if configured) or success page\n\n### URL Format\n\n```\nGET /qr/{token}?tenant={tenant_slug}&user={user_id}\n```\n\n### Errors\n\nIn case of an error, the user is redirected to `/v1/qr/error` with a code:\n\n| Code | Description |\n|------|-------------|\n| `MISSING_USER_ID` | `user` parameter not provided |\n| `MISSING_TENANT` | `tenant` parameter not provided or workspace not found |\n| `CHALLENGE_NOT_FOUND` | Invalid token or challenge not found |\n| `USER_NOT_FOUND` | User not found |\n| `CHALLENGE_NOT_AVAILABLE` | Challenge already completed or in cooldown |\n| `COMPLETION_FAILED` | Error completing the challenge |\n\n**Permissions:** Public (no authentication)\n",
        "tags": [
          "Challenges"
        ],
        "security": [],
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "description": "Unique QR code token for the challenge",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "user",
            "in": "query",
            "required": true,
            "description": "ID of the user completing the challenge",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tenant",
            "in": "query",
            "required": true,
            "description": "Workspace slug returned by the QR URL endpoint",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "302": {
            "description": "Redirect after processing.\n\n**Success:** Redirects to the challenge's `redirect_url` (with query params \n`completed=true`, `challenge_id`, `user_id`) or to `/v1/qr/success`.\n\n**Error:** Redirects to `/v1/qr/error?code={ERROR_CODE}`.\n",
            "headers": {
              "Location": {
                "description": "Redirect URL",
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          }
        }
      }
    },
    "/qrcodes": {
      "get": {
        "operationId": "listQrCodes",
        "summary": "List QR codes",
        "description": "Returns the project's QR codes, ordered by creation (cursor pagination).\n\nEvery QR code encodes a stable scan URL (`scan_url`, `/qr/{id}`): each\nscan is recorded (channel, device, browser, operating system) and\nredirected to the current destination. Changing the destination later\ndoes not require reprinting the QR.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "QR Codes"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/QueryLimit"
          },
          {
            "$ref": "#/components/parameters/QueryStartingAfter"
          },
          {
            "name": "type",
            "in": "query",
            "description": "Filter by destination type",
            "schema": {
              "type": "string",
              "enum": [
                "challenge",
                "url",
                "app_page",
                "guild"
              ]
            }
          },
          {
            "name": "active",
            "in": "query",
            "description": "Filter by status",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of QR codes",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/QrCode"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      },
      "post": {
        "operationId": "createQrCode",
        "summary": "Create QR code",
        "description": "Creates a QR code. The destination depends on `type`:\n\n| Type | Destination | Required field |\n|------|-------------|----------------|\n| `challenge` | Challenge preview in the hosted portal (login, then complete) | `target_id` (challenge) |\n| `url` | Any HTTP(S) URL | `target_url` |\n| `app_page` | A page of the hosted portal | `app_path` (optional, default `/user/menu`) |\n| `guild` | Join flow of a guild | `target_id` (guild) |\n\nFields that don't belong to the type are rejected. Colors and `style`\nbrand the image returned by `GET /qrcodes/{id}/image`.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "QR Codes"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QrCodeCreate"
              },
              "examples": {
                "url": {
                  "summary": "Link to a landing page",
                  "value": {
                    "name": "Booth — Summer event",
                    "type": "url",
                    "target_url": "https://example.com/summer",
                    "color": "#0f172a",
                    "background_color": "#ffffff",
                    "style": "rounded"
                  }
                },
                "challenge": {
                  "summary": "Check-in challenge",
                  "value": {
                    "name": "Gym check-in",
                    "type": "challenge",
                    "target_id": "507f1f77bcf86cd799439020",
                    "style": "dots"
                  }
                },
                "app_page": {
                  "summary": "Portal page",
                  "value": {
                    "name": "Rewards poster",
                    "type": "app_page",
                    "app_path": "/user/menu"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "QR code created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/QrCode"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "507f1f77bcf86cd799439070",
                    "name": "Booth — Summer event",
                    "type": "url",
                    "target_id": null,
                    "target_url": "https://example.com/summer",
                    "app_path": null,
                    "color": "#0f172a",
                    "background_color": "#ffffff",
                    "style": "rounded",
                    "active": true,
                    "scans": 0,
                    "last_scan_at": null,
                    "scan_url": "https://engine.experi.com.br/qr/507f1f77bcf86cd799439070",
                    "image_url": {
                      "png": "https://api.experi.com.br/v1/qrcodes/507f1f77bcf86cd799439070/image?format=png",
                      "svg": "https://api.experi.com.br/v1/qrcodes/507f1f77bcf86cd799439070/image?format=svg"
                    },
                    "created_at": "2026-10-18T12:00:00.000Z",
                    "updated_at": "2026-10-18T12:00:00.000Z"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "The challenge or guild in `target_id` was not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QrError"
                },
                "example": {
                  "error": {
                    "type": "target_not_found",
                    "message": "Challenge '507f1f77bcf86cd799439020' not found"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/qrcodes/{id}": {
      "get": {
        "operationId": "getQrCode",
        "summary": "Get QR code",
        "description": "Returns a QR code with its destination, branding and scan totals.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "QR Codes"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "QR code",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/QrCode"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/QrCodeNotFound"
          }
        }
      },
      "patch": {
        "operationId": "updateQrCode",
        "summary": "Update QR code",
        "description": "Updates the name, destination, branding or status. The printed QR keeps\nworking: only what happens after the scan changes.\n\nChanging `type` drops the fields of the previous type; send the field the\nnew type requires (`target_id`, `target_url` or `app_path`). Inactive QR\ncodes answer scans with `410 Gone`.\n\nQR codes created by Experi Studio campaigns or missions follow the Studio:\nonly `name`, colors and `style` can change (`409 qrcode_in_use`).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "QR Codes"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QrCodeUpdate"
              },
              "example": {
                "type": "url",
                "target_url": "https://example.com/winter"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "QR code updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/QrCode"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/QrCodeNotFound"
          },
          "409": {
            "$ref": "#/components/responses/QrCodeInUse"
          }
        }
      },
      "delete": {
        "operationId": "deleteQrCode",
        "summary": "Delete QR code",
        "description": "Deletes a QR code. Its scan URL stops working (`404`). Recorded scans are\nkept.\n\nQR codes that belong to Experi Studio campaigns or missions can't be\ndeleted through the API (`409 qrcode_in_use`).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "QR Codes"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "QR code deleted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeleteResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/QrCodeNotFound"
          },
          "409": {
            "$ref": "#/components/responses/QrCodeInUse"
          }
        }
      }
    },
    "/qrcodes/{id}/image": {
      "get": {
        "operationId": "getQrCodeImage",
        "summary": "Get QR code image",
        "description": "Generates the QR image with the QR code branding (`color`,\n`background_color` and `style`), the same design the console downloads:\n\n- `square`: square modules and eyes.\n- `dots`: round modules and round eyes.\n- `rounded`: modules rounded where they have no neighbors, extra-rounded eyes with a round center.\n\nThe image encodes `scan_url` with error correction level Q and a quiet\nzone of about 2% (at least one module). PNG is RGB; SVG is vector.\n\nThe endpoint requires the Secret Key, so it can't be used directly in an\n`<img>` tag: fetch it server-side and cache it (`Cache-Control: private,\nmax-age=300`).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "QR Codes"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "name": "format",
            "in": "query",
            "description": "Image format",
            "schema": {
              "type": "string",
              "enum": [
                "png",
                "svg"
              ],
              "default": "png"
            }
          },
          {
            "name": "size",
            "in": "query",
            "description": "Width and height in pixels",
            "schema": {
              "type": "integer",
              "minimum": 64,
              "maximum": 2048,
              "default": 512
            }
          }
        ],
        "responses": {
          "200": {
            "description": "QR image",
            "headers": {
              "Content-Disposition": {
                "description": "`inline; filename=\"qrcode-<name>.<format>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "Cache-Control": {
                "description": "`private, max-age=300`",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/svg+xml": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/QrCodeNotFound"
          }
        }
      }
    },
    "/qrcodes/{id}/scans": {
      "get": {
        "operationId": "getQrCodeScans",
        "summary": "Get QR code scans",
        "description": "Scans in a window, aggregated by day (workspace timezone, days without\nscans included), channel (`counter`, `table`, `whatsapp`, `unknown`),\ndevice, browser and operating system. Staff test scans are excluded.\n\nDefault window: the last 30 days. Maximum: 366 days. Scans recorded\nbefore browser and OS tracking appear as `unknown` in those breakdowns.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "QR Codes"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "name": "from",
            "in": "query",
            "description": "Start of the window (ISO 8601 date or date-time; a date starts at midnight in the workspace timezone). Default `to` − 30 days.",
            "schema": {
              "type": "string",
              "example": "2026-10-01"
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "End of the window (ISO 8601). A date without time includes the whole day in the workspace timezone. Default now.",
            "schema": {
              "type": "string",
              "example": "2026-10-31"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Scan report",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/QrCodeScans"
                    }
                  }
                },
                "example": {
                  "data": {
                    "qrcode_id": "507f1f77bcf86cd799439070",
                    "from": "2026-10-01T03:00:00.000Z",
                    "to": "2026-10-04T02:59:59.999Z",
                    "timezone": "America/Sao_Paulo",
                    "total": 3,
                    "lifetime_scans": 42,
                    "last_scan_at": "2026-10-03T18:21:00.000Z",
                    "by_day": [
                      {
                        "date": "2026-10-01",
                        "scans": 2
                      },
                      {
                        "date": "2026-10-02",
                        "scans": 0
                      },
                      {
                        "date": "2026-10-03",
                        "scans": 1
                      }
                    ],
                    "by_channel": [
                      {
                        "channel": "counter",
                        "scans": 2
                      },
                      {
                        "channel": "table",
                        "scans": 0
                      },
                      {
                        "channel": "whatsapp",
                        "scans": 0
                      },
                      {
                        "channel": "unknown",
                        "scans": 1
                      }
                    ],
                    "by_device": [
                      {
                        "device": "Mobile",
                        "scans": 3
                      }
                    ],
                    "by_browser": [
                      {
                        "browser": "Safari",
                        "scans": 2
                      },
                      {
                        "browser": "Chrome",
                        "scans": 1
                      }
                    ],
                    "by_os": [
                      {
                        "os": "iOS",
                        "scans": 2
                      },
                      {
                        "os": "Android",
                        "scans": 1
                      }
                    ]
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/QrCodeNotFound"
          }
        }
      }
    },
    "/rewards": {
      "get": {
        "operationId": "listRewards",
        "summary": "List rewards",
        "description": "Returns all available rewards in the tenant.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Rewards"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/QueryLimit"
          },
          {
            "$ref": "#/components/parameters/QueryStartingAfter"
          },
          {
            "name": "active",
            "in": "query",
            "description": "Filter by active status",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "reward_type",
            "in": "query",
            "description": "Filter by catalog type (`custom` includes rewards without a type)",
            "schema": {
              "type": "string",
              "enum": [
                "percentage",
                "fixed_amount",
                "free_item",
                "custom"
              ]
            }
          },
          {
            "name": "metadata[key]",
            "in": "query",
            "description": "Filter by metadata fields. Use `metadata[field]=value` to filter \nby specific fields. Example: `metadata[type]=discount` filters \nrewards where `metadata.type == 'discount'`. Multiple filters can \nbe combined.\n",
            "schema": {
              "type": "string"
            },
            "style": "deepObject",
            "explode": true
          }
        ],
        "responses": {
          "200": {
            "description": "List of rewards",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/RewardCatalog"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "507f1f77bcf86cd799439030",
                      "title": "Free Coffee",
                      "description": "Redeem a free espresso coffee",
                      "price": 500,
                      "monetary_cost": 5.5,
                      "single_use": false,
                      "cooldown_days": 7,
                      "start_date": null,
                      "end_date": null,
                      "requirements": [],
                      "hide_if_locked": false,
                      "active": true,
                      "reward_type": "free_item",
                      "value": null,
                      "stock": 100,
                      "stock_remaining": 64,
                      "instructions": "Show the code at the counter",
                      "campaign_id": null,
                      "created_at": "2024-01-01T00:00:00Z",
                      "updated_at": "2024-01-01T00:00:00Z"
                    }
                  ],
                  "has_more": false
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "operationId": "createReward",
        "summary": "Create reward",
        "description": "Creates a new reward.\n\n### Availability Settings\n\n| Field | Description |\n|-------|-------------|\n| `single_use` | If true, user can redeem only once |\n| `cooldown_days` | Waiting days between redemptions (0 = no wait) |\n| `start_date` / `end_date` | Availability period |\n| `requirements` | Required badges to redeem |\n\n### Catalog fields\n\n| Field | Description |\n|-------|-------------|\n| `reward_type` | `percentage`, `fixed_amount`, `free_item` or `custom` (default) |\n| `value` | Discount value: required and positive for `percentage` (up to 100) and `fixed_amount` |\n| `stock` | Total units; omit or `null` for unlimited. Every redemption takes one unit under a per-reward lock: when `stock_remaining` reaches 0, redemptions fail with `409 out_of_stock` |\n| `instructions` | How to use the reward (up to 1000 characters) |\n\nThe same fields are shared with the Experi Studio catalog. The\n`metadata` keys `kind`, `value`, `inventory`, `instructions` and the\ncampaign keys are reserved.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Rewards"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/RewardCreate"
                  },
                  {
                    "$ref": "#/components/schemas/RewardCatalogInput"
                  }
                ]
              },
              "examples": {
                "simple": {
                  "summary": "Simple reward",
                  "value": {
                    "title": "Free Coffee",
                    "description": "Redeem a free espresso coffee",
                    "price": 500,
                    "monetary_cost": 5.5
                  }
                },
                "limited": {
                  "summary": "Limited reward",
                  "value": {
                    "title": "Birthday Discount",
                    "description": "20% discount on your birthday month",
                    "price": 0,
                    "single_use": true,
                    "start_date": "2024-01-01T00:00:00Z",
                    "end_date": "2024-12-31T23:59:59Z"
                  }
                },
                "vip_only": {
                  "summary": "VIP exclusive",
                  "value": {
                    "title": "VIP Lounge Access",
                    "description": "Exclusive access to the VIP lounge",
                    "price": 1000,
                    "requirements": [
                      {
                        "type": "has-badge",
                        "badge_id": "507f1f77bcf86cd799439012"
                      }
                    ],
                    "hide_if_locked": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Reward created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/RewardCatalog"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/rewards/{id}": {
      "get": {
        "operationId": "getReward",
        "summary": "Get reward",
        "description": "Returns the details of a specific reward.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Rewards"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Reward details",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/RewardCatalog"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "operationId": "updateReward",
        "summary": "Update reward",
        "description": "Updates an existing reward. Catalog fields (`reward_type`, `value`,\n`stock`, `instructions`) can be changed independently; `stock: null`\nmakes it unlimited. Raising or lowering `stock` keeps the redemptions\nalready made (`stock_remaining` = `stock` − redemptions).\n\nRewards provisioned by a campaign (`campaign_id` set) are managed by the\ncampaign: `409 reward_managed_by_campaign`.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Rewards"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/RewardUpdate"
                  },
                  {
                    "$ref": "#/components/schemas/RewardCatalogInput"
                  }
                ]
              },
              "example": {
                "price": 400,
                "stock": 250,
                "instructions": "Valid for one order"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Reward updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/RewardCatalog"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`reward_managed_by_campaign` (details: `campaign_id`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RewardError"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteReward",
        "summary": "Delete reward",
        "description": "Deletes a reward (soft delete).\n\nThe redemption history is preserved. Campaign rewards are archived\nwith their campaign (`409 reward_managed_by_campaign`).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Rewards"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Reward deleted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeleteResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`reward_managed_by_campaign`",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RewardError"
                }
              }
            }
          }
        }
      }
    },
    "/rewards/{id}/redeem": {
      "post": {
        "operationId": "redeemReward",
        "summary": "Redeem reward",
        "description": "Redeems a reward for a user.\n\nThis endpoint:\n1. Validates availability (cooldown, requirements, period)\n2. Checks if the user has enough points\n3. Deducts points from the balance\n4. Records the redemption\n\nSend an `Idempotency-Key` to prevent a network retry from redeeming and\ncharging the same reward twice.\n\n### Common Errors\n\n| Code | Type | Description |\n|------|------|-------------|\n| 400 | `insufficient_points` | Insufficient points |\n| 400 | `already_redeemed` | Already redeemed (single_use) |\n| 400 | `cooldown_active` | In cooldown period |\n| 400 | `requirements_not_met` | Missing required badge |\n| 400 | `reward_expired` | Outside validity period |\n| 409 | `out_of_stock` | `stock_remaining` is 0 (stock is never oversold) |\n| 409 | `redemption_in_progress` | Another stock-limited redemption holds the reward; retry (`Retry-After`) |\n| 409 | `reward_managed_by_campaign` | Campaign rewards are redeemed with `POST /v1/campaigns/{id}/redemptions` |\n\nThe response includes `reward.stock_remaining` (null when unlimited).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Rewards"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RedeemRewardRequest"
              },
              "example": {
                "user_id": "507f1f77bcf86cd799439011",
                "metadata": {
                  "order_id": "ORD-456"
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Reward redeemed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/RedeemRewardResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "507f1f77bcf86cd799439077",
                    "user_id": "507f1f77bcf86cd799439011",
                    "reward_id": "507f1f77bcf86cd799439030",
                    "reward": {
                      "id": "507f1f77bcf86cd799439030",
                      "title": "Exclusive T-Shirt",
                      "description": "Black t-shirt with logo",
                      "price": 500,
                      "stock_remaining": 41
                    },
                    "points_spent": 500,
                    "user_balance_after": 1000,
                    "redeemed_at": "2024-01-20T16:00:00Z",
                    "metadata": {
                      "order_id": "ORD-456"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "enum": [
                            "insufficient_points",
                            "already_redeemed",
                            "cooldown_active",
                            "requirements_not_met",
                            "reward_inactive",
                            "reward_not_started",
                            "reward_expired"
                          ]
                        },
                        "message": {
                          "type": "string"
                        },
                        "details": {
                          "type": "object",
                          "properties": {
                            "next_available": {
                              "type": "string",
                              "format": "date-time"
                            }
                          }
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "insufficient": {
                    "summary": "Insufficient points",
                    "value": {
                      "error": {
                        "type": "insufficient_points",
                        "message": "User has 300 points but reward costs 500"
                      }
                    }
                  },
                  "cooldown": {
                    "summary": "In cooldown",
                    "value": {
                      "error": {
                        "type": "cooldown_active",
                        "message": "Reward is in cooldown period",
                        "details": {
                          "next_available": "2024-01-27T16:00:00Z"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/rewards/{id}/availability": {
      "get": {
        "operationId": "checkRewardAvailability",
        "summary": "Check availability",
        "description": "Checks if a reward is available for a user.\n\nUseful for showing status in the UI before attempting to redeem.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Rewards"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "name": "user_id",
            "in": "query",
            "required": true,
            "description": "User ID",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Availability status, one entry per check",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/RewardAvailabilityResult"
                    }
                  }
                },
                "examples": {
                  "out_of_stock": {
                    "summary": "Out of stock",
                    "value": {
                      "data": {
                        "available": false,
                        "reward_id": "507f1f77bcf86cd799439030",
                        "user_id": "507f1f77bcf86cd799439011",
                        "checks": [
                          {
                            "name": "sufficient_points",
                            "passed": true,
                            "details": {
                              "required": 500,
                              "available": 1500,
                              "deficit": 0
                            }
                          },
                          {
                            "name": "stock",
                            "passed": false,
                            "reason": "Out of stock",
                            "details": {
                              "stock": 100,
                              "stock_remaining": 0
                            }
                          }
                        ],
                        "summary": {
                          "total_checks": 2,
                          "passed": 1,
                          "failed": 1
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "user_id not provided"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/actions/track": {
      "post": {
        "operationId": "trackAction",
        "summary": "Track action",
        "description": "Tracks an action performed by a user.\n\nThis endpoint is ideal for integration with external systems.\nWhen an action is tracked:\n\n1. The system looks for challenges with a matching `action_type`\n2. If found, checks availability for the user\n3. Automatically completes available challenges\n4. Evaluates and grants unlocked badges\n\n### Usage Example\n\nYour sales system can call this endpoint after each purchase:\n\n```json\n{\n  \"user_id\": \"...\",\n  \"action_type\": \"purchase_completed\",\n  \"properties\": {\n    \"order_id\": \"ORD-123\",\n    \"amount\": 150.00,\n    \"items_count\": 3\n  }\n}\n```\n\nIf there is a \"Weekly Purchase\" challenge with `action_type: purchase_completed`,\nit will be completed automatically.\n\nSend an `Idempotency-Key` for every logical event. The Engine stores a\nsuccessful result for 24 hours and replays it without applying points or\nrules twice. Reusing the same key with a different body returns `409`.\n\nRequest bodies are limited to 64 KB. The optional `properties` object\naccepts up to 50 top-level keys and 32 KB of serialized JSON.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Actions"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Unique key for this logical action (8–255 characters).",
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 255,
              "example": "order-ORD-123-purchase-completed"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TrackActionRequest"
              },
              "examples": {
                "purchase": {
                  "summary": "Purchase completed",
                  "value": {
                    "user_id": "507f1f77bcf86cd799439011",
                    "action_type": "purchase_completed",
                    "properties": {
                      "order_id": "ORD-123",
                      "amount": 150,
                      "payment_method": "credit_card"
                    }
                  }
                },
                "checkin": {
                  "summary": "Check-in",
                  "value": {
                    "user_id": "507f1f77bcf86cd799439011",
                    "action_type": "store_checkin",
                    "properties": {
                      "store_id": "store_sp_01",
                      "location": "São Paulo"
                    }
                  }
                },
                "referral": {
                  "summary": "Referral",
                  "value": {
                    "user_id": "507f1f77bcf86cd799439011",
                    "action_type": "friend_referred",
                    "properties": {
                      "referred_user_id": "507f1f77bcf86cd799439022"
                    }
                  }
                },
                "with_timestamp": {
                  "summary": "With custom timestamp",
                  "value": {
                    "user_id": "507f1f77bcf86cd799439011",
                    "action_type": "purchase_completed",
                    "properties": {
                      "order_id": "ORD-456"
                    },
                    "timestamp": "2024-01-15T14:30:00Z"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Action tracked",
            "headers": {
              "X-Request-Id": {
                "description": "Correlation ID generated or propagated by the Engine.",
                "schema": {
                  "type": "string",
                  "format": "uuid"
                }
              },
              "Idempotent-Replayed": {
                "description": "Present and true when a cached idempotent result was returned.",
                "schema": {
                  "type": "boolean"
                }
              },
              "RateLimit-Limit": {
                "description": "Maximum requests allowed in the current minute.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "description": "Requests remaining in the current minute.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "description": "Unix timestamp when the current window resets.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/TrackActionResponse"
                    }
                  }
                },
                "examples": {
                  "with_completions": {
                    "summary": "With completed challenges",
                    "value": {
                      "data": {
                        "success": true,
                        "user_id": "507f1f77bcf86cd799439011",
                        "points_earned": 50,
                        "challenges_completed": [
                          {
                            "id": "507f1f77bcf86cd799439020",
                            "title": "Weekly Purchase",
                            "points": 50
                          }
                        ],
                        "badges_earned": [],
                        "summary": {
                          "challenges_triggered": 1,
                          "challenges_completed": 1,
                          "badges_earned": 0,
                          "total_points_earned": 50
                        }
                      }
                    }
                  },
                  "no_completions": {
                    "summary": "No matching challenges",
                    "value": {
                      "data": {
                        "success": true,
                        "user_id": "507f1f77bcf86cd799439011",
                        "points_earned": 0,
                        "challenges_completed": [],
                        "badges_earned": [],
                        "summary": {
                          "challenges_triggered": 0,
                          "challenges_completed": 0,
                          "badges_earned": 0,
                          "total_points_earned": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "User not found",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "example": "user_not_found"
                        },
                        "message": {
                          "type": "string",
                          "example": "User not found"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Idempotency key conflict or a matching request still in progress",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "enum": [
                            "idempotency_conflict",
                            "idempotency_in_progress"
                          ]
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "413": {
            "description": "Request body exceeds the 64 KB limit",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "example": "payload_too_large"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "headers": {
              "Retry-After": {
                "description": "Seconds until the client should retry.",
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                }
              },
              "RateLimit-Reset": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    },
    "/leaderboards": {
      "get": {
        "operationId": "getLeaderboard",
        "summary": "Get leaderboard",
        "description": "Returns the user ranking for one metric.\n\n### Leaderboard Types\n\n| Type | Value | Period |\n|------|-------|--------|\n| `points` | Current points balance (default) | Not applied: always the current balance (`period` is returned as `all`) |\n| `challenges` | Challenge completions | Counted by completion date |\n| `badges` | Badges earned | Counted by `earnedAt` |\n\n### Available Periods\n\n| Period | Starts at |\n|--------|-----------|\n| `all` | No limit (default) |\n| `month` | Day 1 of the current month, 00:00 in the project timezone |\n| `week` | Monday of the current week, 00:00 in the project timezone |\n\nThe start used is returned as `period_start`.\n\n### Ranking rules\n\n- Removed users never appear (in `entries` nor in `user_position`).\n- `challenges` and `badges` list only users with at least one record\n  in the period.\n- Ties share the same rank and the next rank skips (\"1224\"\n  competition ranking). `user_position` follows the same rule:\n  rank = 1 + users strictly ahead.\n\n### Metadata Filters\n\nFilter the leaderboard to only include users that have specific metadata values:\n\n| Format | Example |\n|--------|---------|\n| `metadata[key]=value` | `?metadata[tier]=gold` |\n| `metadata.key=value` | `?metadata.tier=gold` |\n\nNumeric and boolean metadata also match their text form\n(`metadata[level]=5` matches `5` and `\"5\"`).\n\n**Example:** `?type=challenges&period=week&metadata[region]=south` —\nweekly completions ranking for users in the south region only.\n\nUse `include_user` to ensure that a specific user appears in the result\nas `user_position`, even if they are not in the top N.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Leaderboards"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "description": "Leaderboard type (ranking metric)",
            "schema": {
              "type": "string",
              "enum": [
                "points",
                "challenges",
                "badges"
              ],
              "default": "points"
            }
          },
          {
            "name": "period",
            "in": "query",
            "description": "Leaderboard period (ignored for `points`)",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "month",
                "week"
              ],
              "default": "all"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Number of positions (maximum 100)",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 10
            }
          },
          {
            "name": "include_user",
            "in": "query",
            "description": "User ID to return as `user_position` even if not in the top",
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/QueryMetadata"
          }
        ],
        "responses": {
          "200": {
            "description": "Leaderboard",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Leaderboard"
                    }
                  }
                },
                "example": {
                  "data": {
                    "type": "challenges",
                    "period": "week",
                    "period_start": "2026-10-12T03:00:00.000Z",
                    "entries": [
                      {
                        "rank": 1,
                        "user_id": "507f1f77bcf86cd799439011",
                        "user": {
                          "id": "507f1f77bcf86cd799439011",
                          "name": "João Silva",
                          "avatar_url": "https://cdn.example.com/joao.png"
                        },
                        "value": 12
                      },
                      {
                        "rank": 2,
                        "user_id": "507f1f77bcf86cd799439022",
                        "user": {
                          "id": "507f1f77bcf86cd799439022",
                          "name": "Maria Santos"
                        },
                        "value": 9
                      },
                      {
                        "rank": 2,
                        "user_id": "507f1f77bcf86cd799439033",
                        "user": {
                          "id": "507f1f77bcf86cd799439033",
                          "name": "Pedro Costa"
                        },
                        "value": 9
                      }
                    ],
                    "total_entries": 3,
                    "user_position": {
                      "rank": 45,
                      "user_id": "507f1f77bcf86cd799439099",
                      "user": {
                        "id": "507f1f77bcf86cd799439099",
                        "name": "Your User"
                      },
                      "value": 1
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid leaderboard query",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "invalidType": {
                    "value": {
                      "error": {
                        "type": "invalid_type",
                        "message": "Leaderboard type must be 'points', 'challenges', or 'badges'"
                      }
                    }
                  },
                  "validation": {
                    "value": {
                      "error": {
                        "type": "validation_error",
                        "message": "Invalid leaderboard query"
                      }
                    }
                  },
                  "metadata": {
                    "value": {
                      "error": {
                        "type": "invalid_metadata_filter",
                        "message": "Invalid metadata filter key: $where"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/guilds": {
      "get": {
        "tags": [
          "Guilds"
        ],
        "operationId": "listGuilds",
        "summary": "List guilds",
        "description": "Returns the guilds of the project ranked by `total_xp` (cursor\npagination). Deleted guilds are never listed.\n\n### How guilds progress\n\nA user belongs to at most one guild per project. The guild earns 10% of\nthe points its members generate (challenge completions and\n`points.added`) as XP, multiplied by the best active `xp_boost` perk.\nLevel = ⌊√(XP ÷ 100)⌋ + 1; reaching a new level emits\n`guild.level_up` once.\n\nPerks unlock by level and the best active perk of each type applies:\n\n| Type | Value | Effect |\n|------|-------|--------|\n| `challenge_points_multiplier` | multiplier 1–5 (1.1 = +10%) | Challenge points of every member |\n| `xp_boost` | multiplier 1–5 | XP a member generates for the guild |\n| `reward_discount` | fraction 0–0.9 (0.1 = 10% off) | Points price of `POST /v1/rewards/{id}/redeem` (the discounted part rounds down) |\n\n**Permissions:** Secret Key\n",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/QueryLimit"
          },
          {
            "name": "starting_after",
            "in": "query",
            "description": "Guild ID returned as `next_cursor` by the previous page",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "search",
            "in": "query",
            "description": "Search guilds by name (case-insensitive)",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Guilds ranked by XP",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "has_more",
                    "next_cursor"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Guild"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      },
      "post": {
        "tags": [
          "Guilds"
        ],
        "operationId": "createGuild",
        "summary": "Create guild",
        "description": "Creates a guild. With `leader_id`, that user becomes the leader and\nfirst member (they must not belong to another guild). Without it, the\nguild starts without members.\n\n`slug` is generated from the name (accents removed, unique per project)\nwhen omitted. The default perks are `challenge_points_multiplier` 1.05\n(level 3), 1.10 (level 7) and 1.15 (level 12).\n\nThe first guild endpoints used camelCase; `leaderId`, `isPrivate`,\n`avatarUrl` and `maxMembers` are still accepted as aliases.\n\n**Permissions:** Secret Key\n",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GuildCreate"
              },
              "example": {
                "name": "Night Owls",
                "description": "Members who train after 9 PM.",
                "is_private": true,
                "leader_id": "507f1f77bcf86cd799439011",
                "perks": [
                  {
                    "min_level": 2,
                    "type": "xp_boost",
                    "value": 1.2
                  },
                  {
                    "min_level": 5,
                    "type": "reward_discount",
                    "value": 0.1
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Guild created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Guild"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/GuildForbidden"
          },
          "404": {
            "$ref": "#/components/responses/UserNotFound"
          },
          "409": {
            "description": "The leader already belongs to a guild, or the slug is taken",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "alreadyInGuild": {
                    "value": {
                      "error": {
                        "type": "user_already_in_guild",
                        "message": "The user already belongs to a guild in this project"
                      }
                    }
                  },
                  "slugTaken": {
                    "value": {
                      "error": {
                        "type": "resource_conflict",
                        "message": "A resource with the same unique identifier already exists"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/guilds/{id}": {
      "get": {
        "tags": [
          "Guilds"
        ],
        "operationId": "getGuildById",
        "summary": "Get guild",
        "description": "Returns a guild with its member count, level progress and perks.\n\n**Permissions:** Secret Key\n",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/GuildId"
          }
        ],
        "responses": {
          "200": {
            "description": "Guild details",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Guild"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/GuildNotFound"
          }
        }
      },
      "patch": {
        "tags": [
          "Guilds"
        ],
        "operationId": "updateGuild",
        "summary": "Update guild",
        "description": "Updates any subset of the fields. `perks` replaces the whole list.\nPrivate guilds (`is_private`) only accept users through an invite in the\nhosted portal; the API can always add members.\n\n**Permissions:** Secret Key\n",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/GuildId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GuildUpdate"
              },
              "example": {
                "is_private": false,
                "max_members": 80
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Guild updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Guild"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/GuildNotFound"
          }
        }
      },
      "delete": {
        "tags": [
          "Guilds"
        ],
        "operationId": "deleteGuild",
        "summary": "Delete guild",
        "description": "Soft-deletes the guild and removes its memberships, so members can join\nanother guild.\n\n**Permissions:** Secret Key\n",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/GuildId"
          }
        ],
        "responses": {
          "200": {
            "description": "Guild deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "id",
                        "deleted"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "deleted": {
                          "type": "boolean",
                          "example": true
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/GuildNotFound"
          }
        }
      }
    },
    "/guilds/{id}/members": {
      "get": {
        "tags": [
          "Guilds"
        ],
        "operationId": "listGuildMembers",
        "summary": "List members",
        "description": "Returns the members: leader first, then officers, then members by\ncontributed XP.\n\n**Permissions:** Secret Key\n",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/GuildId"
          },
          {
            "$ref": "#/components/parameters/QueryLimit"
          },
          {
            "name": "starting_after",
            "in": "query",
            "description": "Member ID returned as `next_cursor` by the previous page",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Members",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "has_more",
                    "next_cursor"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/GuildMember"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/GuildNotFound"
          }
        }
      },
      "post": {
        "tags": [
          "Guilds"
        ],
        "operationId": "addGuildMember",
        "summary": "Add member",
        "description": "Adds a user of the project to the guild with a role. Works for private\nguilds too (the project is adding the user).\n\n- `leader` transfers the leadership: the previous leader becomes an\n  officer.\n- A user belongs to at most one guild per project.\n\n`userId` is still accepted as an alias of `user_id`.\n\n**Permissions:** Secret Key\n",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/GuildId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "user_id"
                ],
                "properties": {
                  "user_id": {
                    "type": "string",
                    "description": "ID of the user to add"
                  },
                  "role": {
                    "type": "string",
                    "enum": [
                      "member",
                      "officer",
                      "leader"
                    ],
                    "default": "member",
                    "description": "Case-insensitive"
                  }
                }
              },
              "example": {
                "user_id": "507f1f77bcf86cd799439022",
                "role": "officer"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Member added",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/GuildMember"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "Guild or user not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "guild": {
                    "value": {
                      "error": {
                        "type": "guild_not_found",
                        "message": "Guild not found"
                      }
                    }
                  },
                  "user": {
                    "value": {
                      "error": {
                        "type": "user_not_found",
                        "message": "User not found in this project"
                      }
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "The user already belongs to a guild, or the guild is full",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "alreadyInGuild": {
                    "value": {
                      "error": {
                        "type": "user_already_in_guild",
                        "message": "The user already belongs to a guild in this project"
                      }
                    }
                  },
                  "full": {
                    "value": {
                      "error": {
                        "type": "guild_full",
                        "message": "The guild reached max_members"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/guilds/{id}/members/{userId}": {
      "patch": {
        "tags": [
          "Guilds"
        ],
        "operationId": "updateGuildMemberRole",
        "summary": "Update member role",
        "description": "Changes a member's role. `leader` transfers the leadership (the\nprevious leader becomes an officer). The current leader cannot be\ndemoted directly: transfer the leadership first.\n\n**Permissions:** Secret Key\n",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/GuildId"
          },
          {
            "$ref": "#/components/parameters/MemberUserId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "role"
                ],
                "properties": {
                  "role": {
                    "type": "string",
                    "enum": [
                      "member",
                      "officer",
                      "leader"
                    ],
                    "description": "Case-insensitive"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Role updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/GuildMember"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/MemberNotFound"
          },
          "409": {
            "$ref": "#/components/responses/LeadershipTransferRequired"
          }
        }
      },
      "delete": {
        "tags": [
          "Guilds"
        ],
        "operationId": "removeGuildMember",
        "summary": "Remove member",
        "description": "Removes a member. The leader of a guild with other members must\ntransfer the leadership first. When the leader is the only member of a\nnon-official guild, the guild is deleted.\n\n**Permissions:** Secret Key\n",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/GuildId"
          },
          {
            "$ref": "#/components/parameters/MemberUserId"
          }
        ],
        "responses": {
          "200": {
            "description": "Member removed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "guild_id",
                        "user_id",
                        "removed"
                      ],
                      "properties": {
                        "guild_id": {
                          "type": "string"
                        },
                        "user_id": {
                          "type": "string"
                        },
                        "removed": {
                          "type": "boolean",
                          "example": true
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/MemberNotFound"
          },
          "409": {
            "$ref": "#/components/responses/LeadershipTransferRequired"
          }
        }
      }
    },
    "/guilds/{id}/transfer-leadership": {
      "post": {
        "tags": [
          "Guilds"
        ],
        "operationId": "transferGuildLeadership",
        "summary": "Transfer leadership",
        "description": "Makes a member the leader. The previous leader becomes an officer.\nGuilds without a leader (created without `leader_id`) gain one.\n\n`userId` is still accepted as an alias of `user_id`.\n\n**Permissions:** Secret Key\n",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/GuildId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "user_id"
                ],
                "properties": {
                  "user_id": {
                    "type": "string",
                    "description": "Member who becomes the leader"
                  }
                }
              },
              "example": {
                "user_id": "507f1f77bcf86cd799439022"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Leadership transferred",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Guild"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/MemberNotFound"
          }
        }
      }
    },
    "/community-goals": {
      "get": {
        "operationId": "listCommunityGoals",
        "summary": "List community goals",
        "description": "Returns the community goals of the project, newest first.\n\nBy default (`status=open`) only goals that currently accept\ncontributions are returned: `active` or `scheduled` goals whose start\ndate has passed and whose end date has not. Use `status=all` to include\nevery goal (finished ones too) or filter by a single status.\n\nStatuses are kept current automatically: a goal whose `end_date` passes\nbefore reaching the target becomes `failed` (daily routine plus a lazy\ncheck on every read), and a `scheduled` goal becomes `active` at its\n`start_date`.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Community Goals"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "description": "`open` (default) = goals accepting contributions now; `all` = every\ngoal; any other value filters by that status.\n",
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "all",
                "scheduled",
                "active",
                "completed",
                "failed"
              ],
              "default": "open"
            }
          },
          {
            "name": "metric_type",
            "in": "query",
            "description": "Filter goals by tracked metric type",
            "schema": {
              "type": "string",
              "enum": [
                "challenge-completions",
                "points-earned"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Community goals",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/CommunityGoal"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "operationId": "createCommunityGoal",
        "summary": "Create community goal",
        "description": "Creates a goal shared by every user of the project.\n\n### How progress works\n\n| `metric_type` | Each event adds |\n|---------------|-----------------|\n| `challenge-completions` | `1` per `challenge.completed` |\n| `points-earned` | `points_earned` of `challenge.completed` and `amount` of `points.added` |\n\nEach contribution is also added to the user's own total, which feeds\nthe goal leaderboard. Contributions stop when the goal finishes.\n\n### Completion and reward\n\nWhen `current_value` reaches `target_value`, the goal becomes\n`completed` and emits `community_goal.completed` exactly once with\n`{ goal_id, title, target_value, contributors_count }`.\n\nIf a `reward` is configured, every contributor whose own contribution\nreached `reward.min_contribution` receives it once:\n\n- `reward.points` are credited to the balance, emitting `points.added`\n  with `source: \"community_goal\"`. These points never count as\n  contributions to other goals.\n- `reward.reward_id` is granted as a free redemption (no points charged),\n  emitting `reward.redeemed` with `points_spent: 0` and\n  `source: \"community_goal\"`. Fulfill it from that webhook.\n\nDistribution is resumable: `reward_status` is `pending` while it runs\nand `distributed` once every eligible contributor was processed.\n\nA goal whose `start_date` is in the future starts as `scheduled`.\n\n**Permissions:** Secret Key\n",
        "tags": [
          "Community Goals"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CommunityGoalCreate"
              },
              "example": {
                "title": "500 workouts this month",
                "description": "Hit the target together and everyone who joined earns a bonus.",
                "metric_type": "challenge-completions",
                "target_value": 500,
                "end_date": "2026-11-30T23:59:59Z",
                "reward": {
                  "points": 100,
                  "min_contribution": 3
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Community goal created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CommunityGoal"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/GoalBadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/GoalRewardNotFound"
          }
        }
      }
    },
    "/community-goals/{id}": {
      "get": {
        "operationId": "getCommunityGoal",
        "summary": "Get community goal",
        "description": "Returns one community goal, in any status.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Community Goals"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Community goal",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CommunityGoal"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/GoalNotFound"
          }
        }
      },
      "patch": {
        "operationId": "updateCommunityGoal",
        "summary": "Update community goal",
        "description": "Updates any subset of the fields. Send `null` to clear `description`,\n`start_date`, `end_date`, `reward` or `metadata`.\n\n- Lowering `target_value` to or below `current_value` completes the goal\n  immediately (event and reward included).\n- `metric_type` cannot change after the goal received contributions\n  (`metric_locked`).\n- A finished goal (`completed` or `failed`) only accepts `title`,\n  `description`, `active` and `metadata` (`goal_finished`).\n- `active: false` pauses the goal: it stops receiving contributions.\n\n**Permissions:** Secret Key\n",
        "tags": [
          "Community Goals"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CommunityGoalUpdate"
              },
              "example": {
                "target_value": 400,
                "end_date": "2026-12-15T23:59:59Z"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Community goal updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CommunityGoal"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/GoalBadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "Community goal or reward not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "goal": {
                    "value": {
                      "error": {
                        "type": "community_goal_not_found",
                        "message": "Community goal '507f1f77bcf86cd799439060' not found"
                      }
                    }
                  },
                  "reward": {
                    "value": {
                      "error": {
                        "type": "reward_not_found",
                        "message": "reward.reward_id does not match a reward of this project"
                      }
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "The change is not allowed in the current state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "metricLocked": {
                    "value": {
                      "error": {
                        "type": "metric_locked",
                        "message": "The metric cannot change after the goal received contributions"
                      }
                    }
                  },
                  "goalFinished": {
                    "value": {
                      "error": {
                        "type": "goal_finished",
                        "message": "A finished goal only accepts title, description, active and metadata changes"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteCommunityGoal",
        "summary": "Delete community goal",
        "description": "Soft-deletes the goal: it stops receiving contributions and leaves every\nlist. Rewards already granted are kept.\n\n**Permissions:** Secret Key\n",
        "tags": [
          "Community Goals"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Community goal deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "id",
                        "deleted"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "deleted": {
                          "type": "boolean",
                          "example": true
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/GoalNotFound"
          }
        }
      }
    },
    "/community-goals/{id}/leaderboard": {
      "get": {
        "operationId": "getCommunityGoalLeaderboard",
        "summary": "Get community goal leaderboard",
        "description": "Returns the top contributors of a goal by their own contribution.\n\nRemoved users are excluded. Ties share the same rank and the next rank\nskips (\"1224\" competition ranking).\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Community Goals"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Maximum number of leaderboard entries returned",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Community goal leaderboard",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "goal_id",
                        "entries",
                        "total_entries"
                      ],
                      "properties": {
                        "goal_id": {
                          "type": "string"
                        },
                        "entries": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/CommunityGoalLeaderboardEntry"
                          }
                        },
                        "total_entries": {
                          "type": "integer",
                          "description": "Number of entries returned"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/GoalNotFound"
          }
        }
      }
    },
    "/countdowns": {
      "get": {
        "operationId": "listCountdowns",
        "summary": "List countdowns",
        "description": "Returns the countdowns of the project, soonest `end_time` first.\nDeleted countdowns are never listed.\n\nEvery countdown has a public screen at `/public-countdown/{id}` on the\nproject's portal host (TV, kiosk or second screen, no login) and a\nmatching keyless JSON endpoint `GET /api/public-countdowns/{id}` on the\nsame host, which exposes only the name and timing.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Countdowns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "Items per page",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "page",
            "in": "query",
            "description": "Page number (1-based)",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "active",
            "in": "query",
            "description": "Filter by the `active` flag",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Countdowns",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "has_more",
                    "page",
                    "total"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Countdown"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "page": {
                      "type": "integer"
                    },
                    "total": {
                      "type": "integer",
                      "description": "Countdowns matching the filter"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "operationId": "createCountdown",
        "summary": "Create countdown",
        "description": "Creates a timer that linked challenges extend (or shorten) on every\ncompletion.\n\n### Time increments\n\nEach completion of a challenge listed in `challenge_time_increments`\nadds `amount` × `unit` to `end_time` (a negative `amount` shortens it).\nOnly countdowns that are `active` and still have **at least five\nminutes** left are changed, so the end stays predictable. Each increment\nis limited to 366 days, and every `challenge_id` must belong to this\nproject.\n\nWorkspaces billed by a Studio plan that does not include countdowns\nreceive `plan_upgrade_required`.\n\n**Permissions:** Secret Key\n",
        "tags": [
          "Countdowns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CountdownCreate"
              },
              "example": {
                "name": "Launch week",
                "end_time": "2026-11-30T23:00:00Z",
                "challenge_time_increments": [
                  {
                    "challenge_id": "507f1f77bcf86cd799439033",
                    "amount": 5,
                    "unit": "minutes"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Countdown created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Countdown"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/CountdownForbidden"
          },
          "404": {
            "$ref": "#/components/responses/ChallengeNotFound"
          }
        }
      }
    },
    "/countdowns/{id}": {
      "get": {
        "operationId": "getCountdown",
        "summary": "Get countdown",
        "description": "Returns one countdown with its current `state` and `remaining_seconds`.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Countdowns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Countdown",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Countdown"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/CountdownNotFound"
          }
        }
      },
      "patch": {
        "operationId": "updateCountdown",
        "summary": "Update countdown",
        "description": "Updates any subset of the fields. `challenge_time_increments` replaces\nthe whole list. Re-activating (`active: true`) follows the same plan\nrule as creating.\n\n**Permissions:** Secret Key\n",
        "tags": [
          "Countdowns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CountdownUpdate"
              },
              "example": {
                "end_time": "2026-12-01T02:00:00Z"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Countdown updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Countdown"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/CountdownForbidden"
          },
          "404": {
            "description": "Countdown or linked challenge not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "countdown": {
                    "value": {
                      "error": {
                        "type": "countdown_not_found",
                        "message": "Countdown '507f1f77bcf86cd799439080' not found"
                      }
                    }
                  },
                  "challenge": {
                    "value": {
                      "error": {
                        "type": "challenge_not_found",
                        "message": "One or more challenge_id values do not match a challenge of this project",
                        "details": {
                          "challenge_ids": [
                            "507f1f77bcf86cd799439033"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteCountdown",
        "summary": "Delete countdown",
        "description": "Soft-deletes the countdown: it stops running, leaves every list and its\npublic screen returns `404`.\n\n**Permissions:** Secret Key\n",
        "tags": [
          "Countdowns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Countdown deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "id",
                        "deleted"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "deleted": {
                          "type": "boolean",
                          "example": true
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/CountdownNotFound"
          }
        }
      }
    },
    "/referral/validate": {
      "post": {
        "operationId": "validateReferralCode",
        "summary": "Validate referral code",
        "description": "Validates whether a referral code exists and returns the promoter details\nwhen the code is valid. Codes are case-insensitive.\n\nUseful during signup flows before creating the user with\n`POST /v1/users` and `referral_code`.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Referrals"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "code"
                ],
                "properties": {
                  "code": {
                    "type": "string",
                    "minLength": 6,
                    "maxLength": 12,
                    "example": "FRIEND01"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Referral validation result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ReferralValidationResponse"
                    }
                  }
                },
                "examples": {
                  "valid": {
                    "value": {
                      "data": {
                        "valid": true,
                        "promoter": {
                          "id": "507f1f77bcf86cd799439011",
                          "name": "John Smith",
                          "referralCode": "FRIEND01"
                        }
                      }
                    }
                  },
                  "invalid": {
                    "value": {
                      "data": {
                        "valid": false
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/referral/config": {
      "get": {
        "operationId": "getReferralConfig",
        "summary": "Get referral configuration",
        "description": "Returns the points of the referral program.\n\n### How referrals convert\n\n1. A new user is created with the code of an existing user\n   (`POST /v1/users` with `referral_code`), or signs up in the hosted\n   portal through the public invite link `/invite/{code}` (the link\n   keeps the code, opens the sign-in and attributes the account created\n   there; existing accounts are never re-attributed).\n2. On the new user's first challenge completion, both receive points:\n   `referrer_points` for the promoter and `referee_points` for the new\n   user. Each credit emits `points.added`, and the conversion emits\n   `referral.converted` with `promoter_points` and `referred_points`.\n\nThe defaults are 50 and 50.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Referrals"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Referral configuration",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ReferralConfig"
                    }
                  }
                },
                "example": {
                  "data": {
                    "referrer_points": 50,
                    "referee_points": 50,
                    "conversion": "first_challenge_completion"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "put": {
        "operationId": "updateReferralConfig",
        "summary": "Update referral configuration",
        "description": "Changes the points of the referral program. Send one or both values.\n`0` disables the credit for that side. Pending invites convert with the\nvalues in effect at conversion time.\n\n**Permissions:** Secret Key\n",
        "tags": [
          "Referrals"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "minProperties": 1,
                "properties": {
                  "referrer_points": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 100000,
                    "description": "Points for the user who shared the code"
                  },
                  "referee_points": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 100000,
                    "description": "Points for the new user on the first challenge completion"
                  }
                }
              },
              "example": {
                "referrer_points": 100,
                "referee_points": 30
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Referral configuration updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ReferralConfig"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/season-passes/current": {
      "get": {
        "operationId": "getCurrentSeasonPass",
        "summary": "Get current season pass",
        "description": "Returns the active season pass for the project.\n\nUse this endpoint to render the current pass configuration, levels,\nfree rewards, and premium rewards in client applications.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Season Passes"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Active season pass",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SeasonPass"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "No active season pass found",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "example": "not_found"
                        },
                        "message": {
                          "type": "string",
                          "example": "No active season pass found"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/season-passes": {
      "get": {
        "operationId": "listSeasonPasses",
        "summary": "List season passes",
        "description": "Returns every season pass of the project, newest first.\n\nA season pass is a time-boxed track of levels. Users earn season XP\nfrom the points of their challenge completions (and from\n`POST /v1/users/{id}/points/add`) while the pass is running. Each level\ncan point to a free reward and a premium reward; reaching a level makes\nits rewards claimable with `POST /v1/users/{id}/season-pass/claim`.\nOnly one active pass may run at a time.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Season Passes"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "active",
            "in": "query",
            "description": "Only active passes",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Season passes",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SeasonPass"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "operationId": "createSeasonPass",
        "summary": "Create season pass",
        "description": "Creates a season pass. Level rewards must be rewards of this project.\n`premium_currency: points` charges `premium_price` points from the\nuser's balance on upgrade; `BRL` is never charged by Experi: your\nbackend confirms the payment and records it with\n`POST /v1/users/{id}/season-pass/premium`.\n\nRules: 1–100 levels with unique numbers; a higher level cannot require\nless XP than a lower one; `end_date` after `start_date`; an active pass\ncannot overlap another active pass (`409 season_overlap`).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Season Passes"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SeasonPassCreate"
              },
              "example": {
                "name": "Summer Season 2026",
                "description": "Beach-themed rewards",
                "start_date": "2026-12-01T00:00:00-03:00",
                "end_date": "2027-02-28T23:59:59-03:00",
                "premium_price": 500,
                "premium_currency": "points",
                "levels": [
                  {
                    "level": 1,
                    "xp_required": 100,
                    "free_reward_id": "507f1f77bcf86cd799439030"
                  },
                  {
                    "level": 2,
                    "xp_required": 300,
                    "free_reward_id": "507f1f77bcf86cd799439031",
                    "premium_reward_id": "507f1f77bcf86cd799439032"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Season pass created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SeasonPass"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "`reward_not_found`: a level reward does not exist in this project."
          },
          "409": {
            "description": "`season_overlap` or `season_name_taken`."
          }
        }
      }
    },
    "/season-passes/{id}": {
      "get": {
        "operationId": "getSeasonPass",
        "summary": "Get season pass",
        "description": "**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Season Passes"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Season pass",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SeasonPass"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "`season_pass_not_found`"
          }
        }
      },
      "patch": {
        "operationId": "updateSeasonPass",
        "summary": "Update season pass",
        "description": "Updates a season pass. Sending `levels` replaces the whole level list.\nUsers keep their season XP and claimed levels. `premium_price: null`\nremoves the premium price.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Season Passes"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SeasonPassUpdate"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated season pass",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SeasonPass"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "`season_pass_not_found` or `reward_not_found`"
          },
          "409": {
            "description": "`season_overlap` or `season_name_taken`"
          }
        }
      },
      "delete": {
        "operationId": "deleteSeasonPass",
        "summary": "Delete season pass",
        "description": "Archives the pass. Rewards already claimed stay in the users' history.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Season Passes"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "deleted": {
                          "type": "boolean"
                        },
                        "id": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "`season_pass_not_found`"
          }
        }
      }
    },
    "/tiers": {
      "get": {
        "operationId": "getTierConfig",
        "summary": "Get tier configuration",
        "description": "Returns the project's tier ladder and qualification rules.\n\nA user sits in the highest tier whose `min_xp` is less than or equal to\ntheir **qualifying XP**. Qualifying XP is the sum of the points of the\nuser's challenge completions inside the qualification window:\n\n| `qualification_window.type` | Qualifying XP |\n|---|---|\n| `lifetime` | All XP ever earned (never decreases) |\n| `rolling` | Completions in the last `days` days |\n| `calendar` | Completions since January 1st of the current year, in the project's timezone |\n\nPromotions are immediate. When qualifying XP stops sustaining the\ncurrent tier, the user enters a grace period of `grace_period_days`\nand is demoted only if they do not recover before it ends. Both\npromotions and demotions emit `tier.changed`.\n\nThe tier multiplier multiplies the points of every challenge\ncompletion. Fractions are carried per user, so a 1.1 multiplier pays\nexactly 10% more over time.\n\nWith a Secret Key, each tier also includes `users` (how many users are\nin it now).\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Tiers"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Tier configuration",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/TierConfig"
                    }
                  }
                },
                "example": {
                  "data": {
                    "enabled": true,
                    "qualification_window": {
                      "type": "rolling",
                      "days": 365
                    },
                    "grace_period_days": 30,
                    "tiers": [
                      {
                        "slug": "bronze",
                        "name": "Bronze",
                        "min_xp": 0,
                        "multiplier": 1,
                        "color": "#B45309",
                        "icon": null,
                        "benefits": [],
                        "users": 1840
                      },
                      {
                        "slug": "gold",
                        "name": "Gold",
                        "min_xp": 1000,
                        "multiplier": 1.2,
                        "color": "#CA8A04",
                        "icon": "crown",
                        "benefits": [
                          "Priority support"
                        ],
                        "users": 212
                      }
                    ]
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "put": {
        "operationId": "replaceTierConfig",
        "summary": "Replace tier configuration",
        "description": "Replaces the whole tier configuration. Users are re-evaluated right\naway within a short time budget; `reevaluation.complete: false` means\nthe remaining users are re-evaluated by the daily maintenance run.\n\nRules: up to 10 tiers, unique `slug` (lowercase letters, numbers and\nhyphens) and unique `min_xp`; the entry tier must start at `min_xp: 0`;\n`multiplier` between 1 and 5; `days` (rolling window) between 1 and\n3650; `grace_period_days` between 0 and 365.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Tiers"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TierConfigInput"
              },
              "example": {
                "enabled": true,
                "qualification_window": {
                  "type": "rolling",
                  "days": 365
                },
                "grace_period_days": 30,
                "tiers": [
                  {
                    "slug": "bronze",
                    "name": "Bronze",
                    "min_xp": 0,
                    "multiplier": 1
                  },
                  {
                    "slug": "silver",
                    "name": "Silver",
                    "min_xp": 300,
                    "multiplier": 1.1,
                    "benefits": [
                      "Free shipping"
                    ]
                  },
                  {
                    "slug": "gold",
                    "name": "Gold",
                    "min_xp": 1000,
                    "multiplier": 1.2,
                    "color": "#CA8A04"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved configuration",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/TierConfig"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "reevaluation": {
                              "type": "object",
                              "properties": {
                                "users_evaluated": {
                                  "type": "integer"
                                },
                                "complete": {
                                  "type": "boolean"
                                }
                              }
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/streaks": {
      "get": {
        "operationId": "listStreaks",
        "summary": "List streaks",
        "description": "Returns the streak definitions of the project with the challenges that\nfeed each one (`challenge_ids`).\n\nA streak advances when the user completes any linked challenge\n(through any completion path: QR, `POST /v1/actions/track`,\n`POST /v1/challenges/{id}/complete`, survey answers). Periods follow\nthe project's timezone: `daily` counts calendar days, `weekly` ISO\nweeks (from Monday) and `monthly` calendar months.\n\n- Completing again in the same cycle changes nothing.\n- Completing in the next allowed period, or within `tolerance_hours`\n  after it ends, adds 1.\n- Missing the deadline breaks the streak: it is marked `broken`, its\n  value becomes 0 and `streak.broken` is emitted (by the daily run or\n  on the next read/completion, whichever comes first).\n\nThe link also lives on the challenge: `streak_ids` in\n`POST /v1/challenges` and `PATCH /v1/challenges/{id}`.\n\nWith a Secret Key, each streak includes `stats` (participants, users\nwith a live streak and the best streak ever).\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Streaks"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "active",
            "in": "query",
            "description": "Only active streaks",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Streak definitions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Streak"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "operationId": "createStreak",
        "summary": "Create streak",
        "description": "Creates a streak definition and, optionally, links challenges to it in\nthe same call (`challenge_ids` replaces nothing on creation: it sets\n`streak_ids` on each listed challenge).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Streaks"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StreakCreate"
              },
              "example": {
                "name": "Daily practice",
                "description": "Complete one lesson every day",
                "frequency": {
                  "type": "daily",
                  "interval": 1,
                  "tolerance_hours": 6
                },
                "challenge_ids": [
                  "507f1f77bcf86cd799439031"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Streak created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Streak"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "`challenge_not_found`: a listed challenge does not exist in this project."
          },
          "409": {
            "description": "`streak_name_taken`: another streak already uses this name."
          }
        }
      }
    },
    "/streaks/{id}": {
      "get": {
        "operationId": "getStreak",
        "summary": "Get streak",
        "description": "**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Streaks"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Streak",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Streak"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "`streak_not_found`"
          }
        }
      },
      "patch": {
        "operationId": "updateStreak",
        "summary": "Update streak",
        "description": "Updates a streak. When `challenge_ids` is sent it **replaces** the\nlinked set: challenges not in the list stop feeding the streak.\nChanging the frequency applies from the next completion on; streaks\nin progress keep their values.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Streaks"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StreakUpdate"
              },
              "example": {
                "frequency": {
                  "tolerance_hours": 12
                },
                "challenge_ids": [
                  "507f1f77bcf86cd799439031",
                  "507f1f77bcf86cd799439032"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated streak",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Streak"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "`streak_not_found` or `challenge_not_found`"
          },
          "409": {
            "description": "`streak_name_taken`"
          }
        }
      },
      "delete": {
        "operationId": "deleteStreak",
        "summary": "Delete streak",
        "description": "Archives the streak and removes it from every challenge's\n`streak_ids`. Users' past streak records are kept.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Streaks"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "deleted": {
                          "type": "boolean"
                        },
                        "id": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "`streak_not_found`"
          }
        }
      }
    },
    "/surveys": {
      "get": {
        "operationId": "listSurveys",
        "summary": "List surveys",
        "description": "Returns a paginated list of published surveys.\n\nOnly published and non-archived surveys are returned.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Surveys"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/QueryLimit"
          },
          {
            "$ref": "#/components/parameters/QueryStartingAfter"
          },
          {
            "name": "metadata[key]",
            "in": "query",
            "description": "Filter by metadata fields. Use `metadata[field]=value` to filter \nby specific fields. Example: `metadata[campaign]=summer2025` filters \nsurveys where `metadata.campaign == 'summer2025'`. Multiple filters can \nbe combined.\n",
            "schema": {
              "type": "string"
            },
            "style": "deepObject",
            "explode": true
          }
        ],
        "responses": {
          "200": {
            "description": "List of surveys",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Survey"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "507f1f77bcf86cd799439050",
                      "title": "Satisfaction Survey",
                      "description": "We want to know your opinion about our services",
                      "questions": [
                        {
                          "question": "How do you rate our customer service?",
                          "type": "5-star-rating",
                          "required": true
                        },
                        {
                          "question": "What can we improve?",
                          "type": "long-text",
                          "required": false
                        },
                        {
                          "question": "What is your preferred customer service channel?",
                          "type": "radio",
                          "options": [
                            "WhatsApp",
                            "Email",
                            "Phone",
                            "Chat"
                          ],
                          "required": true
                        },
                        {
                          "question": "Which products do you use the most?",
                          "type": "checkbox",
                          "options": [
                            "Product A",
                            "Product B",
                            "Product C"
                          ],
                          "allow_custom_option": true,
                          "required": false
                        }
                      ],
                      "responses_count": 42,
                      "published_at": "2024-01-01T00:00:00Z",
                      "created_at": "2024-01-01T00:00:00Z",
                      "updated_at": "2024-01-01T00:00:00Z"
                    }
                  ],
                  "has_more": false
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "operationId": "createSurvey",
        "summary": "Create survey",
        "description": "Creates a survey. Surveys created through the API are **published\nimmediately**: they show up in `GET /surveys` and accept answers right away.\n\nLink the survey to a challenge with `POST /challenges` (`type: survey`,\n`survey_id`) to award points when a user answers it.\n\n### Rules\n\n- 1 to 50 questions; 8 question types (see `SurveyQuestion`).\n- `radio` and `checkbox` need 2 to 30 unique options. `allow_custom_option`\n  adds a free-text \"Other\" answer and is only valid for these two types.\n- `required` defaults to `true`.\n- Questions lock after the first answer (`PATCH` returns `409 survey_locked`).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Surveys"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SurveyCreate"
              },
              "example": {
                "title": "Visit feedback",
                "description": "Takes less than a minute",
                "questions": [
                  {
                    "question": "How likely are you to recommend us to a friend?",
                    "type": "rating-0-10"
                  },
                  {
                    "question": "Which channel do you prefer?",
                    "type": "radio",
                    "options": [
                      "WhatsApp",
                      "Email"
                    ],
                    "allow_custom_option": true
                  },
                  {
                    "question": "Anything we could improve?",
                    "type": "long-text",
                    "required": false
                  }
                ],
                "metadata": {
                  "campaign": "october"
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Survey created and published",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Survey"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/surveys/{id}": {
      "get": {
        "operationId": "getSurvey",
        "summary": "Get survey",
        "description": "Returns the details of a specific survey.\n\nOnly published and non-archived surveys are returned.\n\n**Permissions:** Public Key or Secret Key\n",
        "tags": [
          "Surveys"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Survey details",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Survey"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "operationId": "updateSurvey",
        "summary": "Update survey",
        "description": "Updates the title, description, questions or metadata of a published\nsurvey. Send only the fields you want to change; `questions` replaces the\nwhole list and `metadata` replaces the stored object (`null` clears it).\n\nQuestions **lock after the first answer**: changing them returns\n`409 survey_locked` (title, description and metadata stay editable). To\nchange the questions of a survey that already has answers, create a new\nsurvey and point the challenge to it with `PATCH /challenges/{id}`.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Surveys"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SurveyUpdate"
              },
              "example": {
                "title": "Visit feedback (October)"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Survey updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Survey"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/SurveyNotFound"
          },
          "409": {
            "description": "Questions are locked because the survey already has answers",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SurveyError"
                },
                "example": {
                  "error": {
                    "type": "survey_locked",
                    "message": "Questions can't change after the survey receives its first answer. Create a new survey instead."
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "archiveSurvey",
        "summary": "Archive survey",
        "description": "Archives a survey. Archived surveys disappear from the API and stop\naccepting answers; existing answers and results are kept.\n\nA survey can't be archived while a (non-deleted) challenge uses it:\ndelete the challenge first (`DELETE /challenges/{id}`), otherwise the\nrequest returns `409 survey_in_use`.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Surveys"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Survey archived",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "id",
                        "archived",
                        "archived_at"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "archived": {
                          "type": "boolean",
                          "example": true
                        },
                        "archived_at": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/SurveyNotFound"
          },
          "409": {
            "description": "A challenge still uses the survey",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SurveyError"
                },
                "example": {
                  "error": {
                    "type": "survey_in_use",
                    "message": "A challenge still uses this survey. Delete the challenge (DELETE /v1/challenges/{id}) before archiving the survey."
                  }
                }
              }
            }
          }
        }
      }
    },
    "/surveys/{id}/results": {
      "get": {
        "operationId": "getSurveyResults",
        "summary": "Get survey results",
        "description": "Aggregated results of a survey, optionally limited to a date window.\n\nFor each question:\n\n| Type | Fields |\n|------|--------|\n| `rating-0-10` | `average`, `distribution` (0–10), `nps` and NPS per day |\n| `5-star-rating` | `average`, `distribution` (1–5) |\n| `integer` | `average`, `min`, `max`, `sum`, `distribution` |\n| `radio`, `checkbox` | `options` with configured options (including zero counts) and free answers (`custom: true`); checkbox answers count each selected option |\n| `short-text`, `long-text`, `date` | `responses` only (read the answers with `GET /surveys/{id}/answers`) |\n\n**NPS** = % promoters (9–10) − % detractors (0–6), rounded; passives are 7–8.\nDaily series use the workspace timezone (`timezone` in the response).\n\n**Permissions:** Secret Key only (business metrics)\n",
        "tags": [
          "Surveys"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "name": "from",
            "in": "query",
            "description": "Start of the window (ISO 8601 date or date-time). A date without time starts at midnight in the workspace timezone. Omit for all time.",
            "schema": {
              "type": "string",
              "example": "2026-10-01"
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "End of the window (ISO 8601). A date without time includes the whole day in the workspace timezone.",
            "schema": {
              "type": "string",
              "example": "2026-10-31"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Survey results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SurveyResults"
                    }
                  }
                },
                "example": {
                  "data": {
                    "survey_id": "507f1f77bcf86cd799439050",
                    "title": "Visit feedback",
                    "from": "2026-10-01T03:00:00.000Z",
                    "to": "2026-11-01T02:59:59.999Z",
                    "timezone": "America/Sao_Paulo",
                    "responses": 8,
                    "series": [
                      {
                        "date": "2026-10-01",
                        "responses": 4
                      },
                      {
                        "date": "2026-10-02",
                        "responses": 4
                      }
                    ],
                    "questions": [
                      {
                        "question_index": 0,
                        "question": "How likely are you to recommend us to a friend?",
                        "type": "rating-0-10",
                        "required": true,
                        "responses": 8,
                        "average": 7.38,
                        "min": null,
                        "max": null,
                        "sum": null,
                        "distribution": [
                          {
                            "value": "3",
                            "count": 2
                          },
                          {
                            "value": "7",
                            "count": 2
                          },
                          {
                            "value": "9",
                            "count": 1
                          },
                          {
                            "value": "10",
                            "count": 3
                          }
                        ],
                        "nps": {
                          "score": 25,
                          "promoters": 4,
                          "passives": 2,
                          "detractors": 2
                        },
                        "options": null,
                        "series": [
                          {
                            "date": "2026-10-01",
                            "responses": 4,
                            "average": 9.75,
                            "nps": 100
                          },
                          {
                            "date": "2026-10-02",
                            "responses": 4,
                            "average": 5,
                            "nps": -50
                          }
                        ]
                      },
                      {
                        "question_index": 1,
                        "question": "Which channel do you prefer?",
                        "type": "radio",
                        "required": true,
                        "responses": 8,
                        "average": null,
                        "min": null,
                        "max": null,
                        "sum": null,
                        "distribution": [],
                        "nps": null,
                        "options": [
                          {
                            "option": "WhatsApp",
                            "count": 5,
                            "custom": false
                          },
                          {
                            "option": "Email",
                            "count": 1,
                            "custom": false
                          },
                          {
                            "option": "Instagram",
                            "count": 2,
                            "custom": true
                          }
                        ],
                        "series": [
                          {
                            "date": "2026-10-01",
                            "responses": 4,
                            "average": null,
                            "nps": null
                          },
                          {
                            "date": "2026-10-02",
                            "responses": 4,
                            "average": null,
                            "nps": null
                          }
                        ]
                      }
                    ]
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/SurveyNotFound"
          }
        }
      }
    },
    "/surveys/{id}/answers": {
      "get": {
        "operationId": "listSurveyAnswers",
        "summary": "List survey answers",
        "description": "Returns all answers for a specific survey.\n\n**Permissions:** Secret Key only (contains personal data)\n",
        "tags": [
          "Surveys"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "$ref": "#/components/parameters/QueryLimit"
          },
          {
            "$ref": "#/components/parameters/QueryStartingAfter"
          }
        ],
        "responses": {
          "200": {
            "description": "List of answers",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SurveyAnswer"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "post": {
        "operationId": "submitSurveyAnswer",
        "summary": "Submit survey answer",
        "description": "Submits an answer for a specific survey.\n\nThe survey must be published and not archived.\nThe user cannot have answered the survey previously.\n\n### Completing a survey challenge\n\nSend `challenge_id` (a `survey` challenge linked to this survey) to\ncomplete the challenge with the answer: the user earns the challenge\npoints (tier multipliers apply) and the response includes\n`points_earned`. The challenge must be active, inside its dates and with\nits requirements met, otherwise the request returns\n`409 challenge_not_available`. Without `challenge_id` the answer is stored\nand no points are awarded.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Surveys"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "user_id",
                  "answers"
                ],
                "properties": {
                  "user_id": {
                    "type": "string",
                    "description": "ID of the user answering",
                    "example": "507f1f77bcf86cd799439011"
                  },
                  "challenge_id": {
                    "type": "string",
                    "description": "Optional `survey` challenge linked to this survey. The answer\ncompletes the challenge and awards its points.\n",
                    "example": "507f1f77bcf86cd799439020"
                  },
                  "answers": {
                    "type": "array",
                    "description": "List of answers for each question",
                    "items": {
                      "type": "object",
                      "required": [
                        "question_index",
                        "answer"
                      ],
                      "properties": {
                        "question_index": {
                          "type": "integer",
                          "minimum": 0,
                          "description": "Question index in the survey (0-based)",
                          "example": 0
                        },
                        "answer": {
                          "oneOf": [
                            {
                              "type": "string",
                              "description": "Text answer or single option"
                            },
                            {
                              "type": "array",
                              "items": {
                                "type": "string"
                              },
                              "description": "Multiple selected options (checkbox)"
                            },
                            {
                              "type": "number",
                              "description": "Numeric score (rating)"
                            }
                          ],
                          "description": "Question answer (format depends on the question type)",
                          "example": 5
                        }
                      }
                    }
                  }
                }
              },
              "example": {
                "user_id": "507f1f77bcf86cd799439011",
                "answers": [
                  {
                    "question_index": 0,
                    "answer": 5
                  },
                  {
                    "question_index": 1,
                    "answer": "I really liked the customer service"
                  },
                  {
                    "question_index": 2,
                    "answer": "WhatsApp"
                  },
                  {
                    "question_index": 3,
                    "answer": [
                      "Product A",
                      "Product C"
                    ]
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Answer submitted successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/SurveyAnswer"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "points_earned": {
                              "type": "integer",
                              "description": "Points awarded by the survey challenge (only when `challenge_id` was sent)",
                              "example": 20
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid data or user has already answered",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "message": {
                          "type": "string"
                        },
                        "code": {
                          "type": "string"
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "validation_error": {
                    "summary": "Validation error",
                    "value": {
                      "error": {
                        "message": "Invalid request body",
                        "code": "validation_error"
                      }
                    }
                  },
                  "already_answered": {
                    "summary": "User has already answered",
                    "value": {
                      "error": {
                        "message": "User has already answered this survey",
                        "code": "already_answered"
                      }
                    }
                  },
                  "missing_required": {
                    "summary": "Required question not answered",
                    "value": {
                      "error": {
                        "message": "Missing answer for required question at index 0",
                        "code": "missing_required_answer"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "The user already answered, or the survey challenge is not available",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SurveyError"
                },
                "examples": {
                  "already_answered": {
                    "summary": "User has already answered",
                    "value": {
                      "error": {
                        "type": "already_answered",
                        "message": "User has already answered this survey"
                      }
                    }
                  },
                  "challenge_not_available": {
                    "summary": "Survey challenge not available for the user",
                    "value": {
                      "error": {
                        "type": "challenge_not_available",
                        "message": "The survey challenge is not available for this user (inactive, outside its dates or requirements not met)"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/webhooks": {
      "get": {
        "operationId": "listWebhooks",
        "summary": "List webhooks",
        "description": "Returns all configured webhooks and the list of available events.\n\nThe response includes an `available_events` field with all event types\nthat can be subscribed to.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Webhooks"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of webhooks",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Webhook"
                      }
                    },
                    "available_events": {
                      "type": "array",
                      "description": "List of all event types that can be subscribed to",
                      "items": {
                        "type": "string"
                      },
                      "example": [
                        "user.created",
                        "user.updated",
                        "user.deleted",
                        "user.at_risk",
                        "user.reactivated",
                        "challenge.completed",
                        "badge.earned",
                        "badge.revoked",
                        "reward.redeemed",
                        "points.added",
                        "points.deducted",
                        "guild.level_up",
                        "season.level_up",
                        "referral.converted",
                        "winback.dispatched",
                        "survey.answered",
                        "action.tracked",
                        "tier.changed",
                        "streak.broken",
                        "season.reward_claimed",
                        "community_goal.completed",
                        "webhook.test"
                      ]
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "507f1f77bcf86cd799439012",
                      "url": "https://my-server.com/webhooks/experi",
                      "description": "Main webhook",
                      "secret": "whsec_abc123...",
                      "events": [
                        "*"
                      ],
                      "status": "active",
                      "failure_count": 0,
                      "last_delivery_at": "2026-02-20T18:30:00Z",
                      "last_delivery_status": "success",
                      "created_at": "2026-01-15T10:30:00Z",
                      "updated_at": "2026-02-20T18:30:00Z"
                    }
                  ],
                  "available_events": [
                    "user.created",
                    "user.updated",
                    "user.deleted",
                    "user.at_risk",
                    "user.reactivated",
                    "challenge.completed",
                    "badge.earned",
                    "badge.revoked",
                    "reward.redeemed",
                    "points.added",
                    "points.deducted",
                    "guild.level_up",
                    "season.level_up",
                    "referral.converted",
                    "winback.dispatched",
                    "survey.answered",
                    "action.tracked",
                    "tier.changed",
                    "streak.broken",
                    "season.reward_claimed",
                    "community_goal.completed",
                    "webhook.test"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      },
      "post": {
        "operationId": "createWebhook",
        "summary": "Create webhook",
        "description": "Creates a new webhook endpoint to receive event notifications.\n\n### Events\n\nEach webhook can subscribe to specific events or use `\"*\"` to receive all.\nEvents produced by an automation also carry an `automation` object\n(`rule_id`, `rule_ids`, `depth`) next to `data`:\n\n| Event | Description |\n|-------|-------------|\n| `user.created` | When a new user is registered |\n| `user.updated` | When a user's data is changed |\n| `user.deleted` | When a user is removed |\n| `user.at_risk` | When a user is flagged as churn risk |\n| `user.reactivated` | When an at-risk user re-engages |\n| `challenge.completed` | When a user completes a challenge |\n| `badge.earned` | When a user earns a badge |\n| `badge.revoked` | When a badge is removed from a user |\n| `reward.redeemed` | When a user redeems a reward |\n| `points.added` | When points are added to a user |\n| `points.deducted` | When points are deducted from a user |\n| `guild.level_up` | When a guild reaches a new level |\n| `season.level_up` | When a user levels up in the active season pass |\n| `referral.converted` | When a referral becomes a rewarded conversion |\n| `winback.dispatched` | When a win-back campaign dispatch is recorded |\n| `survey.answered` | When a user answers a survey |\n| `action.tracked` | When an action is tracked via API |\n| `tier.changed` | When a user's tier changes |\n| `streak.broken` | When a user's streak is broken |\n| `season.reward_claimed` | When a user claims a season pass reward |\n| `community_goal.completed` | When a community goal is reached |\n| `webhook.test` | Test event sent to one endpoint (Send test) |\n| `*` | Wildcard — receives all events |\n\n### Limit\n\nEach tenant can have at most **5 webhooks** active simultaneously.\n\n### Signing Secret\n\nWhen creating a webhook, a `secret` (prefix `whsec_`) is automatically generated.\nUse it to verify the authenticity of received payloads (see the\n\"Signature Verification\" section in the Webhooks documentation).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Webhooks"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookCreate"
              },
              "examples": {
                "all_events": {
                  "summary": "All events",
                  "value": {
                    "url": "https://my-server.com/webhooks/experi",
                    "description": "Main webhook — all events",
                    "events": [
                      "*"
                    ]
                  }
                },
                "specific_events": {
                  "summary": "Specific events",
                  "value": {
                    "url": "https://my-server.com/webhooks/users",
                    "description": "User events only",
                    "events": [
                      "user.created",
                      "user.updated",
                      "user.deleted"
                    ]
                  }
                },
                "with_metadata": {
                  "summary": "With metadata",
                  "value": {
                    "url": "https://my-server.com/webhooks/experi",
                    "events": [
                      "reward.redeemed",
                      "challenge.completed"
                    ],
                    "metadata": {
                      "env": "production",
                      "team": "backend"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Webhook created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Webhook"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "507f1f77bcf86cd799439012",
                    "url": "https://my-server.com/webhooks/experi",
                    "description": "Main webhook — all events",
                    "secret": "whsec_a1b2c3d4e5f6...",
                    "events": [
                      "*"
                    ],
                    "status": "active",
                    "failure_count": 0,
                    "created_at": "2026-02-21T10:30:00Z",
                    "updated_at": "2026-02-21T10:30:00Z"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid data or limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "validation_error": {
                    "summary": "Validation error",
                    "value": {
                      "error": {
                        "type": "validation_error",
                        "message": "Invalid request body"
                      }
                    }
                  },
                  "limit_exceeded": {
                    "summary": "Webhook limit exceeded",
                    "value": {
                      "error": {
                        "type": "webhook_limit_exceeded",
                        "message": "Maximum number of webhooks reached for this tenant"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/webhooks/{id}": {
      "get": {
        "operationId": "getWebhook",
        "summary": "Get webhook",
        "description": "Returns the details of a specific webhook, including the signing secret.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Webhooks"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Webhook details",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Webhook"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "operationId": "updateWebhook",
        "summary": "Update webhook",
        "description": "Updates an existing webhook. Only the provided fields are changed.\n\nTo temporarily pause a webhook, send `status: \"paused\"`.\nTo reactivate, send `status: \"active\"`.\n\n> **Note:** Webhooks automatically disabled due to consecutive failures \n> (status `disabled`) cannot be reactivated via this endpoint.\n> Create a new webhook in that case.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Webhooks"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookUpdate"
              },
              "examples": {
                "pause": {
                  "summary": "Pause webhook",
                  "value": {
                    "status": "paused"
                  }
                },
                "change_events": {
                  "summary": "Change events",
                  "value": {
                    "events": [
                      "user.created",
                      "user.updated",
                      "badge.earned"
                    ]
                  }
                },
                "update_url": {
                  "summary": "Change URL",
                  "value": {
                    "url": "https://new-server.com/webhooks/experi"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Webhook updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Webhook"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "delete": {
        "operationId": "deleteWebhook",
        "summary": "Delete webhook",
        "description": "Permanently removes a webhook and all its delivery logs.\n\n**This action cannot be undone.**\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Webhooks"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Webhook deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "deleted": {
                          "type": "boolean",
                          "example": true
                        },
                        "id": {
                          "type": "string",
                          "example": "507f1f77bcf86cd799439012"
                        },
                        "events_deleted": {
                          "type": "integer",
                          "description": "Number of delivery logs removed",
                          "example": 42
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/campaigns": {
      "get": {
        "operationId": "listCampaigns",
        "summary": "List campaigns",
        "description": "Lists the project's campaigns, newest first. Archived campaigns are\nhidden unless `include_archived=true` or `status=archived`.\n\n**Permissions:** Public Key or Secret Key. With a public key, `metrics`\nis `null`.\n",
        "tags": [
          "Campaigns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/QueryLimit"
          },
          {
            "$ref": "#/components/parameters/QueryStartingAfter"
          },
          {
            "name": "goal",
            "in": "query",
            "description": "Filter by goal",
            "schema": {
              "type": "string",
              "enum": [
                "return",
                "feedback",
                "referral"
              ]
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Filter by status",
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "active",
                "paused",
                "archived"
              ]
            }
          },
          {
            "name": "include_archived",
            "in": "query",
            "description": "Include archived campaigns",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Campaigns",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Campaign"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "operationId": "createCampaign",
        "summary": "Create campaign",
        "description": "Provisions the whole loop in one call: the challenge, the reward (return,\nor feedback with a reward), the survey (feedback) and a QR code for the\ndistribution channels.\n\n| Goal | What each user gets |\n|------|---------------------|\n| `return` | +1 point per visit; every `visits_required` visits unlock one reward; unclaimed rewards accumulate |\n| `feedback` | `completion_points` for the single response; optional reward |\n| `referral` | `promoter_reward_points` / `referred_reward_points` when the invited user converts |\n\nThe campaign is published (`active`) unless `status: \"draft\"` is sent.\nWith `reward.catalog_reward_id`, the campaign keeps a private copy of a\ncatalog reward (remaining stock included): later catalog edits never\nchange a published campaign. The goal cannot change later.\n\nSend an `Idempotency-Key`: the same key always returns the same campaign.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Campaigns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CampaignCreate"
              },
              "examples": {
                "return": {
                  "summary": "Return loop",
                  "value": {
                    "goal": "return",
                    "title": "Train five times",
                    "channels": [
                      "counter"
                    ],
                    "visits_required": 5,
                    "visit_cooldown_hours": 20,
                    "reward": {
                      "title": "Free smoothie",
                      "monetary_cost": 9.9
                    }
                  }
                },
                "feedback": {
                  "summary": "Feedback with reward",
                  "value": {
                    "goal": "feedback",
                    "title": "How was your class?",
                    "channels": [
                      "counter",
                      "whatsapp"
                    ],
                    "survey": {
                      "title": "Class feedback",
                      "questions": [
                        {
                          "question": "Rate the class",
                          "type": "5-star-rating"
                        },
                        {
                          "question": "What should we improve?",
                          "type": "long-text",
                          "required": false
                        }
                      ]
                    },
                    "completion_points": 20,
                    "reward": {
                      "title": "10% off the next plan"
                    }
                  }
                },
                "referral": {
                  "summary": "Referral loop",
                  "value": {
                    "goal": "referral",
                    "title": "Bring a friend",
                    "channels": [
                      "whatsapp"
                    ],
                    "promoter_reward_points": 50,
                    "referred_reward_points": 50,
                    "conversion_event": "first-visit"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Campaign provisioned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Campaign"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/campaigns/{id}": {
      "get": {
        "operationId": "getCampaign",
        "summary": "Get campaign",
        "description": "Campaign with its rules, provisioned assets and lifetime metrics.\n`{id}` also accepts the campaign's `challenge_id`.\n\n**Permissions:** Public Key or Secret Key (public keys get `metrics: null`)\n",
        "tags": [
          "Campaigns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Campaign",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Campaign"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "operationId": "updateCampaign",
        "summary": "Update campaign",
        "description": "Partial update of the rules. Fields of the stored goal only; `goal`\nitself cannot change (`409 goal_mismatch`). Send `expected_version` to\ndetect concurrent edits (`409 stale_version`).\n\n- Changing `visits_required` recalculates every user's cycle.\n- Survey questions are locked after the first response (`409 survey_locked`).\n- Referral points and conversion event are frozen in pending invitations.\n- Archived campaigns are read-only.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Campaigns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CampaignUpdate"
              },
              "example": {
                "visits_required": 4,
                "reward": {
                  "title": "Free smoothie (large)"
                },
                "expected_version": 3
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Campaign updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Campaign"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/campaigns/{id}/status": {
      "post": {
        "operationId": "setCampaignStatus",
        "summary": "Activate, pause or archive",
        "description": "Transitions: `draft → active | paused | archived`, `active ⇄ paused`,\nany → `archived`. Archived is final (duplicate to start again). Pausing\nor archiving deactivates the challenge, the reward and the QR code; a\nscan of a paused campaign answers that it is unavailable.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Campaigns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "status"
                ],
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": [
                      "active",
                      "paused",
                      "archived"
                    ]
                  },
                  "expected_version": {
                    "type": "integer",
                    "minimum": 1
                  }
                }
              },
              "example": {
                "status": "paused"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Campaign with the new status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Campaign"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/campaigns/{id}/duplicate": {
      "post": {
        "operationId": "duplicateCampaign",
        "summary": "Duplicate campaign",
        "description": "Copies the rules into a new **draft** (\"Cópia de …\" unless `title` is\nsent), with its own challenge, reward, survey and QR code.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Campaigns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 80
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Draft copy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Campaign"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/campaigns/{id}/visits": {
      "post": {
        "operationId": "recordCampaignVisit",
        "summary": "Record a visit",
        "description": "Trusted, server-to-server visit of a user.\n\n- **Return:** one visit per `Idempotency-Key` (required). Respects\n  `visit_cooldown_hours` (`409 visit_cooldown` with\n  `next_available_at`), adds +1 point and XP, and closes a cycle every\n  `visits_required` visits (`reward_unlocked: true`). Emits\n  `challenge.completed`.\n- **Referral:** records the visit of an invited user; with\n  `conversion_event: first-visit`, it converts the pending invitation\n  (points for both users, `referral.converted`).\n- **Feedback:** not available (`409 goal_mismatch`); use\n  `POST /v1/campaigns/{id}/responses`.\n\nAny visit also converts the user's pending `first-visit` invitation;\nclosing a return cycle converts a pending `first-campaign-completion`\ninvitation. `occurred_at` accepts the last 30 days up to 5 minutes ahead.\nA replay with the same key answers `200` with `created: false`.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Campaigns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "One key per real visit (8–255 characters).",
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 255
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "user_id"
                ],
                "properties": {
                  "user_id": {
                    "type": "string"
                  },
                  "occurred_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "channel": {
                    "type": "string",
                    "enum": [
                      "counter",
                      "table",
                      "whatsapp"
                    ],
                    "description": "Distribution channel to attribute in results"
                  }
                }
              },
              "example": {
                "user_id": "507f1f77bcf86cd799439011",
                "channel": "counter"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Replay of an already recorded visit (`created: false`)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CampaignVisit"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Visit recorded",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CampaignVisit"
                    }
                  }
                },
                "example": {
                  "data": {
                    "object": "campaign_visit",
                    "campaign_id": "65f1c0d2e4b0a1a2b3c4d5e6",
                    "user_id": "507f1f77bcf86cd799439011",
                    "goal": "return",
                    "created": true,
                    "completion_id": "65f1c0d2e4b0a1a2b3c4d5f0",
                    "points_earned": 1,
                    "reward_unlocked": false,
                    "progress": {
                      "total_visits": 2,
                      "cycle_visits": 2,
                      "visits_required": 5,
                      "rewards_available": 0,
                      "rewards_claimed": 0,
                      "next_reward_in": 3,
                      "last_visit_at": "2026-10-18T13:00:00.000Z",
                      "last_reward_at": null,
                      "next_visit_available_at": "2026-10-19T09:00:00.000Z"
                    },
                    "referral_conversion": {
                      "converted": false
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Missing Idempotency-Key, invalid body or `invalid_occurred_at`",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CampaignError"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "description": "`campaign_not_found` or `user_not_found`",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CampaignError"
                }
              }
            }
          },
          "409": {
            "description": "`visit_cooldown`, `campaign_not_active`, `campaign_outside_window`,\n`goal_mismatch`, `idempotency_conflict` or `idempotency_in_progress`\n",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CampaignError"
                },
                "example": {
                  "error": {
                    "type": "visit_cooldown",
                    "message": "A new visit cannot be recorded for this user yet",
                    "details": {
                      "next_available_at": "2026-10-19T09:00:00.000Z"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/campaigns/{id}/progress": {
      "get": {
        "operationId": "getCampaignProgress",
        "summary": "Progress of a user",
        "description": "Shaped by the goal: cycle progress (return), response and reward state\n(feedback), or invitations as promoter and attribution as invited user\n(referral).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Campaigns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "$ref": "#/components/parameters/QueryUserId"
          }
        ],
        "responses": {
          "200": {
            "description": "Progress",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CampaignProgress"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/campaigns/{id}/redemptions": {
      "post": {
        "operationId": "redeemCampaignReward",
        "summary": "Redeem the campaign reward",
        "description": "- `user_id`: redeems one complete return cycle, or the feedback reward\n  after the response. Requires an `Idempotency-Key`: each key redeems\n  at most once. Never charges points.\n- `pass_token`: confirms the pass a user shows in the hosted journey\n  (the pass is the idempotency key).\n\nRefusals (`409`): `no_reward_available`, `already_redeemed`,\n`cooldown_active` (with `next_available_at`), `out_of_stock`,\n`survey_not_answered`, `campaign_without_reward`,\n`redemption_in_progress`, `campaign_not_active`. Invalid or expired\npass: `403 invalid_pass_token`. Emits `reward.redeemed`.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Campaigns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Required with `user_id` (8–255 characters).",
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 255
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "description": "Send exactly one of `user_id` or `pass_token`.",
                "properties": {
                  "user_id": {
                    "type": "string"
                  },
                  "pass_token": {
                    "type": "string"
                  }
                }
              },
              "example": {
                "user_id": "507f1f77bcf86cd799439011"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Replay of an already confirmed redemption (`created: false`)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CampaignRedemption"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Reward redeemed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CampaignRedemption"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "Redemption refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CampaignError"
                }
              }
            }
          }
        }
      }
    },
    "/campaigns/{id}/referral-links": {
      "post": {
        "operationId": "createCampaignReferralLink",
        "summary": "Personal referral link",
        "description": "Creates the personal link of a promoter (valid for 30 days). Share\n`url` (it opens the project's hosted journey), or carry `token` in your\nown sign-up flow and attribute the invited user with\n`POST /v1/campaigns/{id}/referrals`. The campaign must be active.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Campaigns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "user_id"
                ],
                "properties": {
                  "user_id": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Referral link",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "object": {
                          "type": "string",
                          "enum": [
                            "referral_link"
                          ]
                        },
                        "campaign_id": {
                          "type": "string"
                        },
                        "user_id": {
                          "type": "string"
                        },
                        "url": {
                          "type": "string"
                        },
                        "code": {
                          "type": "string"
                        },
                        "token": {
                          "type": "string"
                        },
                        "expires_at": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/campaigns/{id}/referrals": {
      "post": {
        "operationId": "attributeCampaignReferral",
        "summary": "Attribute an invited user",
        "description": "Attributes `user_id` (the invited user) to the promoter of\n`referral_token`. A user is attributed at most once per project\n(`409 already_referred`) and cannot use their own link\n(`409 self_referral`). Points are granted on conversion: the invited\nuser's first visit (`first-visit`) or first completed campaign\n(`first-campaign-completion`), as frozen in the invitation.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Campaigns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "user_id",
                  "referral_token"
                ],
                "properties": {
                  "user_id": {
                    "type": "string"
                  },
                  "referral_token": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The user was already attributed to this promoter (`captured: false`)"
          },
          "201": {
            "description": "Attribution created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "object": {
                          "type": "string",
                          "enum": [
                            "referral_attribution"
                          ]
                        },
                        "campaign_id": {
                          "type": "string"
                        },
                        "referred_user_id": {
                          "type": "string"
                        },
                        "promoter_user_id": {
                          "type": "string"
                        },
                        "captured": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "`invalid_referral_token` or invalid body"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/campaigns/{id}/responses": {
      "post": {
        "operationId": "submitCampaignResponse",
        "summary": "Answer a feedback campaign",
        "description": "Unlike `POST /v1/surveys/{id}/answers`, a campaign response completes\nthe campaign: it grants `completion_points`, emits `survey.answered`\nand `challenge.completed`, unlocks the optional reward and converts a\npending `first-campaign-completion` invitation. One response per user\n(a repeat answers `200` with `created: false`).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Campaigns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "user_id",
                  "answers"
                ],
                "properties": {
                  "user_id": {
                    "type": "string"
                  },
                  "answers": {
                    "type": "array",
                    "maxItems": 100,
                    "items": {
                      "type": "object",
                      "required": [
                        "question_index",
                        "answer"
                      ],
                      "properties": {
                        "question_index": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "answer": {
                          "oneOf": [
                            {
                              "type": "string"
                            },
                            {
                              "type": "number"
                            },
                            {
                              "type": "array",
                              "items": {
                                "type": "string"
                              }
                            }
                          ]
                        }
                      }
                    }
                  }
                }
              },
              "example": {
                "user_id": "507f1f77bcf86cd799439011",
                "answers": [
                  {
                    "question_index": 0,
                    "answer": 5
                  },
                  {
                    "question_index": 1,
                    "answer": "More evening classes"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The user had already answered (`created: false`)"
          },
          "201": {
            "description": "Response recorded",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "object": {
                          "type": "string",
                          "enum": [
                            "campaign_response"
                          ]
                        },
                        "campaign_id": {
                          "type": "string"
                        },
                        "user_id": {
                          "type": "string"
                        },
                        "created": {
                          "type": "boolean"
                        },
                        "points_earned": {
                          "type": "integer"
                        },
                        "referral_conversion": {
                          "$ref": "#/components/schemas/ReferralConversion"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/campaigns/{id}/results": {
      "get": {
        "operationId": "getCampaignResults",
        "summary": "Campaign results",
        "description": "Totals, funnel, daily series and channels for a period (default: last\n30 days, at most 366). `YYYY-MM-DD` dates are days of the project time\nzone. Scans are events; participants and the following funnel stages\nare unique users, so no rate is computed between scans and people.\nStaff test scans and previews never count.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Campaigns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "name": "from",
            "in": "query",
            "description": "Start (YYYY-MM-DD or ISO 8601 datetime)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "End (YYYY-MM-DD or ISO 8601 datetime)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "channel",
            "in": "query",
            "description": "Only scans and actions attributed to this channel",
            "schema": {
              "type": "string",
              "enum": [
                "counter",
                "table",
                "whatsapp"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CampaignResults"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/campaigns/{id}/qrcodes": {
      "get": {
        "operationId": "getCampaignQrCodes",
        "summary": "QR codes by channel",
        "description": "Scan URL, PNG (data URL) and scan count per distribution channel.\nScanning opens the project's hosted journey: preview, sign-in, then the\nvisit (return), the survey (feedback) or the invitation (referral).\n`preview_url` opens the same journey without counting scans or visits\n(valid for 10 minutes).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Campaigns"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "QR assets",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CampaignQrCodes"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/analytics/overview": {
      "get": {
        "operationId": "getAnalyticsOverview",
        "summary": "Project overview",
        "description": "Activity of the whole project for a period (default: last 30 days, at\nmost 366). `YYYY-MM-DD` dates are days of the project time zone\n(`range.timezone`); an ISO 8601 datetime is an exact instant.\n\n| Field | Definition |\n|-------|------------|\n| `active_users` | Unique users with a completion or a redemption in the period |\n| `completions` | Challenge completions: rules, actions, campaign visits, survey and campaign responses, the invited side of referral conversions |\n| `redemptions` | Reward claims (points catalog and campaign rewards) |\n| `points_issued` | Points of the completions plus the promoter points of converted campaign referrals |\n| `points_spent` | Points charged by redemptions |\n| `new_users` | Users created in the period |\n| `rates.activation` | `active_users` ÷ `total_users`, in percent |\n| `rates.redemption` | `redeeming_users` ÷ `active_users`, in percent |\n\nDirect balance adjustments (`POST /v1/users/{id}/points/add|deduct`)\nand the `/v1/referral` program credit points without a per-period\nrecord, so they are not part of `points_issued`.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Analytics"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "description": "Start (YYYY-MM-DD or ISO 8601 datetime)",
            "schema": {
              "type": "string",
              "example": "2026-10-01"
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "End (YYYY-MM-DD or ISO 8601 datetime)",
            "schema": {
              "type": "string",
              "example": "2026-10-18"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Overview",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/AnalyticsOverview"
                    }
                  }
                },
                "example": {
                  "data": {
                    "object": "analytics_overview",
                    "range": {
                      "from": "2026-10-01T03:00:00.000Z",
                      "to": "2026-10-19T02:59:59.999Z",
                      "timezone": "America/Sao_Paulo",
                      "generated_at": "2026-10-18T15:00:00.000Z"
                    },
                    "totals": {
                      "active_users": 412,
                      "redeeming_users": 37,
                      "completions": 2981,
                      "redemptions": 44,
                      "points_issued": 31840,
                      "points_spent": 12200,
                      "new_users": 96,
                      "total_users": 1280
                    },
                    "rates": {
                      "activation": 32.19,
                      "redemption": 8.98
                    },
                    "daily": [
                      {
                        "date": "2026-10-01",
                        "active_users": 51,
                        "completions": 160,
                        "redemptions": 2,
                        "points_issued": 1710,
                        "points_spent": 500,
                        "new_users": 4
                      }
                    ]
                  }
                }
              }
            }
          },
          "400": {
            "description": "`validation_error` or `invalid_date_range`",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/events": {
      "get": {
        "operationId": "listEvents",
        "summary": "List tracked events",
        "description": "Processing log of every `POST /actions/track` call of the project,\nkept for 30 days and newest first: the action type, the user, the\noutcome and the effects it produced. Property **values** are never\nstored, only their keys — use it to debug an integration, not as a data\nexport.\n\n| `outcome` | Meaning |\n|-----------|---------|\n| `processed` | The event was accepted and rules ran |\n| `rejected` | The request was invalid or not allowed (4xx) |\n| `failed` | The Engine could not process it (5xx) |\n\nDomain events (`points.added`, `user.at_risk`…) are delivered through\nwebhooks; each delivery is logged per endpoint.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Events"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "outcome",
            "in": "query",
            "description": "Filter by result",
            "schema": {
              "type": "string",
              "enum": [
                "processed",
                "rejected",
                "failed"
              ]
            }
          },
          {
            "name": "action_type",
            "in": "query",
            "description": "Exact `action_type`",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "user_id",
            "in": "query",
            "required": false,
            "description": "The `user_id` sent to `/actions/track`",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "created_after",
            "in": "query",
            "description": "Inclusive lower bound (ISO 8601)",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "created_before",
            "in": "query",
            "description": "Exclusive upper bound (ISO 8601)",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "$ref": "#/components/parameters/QueryLimit"
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "Value of `next_cursor` from the previous page",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Page of tracked events",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/TrackedEvent"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "6712f0c2a1b2c3d4e5f60801",
                      "type": "action.tracked",
                      "request_id": "req_7f3a2c1b",
                      "action_type": "lesson_completed",
                      "user_id": "507f1f77bcf86cd799439011",
                      "property_keys": [
                        "course_id",
                        "duration"
                      ],
                      "outcome": "processed",
                      "status_code": 200,
                      "duration_ms": 42,
                      "effects": {
                        "challenges_completed": 1,
                        "badges_earned": 0,
                        "points_earned": 50
                      },
                      "error_type": null,
                      "created_at": "2026-10-18T14:35:00.000Z"
                    }
                  ],
                  "has_more": false
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/win-back/config": {
      "get": {
        "operationId": "getWinBackConfig",
        "summary": "Get churn-risk configuration",
        "description": "Returns the thresholds that classify users by days without\ninteraction, whether the daily detection is enabled and when the last\ncomplete detection ran.\n\n| Level | Default | Meaning |\n|-------|---------|---------|\n| `low` | 7 | No interaction for 7 days or more |\n| `medium` | 14 | 14 days or more |\n| `high` | 30 | 30 days or more |\n| `lost` | 60 | 60 days or more |\n\nAn interaction is a completed challenge, a redeemed reward, a tracked\naction or points added by your app (effects of automations do not\ncount). Any interaction moves the user back to `none` and emits\n`user.reactivated` when the user was at risk.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Win-back"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current configuration",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WinBackConfig"
                    }
                  }
                },
                "example": {
                  "data": {
                    "enabled": true,
                    "thresholds": {
                      "low": 7,
                      "medium": 14,
                      "high": 30,
                      "lost": 60
                    },
                    "last_detection_at": "2026-10-18T06:00:12.000Z"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      },
      "put": {
        "operationId": "updateWinBackConfig",
        "summary": "Update churn-risk configuration",
        "description": "Updates the thresholds and/or turns the daily detection on or off.\nOmitted fields keep their current value. Thresholds are whole days and\nmust increase: `low < medium < high < lost` (`lost` up to 730).\n\nNew thresholds apply on the next detection (daily, or now with\n`POST /win-back/detect`).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Win-back"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "enabled": {
                    "type": "boolean",
                    "description": "Run the detection automatically every day"
                  },
                  "thresholds": {
                    "$ref": "#/components/schemas/WinBackThresholds"
                  }
                }
              },
              "example": {
                "thresholds": {
                  "low": 10,
                  "medium": 21,
                  "high": 45,
                  "lost": 90
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated configuration",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WinBackConfig"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/win-back/users": {
      "get": {
        "operationId": "listWinBackUsers",
        "summary": "List at-risk users",
        "description": "Users whose risk level is not `none`, longest absence first. Levels are\nrefreshed by the daily detection; `days_since_last_interaction` is the\nvalue computed on the last detection.\n\nUse `next_cursor` as `cursor` to fetch the next page.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Win-back"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "level",
            "in": "query",
            "description": "`at_risk` (default, every level) or a comma-separated list of\n`low`, `medium`, `high`, `lost`.\n",
            "schema": {
              "type": "string",
              "example": "high,lost"
            }
          },
          {
            "$ref": "#/components/parameters/QueryLimit"
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "Opaque cursor returned as `next_cursor`",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "search",
            "in": "query",
            "description": "Filter by name, email or external ID",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Page of at-risk users",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WinBackUser"
                      }
                    },
                    "total": {
                      "type": "integer",
                      "description": "Users matching the filter"
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "507f1f77bcf86cd799439011",
                      "name": "Ana Souza",
                      "email": "ana@example.com",
                      "external_id": "cust_123",
                      "risk_level": "high",
                      "days_since_last_interaction": 34,
                      "last_interaction_at": "2026-09-14T18:02:00.000Z",
                      "last_dispatch_at": null,
                      "dispatch_count": 0
                    }
                  ],
                  "total": 42,
                  "has_more": true,
                  "next_cursor": "MzQ6NTA3ZjFmNzdiY2Y4NmNkNzk5NDM5MDEx"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/win-back/detect": {
      "post": {
        "operationId": "detectWinBackRisks",
        "summary": "Run churn-risk detection now",
        "description": "Recomputes the risk of every user now, in batches, with the current\nthresholds (the daily maintenance does the same automatically when\n`enabled` is true). Users whose level changes emit `user.at_risk` (or\n`user.reactivated` when they leave the risk levels).\n\nA call is bounded to about 25 seconds. When the base is larger,\n`completed` is `false`; the next call or the daily run scans it again\nfrom the start. `last_detection_at` only changes when a scan completes.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Win-back"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Detection result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "processed": {
                          "type": "integer",
                          "description": "Users evaluated"
                        },
                        "changed": {
                          "type": "integer",
                          "description": "Users whose level changed"
                        },
                        "at_risk_events": {
                          "type": "integer"
                        },
                        "reactivated_events": {
                          "type": "integer"
                        },
                        "completed": {
                          "type": "boolean"
                        },
                        "last_detection_at": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "date-time"
                        },
                        "duration_ms": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": {
                    "processed": 1840,
                    "changed": 37,
                    "at_risk_events": 35,
                    "reactivated_events": 2,
                    "completed": true,
                    "last_detection_at": "2026-10-18T14:20:05.000Z",
                    "duration_ms": 812
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/win-back/dispatches": {
      "get": {
        "operationId": "listWinBackDispatches",
        "summary": "List return invitations",
        "description": "Return invitations recorded for the project, newest first, with the\nconversion status (`converted` turns true when the user interacts\nwithin 30 days after the invitation).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Win-back"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "user_id",
            "in": "query",
            "description": "Only invitations of this user",
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/QueryLimit"
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "Value of `next_cursor` from the previous page",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Page of invitations",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WinBackDispatch"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      },
      "post": {
        "operationId": "createWinBackDispatch",
        "summary": "Record a return invitation",
        "description": "Records that your system sent a return invitation to a user (email,\npush or WhatsApp) and emits `winback.dispatched`. When the user\ninteracts within 30 days, the invitation is marked as converted and\n`user.reactivated` lists it in `winback_dispatch_ids`.\n\n**Idempotent.** Send an `Idempotency-Key` header (or\n`idempotency_key`): repeating the key returns the stored invitation\nwith `200` and `Idempotent-Replayed: true`. Without a key, the same\nuser, campaign and channel on the same UTC day is one invitation.\nReusing a key for a different user, campaign or channel returns `409`.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Win-back"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Stable key for this invitation (8–255 characters)",
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 255
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "user_id",
                  "campaign_id",
                  "channel"
                ],
                "properties": {
                  "user_id": {
                    "type": "string",
                    "description": "Experi user ID"
                  },
                  "campaign_id": {
                    "type": "string",
                    "maxLength": 120,
                    "description": "Your identifier for the invitation campaign"
                  },
                  "channel": {
                    "type": "string",
                    "enum": [
                      "whatsapp",
                      "email",
                      "push"
                    ]
                  },
                  "idempotency_key": {
                    "type": "string",
                    "minLength": 8,
                    "maxLength": 255
                  }
                }
              },
              "example": {
                "user_id": "507f1f77bcf86cd799439011",
                "campaign_id": "october-comeback",
                "channel": "email"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Same idempotency key — the stored invitation",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WinBackDispatch"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Invitation recorded",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/WinBackDispatch"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "created": {
                              "type": "boolean"
                            }
                          }
                        }
                      ]
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "6712f0c2a1b2c3d4e5f60718",
                    "user_id": "507f1f77bcf86cd799439011",
                    "campaign_id": "october-comeback",
                    "channel": "email",
                    "source": "api",
                    "risk_level": "high",
                    "days_since_last_interaction": 34,
                    "converted": false,
                    "converted_at": null,
                    "created_at": "2026-10-18T14:21:00.000Z",
                    "created": true
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/automations": {
      "get": {
        "operationId": "listAutomations",
        "summary": "List automations",
        "description": "Automations run when an event happens: \"when `trigger.event_type`\nhappens and every condition matches, run the actions\". Rules for the\nsame event run in `priority` order (lower first).\n\n### Loop protection\n\nEvents produced by an automation action carry an `automation` object\n(`rule_id`, `rule_ids`, `depth`) — also in webhook payloads. A rule\nnever reacts to an event that its own actions caused, directly or\nthrough other rules, and chains stop after `loop_protection.max_depth`\nhops. Those evaluations are recorded as `skipped` with `skip_reason`\n`self_trigger` or `max_depth`.\n\n`is_weekend` and `time_between` use the project timezone. Events\nwithout a user (for example `guild.level_up`) skip user actions with\n`skip_reason: no_user` and never count as failures. After\n`loop_protection.max_consecutive_failures` failures in a row the rule\nis disabled (`disabled_after_failures: true`).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Automations"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "event_type",
            "in": "query",
            "description": "Only rules triggered by this event",
            "schema": {
              "type": "string",
              "example": "challenge.completed"
            }
          },
          {
            "name": "enabled",
            "in": "query",
            "description": "Filter by status",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Automation rules",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Automation"
                      }
                    },
                    "loop_protection": {
                      "type": "object",
                      "properties": {
                        "max_depth": {
                          "type": "integer",
                          "example": 3
                        },
                        "max_consecutive_failures": {
                          "type": "integer",
                          "example": 10
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      },
      "post": {
        "operationId": "createAutomation",
        "summary": "Create automation",
        "description": "Creates a rule. Conditions read `event.*` (event data), `user.*`,\n`challenge.*`, `reward.*` or `badge.*` fields of the documents linked\nto the event.\n\n| Operator | Field | Value |\n|----------|-------|-------|\n| `eq`, `neq`, `contains` | required | required |\n| `gt`, `gte`, `lt`, `lte` | required | number |\n| `is_weekend` | — | — |\n| `time_between` | — | `\"HH:mm-HH:mm\"` (may cross midnight) |\n\n| Action | Params |\n|--------|--------|\n| `add_points` / `deduct_points` | `amount` (1–1,000,000), `reason`; deduct also `allow_negative` |\n| `award_badge` | `badge_id` or `badge_slug` |\n| `send_webhook` | `webhook_id` — delivers the triggering event to that endpoint, signed and retried like any delivery; an endpoint never receives the same event twice |\n| `log_event` | `message` |\n\nFor `referral.converted`, user actions apply to the person who\nreferred (`promoter_user_id`).\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Automations"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AutomationInput"
              },
              "examples": {
                "weekend_bonus": {
                  "summary": "Weekend bonus after a challenge",
                  "value": {
                    "name": "Weekend bonus",
                    "trigger": {
                      "event_type": "challenge.completed"
                    },
                    "conditions": [
                      {
                        "operator": "is_weekend"
                      },
                      {
                        "operator": "time_between",
                        "value": "18:00-23:00"
                      }
                    ],
                    "actions": [
                      {
                        "type": "add_points",
                        "params": {
                          "amount": 20,
                          "reason": "Weekend bonus"
                        }
                      }
                    ]
                  }
                },
                "forward_vip": {
                  "summary": "Forward big redemptions to a webhook",
                  "value": {
                    "name": "Notify CRM on big redemptions",
                    "trigger": {
                      "event_type": "reward.redeemed"
                    },
                    "conditions": [
                      {
                        "field": "event.points_spent",
                        "operator": "gte",
                        "value": 1000
                      }
                    ],
                    "actions": [
                      {
                        "type": "send_webhook",
                        "params": {
                          "webhook_id": "507f1f77bcf86cd799439012"
                        }
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Automation created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Automation"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/automations/{id}": {
      "get": {
        "operationId": "getAutomation",
        "summary": "Get automation",
        "description": "**Permissions:** Secret Key only",
        "tags": [
          "Automations"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Automation",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Automation"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "operationId": "updateAutomation",
        "summary": "Update automation",
        "description": "Updates any field of the rule. Sending `conditions` or `actions`\nreplaces the whole list. Re-enabling a rule disabled after failures\nresets its failure count.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Automations"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AutomationUpdate"
              },
              "example": {
                "enabled": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated automation",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Automation"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "delete": {
        "operationId": "deleteAutomation",
        "summary": "Delete automation",
        "description": "Deletes the rule (it stops running immediately). Its execution history\nremains available for 90 days.\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Automations"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Automation deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "deleted": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/automations/{id}/executions": {
      "get": {
        "operationId": "listAutomationExecutions",
        "summary": "List automation executions",
        "description": "Every evaluation of the rule (kept for 90 days), newest first:\n`matched` (actions ran), `skipped` (see `skip_reason`) or `failed`.\n\n| `skip_reason` | Meaning |\n|---------------|---------|\n| `conditions_not_met` | The conditions did not match the event |\n| `self_trigger` | Loop protection: the event was caused by this rule |\n| `max_depth` | Loop protection: the automation chain is too deep |\n| `no_user` | The event has no user for user actions |\n\n**Permissions:** Secret Key only\n",
        "tags": [
          "Automations"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/PathId"
          },
          {
            "$ref": "#/components/parameters/QueryLimit"
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "Value of `next_cursor` from the previous page",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Filter by result",
            "schema": {
              "type": "string",
              "enum": [
                "matched",
                "skipped",
                "failed"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Page of executions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AutomationExecution"
                      }
                    },
                    "has_more": {
                      "type": "boolean"
                    },
                    "next_cursor": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "6712f0c2a1b2c3d4e5f60799",
                      "automation_id": "6712f0c2a1b2c3d4e5f60700",
                      "event_id": "evt_4b1c...",
                      "event_type": "points.added",
                      "user_id": "507f1f77bcf86cd799439011",
                      "status": "skipped",
                      "skip_reason": "self_trigger",
                      "conditions_matched": false,
                      "actions": [],
                      "duration_ms": 3,
                      "error": null,
                      "origin": {
                        "rule_ids": [
                          "6712f0c2a1b2c3d4e5f60700"
                        ],
                        "depth": 1
                      },
                      "created_at": "2026-10-18T14:30:00.000Z"
                    }
                  ],
                  "has_more": false
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Use your API Key in the format `Bearer sk_live_xxx` or `Bearer pk_live_xxx`.\n\n**Secret Keys** (`sk_live_`) have full access to the API.\n**Public Keys** (`pk_live_`) can only access read endpoints (GET).\n",
        "bearerFormat": "API Key"
      }
    },
    "parameters": {
      "QueryLimit": {
        "name": "limit",
        "in": "query",
        "description": "Maximum number of items per page",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100,
          "default": 20
        }
      },
      "QueryStartingAfter": {
        "name": "starting_after",
        "in": "query",
        "description": "ID of the item after which to start listing (for pagination)",
        "schema": {
          "type": "string"
        }
      },
      "QueryMetadata": {
        "name": "metadata[key]",
        "in": "query",
        "description": "Filter by user metadata. Supports multiple keys.\n\n**Accepted formats:**\n- `metadata[key]=value` - e.g.: `metadata[tier]=gold`\n- `metadata.key=value` - e.g.: `metadata.tier=gold`\n\n**Multiple filters:** `metadata[tier]=gold&metadata[region]=south`\n",
        "schema": {
          "type": "string"
        },
        "example": "gold"
      },
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "description": "Stable key for one logical mutation (8–255 characters). Successful JSON\nresponses are retained for 24 hours. Reusing the key with a different\noperation or body returns `409`.\n",
        "schema": {
          "type": "string",
          "minLength": 8,
          "maxLength": 255
        }
      },
      "PathId": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "Unique resource ID",
        "schema": {
          "type": "string",
          "example": "507f1f77bcf86cd799439011"
        }
      },
      "GuildId": {
        "name": "id",
        "in": "path",
        "description": "Guild identifier",
        "required": true,
        "schema": {
          "type": "string",
          "example": "507f1f77bcf86cd799439070"
        }
      },
      "MemberUserId": {
        "name": "userId",
        "in": "path",
        "description": "User identifier of the guild member",
        "required": true,
        "schema": {
          "type": "string",
          "example": "507f1f77bcf86cd799439022"
        }
      },
      "QueryUserId": {
        "name": "user_id",
        "in": "query",
        "required": true,
        "description": "User ID",
        "schema": {
          "type": "string"
        }
      }
    },
    "schemas": {
      "User": {
        "type": "object",
        "description": "**User** is the central entity of the loyalty program.\n\nRepresents a registered individual who can:\n- Earn and spend **points**\n- Complete **challenges** to earn points\n- Unlock **badges** (achievements)\n- Redeem **rewards**\n- Answer **surveys**\n\n### Identification\n\nEach user has a unique internal `id`, but you can use the\n`external_id` field to link to your system's ID (e.g., customer ID in your ERP).\n\n### Points\n\nThe `points` field represents the current balance available for redemption.\nPoints are:\n- **Earned** by completing challenges or via manual addition\n- **Spent** by redeeming rewards or via manual deduction\n\n### Metadata\n\nUse the `metadata` field to store custom data such as\ncustomer tier, segment, preferences, etc. This data can\nbe filtered in queries.\n",
        "required": [
          "id",
          "name",
          "points",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique user identifier (MongoDB ObjectId)",
            "example": "507f1f77bcf86cd799439011"
          },
          "name": {
            "type": "string",
            "description": "Full name of the user",
            "example": "John Smith"
          },
          "email": {
            "type": "string",
            "format": "email",
            "description": "User email (unique per tenant, used for communications)",
            "example": "john@example.com"
          },
          "phone": {
            "type": "string",
            "description": "Phone number in international WhatsApp format.\nFormat: country code + area code + number (no spaces or special characters)\n",
            "example": "5511999999999"
          },
          "external_id": {
            "type": "string",
            "description": "External ID for integration with other systems.\nUse to link to the customer ID in your ERP, CRM, or database.\nMust be unique per tenant.\n",
            "example": "cust_abc123"
          },
          "points": {
            "type": "integer",
            "description": "Current point balance available for redemption.\nThis value is automatically updated when the user:\n- Completes challenges (+points)\n- Redeems rewards (-points)\n- Receives points via API (+/- points)\n",
            "minimum": 0,
            "example": 1500
          },
          "xp": {
            "type": "integer",
            "description": "Total XP (Experience Points) accumulated by the user. Used to level up (Tier).",
            "minimum": 0,
            "example": 2500
          },
          "qualifying_xp": {
            "type": "integer",
            "description": "Valid XP for qualification in the current period (depends on the Tenant's expiration rule).",
            "minimum": 0,
            "example": 2500
          },
          "current_tier": {
            "type": "string",
            "description": "Slug of the user's current tier (level).",
            "example": "gold"
          },
          "tier_qualified_at": {
            "type": "string",
            "format": "date-time",
            "description": "Date when the user reached the current tier.",
            "example": "2026-02-21T10:30:00Z"
          },
          "tier_expires_at": {
            "type": "string",
            "format": "date-time",
            "description": "Date when the current tier expires (if applicable).",
            "example": "2026-12-31T23:59:59Z"
          },
          "badges": {
            "type": "array",
            "description": "IDs of badges (achievements) already unlocked by the user",
            "items": {
              "type": "string"
            },
            "example": [
              "507f1f77bcf86cd799439011",
              "507f1f77bcf86cd799439012"
            ]
          },
          "challenges_count": {
            "type": "integer",
            "description": "Total challenges completed by the user (lifetime)",
            "example": 15
          },
          "rewards_count": {
            "type": "integer",
            "description": "Total rewards redeemed by the user (lifetime)",
            "example": 3
          },
          "metadata": {
            "type": "object",
            "description": "Custom additional data in key-value format.\n\n**Usage examples:**\n- `tier`: customer level (bronze, silver, gold)\n- `signup_source`: registration source (app, website, store)\n- `cpf`: customer document (if needed)\n\nCan be filtered via `?metadata[key]=value` in queries.\n",
            "additionalProperties": true,
            "example": {
              "tier": "gold",
              "signup_source": "mobile_app"
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "Date and time of registration creation (UTC)",
            "example": "2024-01-15T10:30:00Z"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "description": "Date and time of the last update (UTC)",
            "example": "2024-01-20T14:45:00Z"
          }
        }
      },
      "UserCreate": {
        "type": "object",
        "description": "Data to create a new user",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string",
            "description": "User name",
            "minLength": 2,
            "maxLength": 100,
            "example": "John Smith"
          },
          "email": {
            "type": "string",
            "format": "email",
            "description": "User email",
            "example": "john@example.com"
          },
          "phone": {
            "type": "string",
            "description": "Phone number in WhatsApp format (country code + area code + number)",
            "example": "5511999999999"
          },
          "external_id": {
            "type": "string",
            "description": "External ID for integration",
            "example": "cust_abc123"
          },
          "referral_code": {
            "type": "string",
            "description": "Optional referral code supplied during signup.\nIf valid, the new user is linked to the promoter and can participate\nin the referral conversion flow.\n",
            "minLength": 6,
            "maxLength": 12,
            "example": "FRIEND01"
          },
          "metadata": {
            "type": "object",
            "description": "Custom additional data",
            "additionalProperties": true
          }
        }
      },
      "DeleteResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "deleted": {
                "type": "boolean",
                "example": true
              }
            }
          }
        }
      },
      "UserUpdate": {
        "type": "object",
        "description": "Data to update a user",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 2,
            "maxLength": 100
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "phone": {
            "type": "string"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "UserBadgeGrant": {
        "type": "object",
        "description": "A badge earned by a user and how it was granted.",
        "properties": {
          "id": {
            "type": "string"
          },
          "badge_id": {
            "type": "string"
          },
          "badge": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "slug": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "description": {
                "type": "string"
              },
              "rarity": {
                "type": "string",
                "enum": [
                  "common",
                  "rare",
                  "epic",
                  "legendary"
                ]
              },
              "icon_url": {
                "type": "string"
              }
            }
          },
          "awarded_at": {
            "type": "string",
            "format": "date-time"
          },
          "source": {
            "type": "string",
            "enum": [
              "automatic",
              "api",
              "console",
              "studio",
              "automation"
            ]
          },
          "granted_by": {
            "type": [
              "string",
              "null"
            ]
          },
          "metadata": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true
          }
        }
      },
      "UserRewardClaim": {
        "type": "object",
        "description": "Reward redemption record",
        "properties": {
          "id": {
            "type": "string"
          },
          "reward_id": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "points_spent": {
            "type": "integer"
          },
          "redeemed_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ReferralStats": {
        "type": "object",
        "required": [
          "pending",
          "converted",
          "totalPointsEarned"
        ],
        "properties": {
          "pending": {
            "type": "integer",
            "example": 3
          },
          "converted": {
            "type": "integer",
            "example": 5
          },
          "totalPointsEarned": {
            "type": "integer",
            "example": 250
          }
        }
      },
      "ReferralEntry": {
        "type": "object",
        "required": [
          "id",
          "name",
          "createdAt",
          "converted"
        ],
        "properties": {
          "id": {
            "type": "string",
            "example": "507f1f77bcf86cd799439022"
          },
          "name": {
            "type": "string",
            "example": "Maria Souza"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "example": "2026-03-10T14:00:00Z"
          },
          "converted": {
            "type": "boolean",
            "example": true
          }
        }
      },
      "ReferralStatsResponse": {
        "type": "object",
        "required": [
          "stats",
          "referrals"
        ],
        "properties": {
          "code": {
            "type": [
              "string",
              "null"
            ],
            "example": "FRIEND01"
          },
          "referralLink": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "example": "https://demo.experi.com.br/invite/FRIEND01?tenant=507f1f77bcf86cd799439099"
          },
          "stats": {
            "$ref": "#/components/schemas/ReferralStats"
          },
          "referrals": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ReferralEntry"
            }
          }
        }
      },
      "SeasonPassLevel": {
        "type": "object",
        "required": [
          "level",
          "xp_required"
        ],
        "properties": {
          "level": {
            "type": "integer",
            "minimum": 1
          },
          "xp_required": {
            "type": "integer",
            "minimum": 0
          },
          "free_reward_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "premium_reward_id": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "SeasonPass": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "start_date": {
            "type": "string",
            "format": "date-time"
          },
          "end_date": {
            "type": "string",
            "format": "date-time"
          },
          "levels": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SeasonPassLevel"
            }
          },
          "premium_price": {
            "type": [
              "number",
              "null"
            ]
          },
          "premium_currency": {
            "type": "string",
            "enum": [
              "BRL",
              "points"
            ]
          },
          "active": {
            "type": "boolean"
          },
          "metadata": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "SeasonTrackItem": {
        "type": [
          "object",
          "null"
        ],
        "properties": {
          "reward_id": {
            "type": "string"
          },
          "reward_title": {
            "type": [
              "string",
              "null"
            ]
          },
          "reward_available": {
            "type": "boolean"
          },
          "claimed": {
            "type": "boolean"
          },
          "claimable": {
            "type": "boolean"
          }
        }
      },
      "UserSeasonPass": {
        "type": "object",
        "properties": {
          "user_id": {
            "type": "string"
          },
          "pass": {
            "$ref": "#/components/schemas/SeasonPass"
          },
          "progress": {
            "type": "object",
            "properties": {
              "current_xp": {
                "type": "integer"
              },
              "current_level": {
                "type": "integer",
                "description": "0 before the first level is reached."
              },
              "next_level": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "xp_to_next_level": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "progress_percent": {
                "type": "integer"
              },
              "is_premium": {
                "type": "boolean"
              },
              "premium_granted_via": {
                "type": [
                  "string",
                  "null"
                ],
                "enum": [
                  "points",
                  "external_payment",
                  "complimentary",
                  null
                ]
              },
              "premium_granted_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "claimed_free_levels": {
                "type": "array",
                "items": {
                  "type": "integer"
                }
              },
              "claimed_premium_levels": {
                "type": "array",
                "items": {
                  "type": "integer"
                }
              }
            }
          },
          "levels": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "level": {
                  "type": "integer"
                },
                "xp_required": {
                  "type": "integer"
                },
                "reached": {
                  "type": "boolean"
                },
                "free": {
                  "$ref": "#/components/schemas/SeasonTrackItem"
                },
                "premium": {
                  "$ref": "#/components/schemas/SeasonTrackItem"
                }
              }
            }
          }
        }
      },
      "SeasonClaim": {
        "type": "object",
        "properties": {
          "claim_id": {
            "type": "string"
          },
          "created": {
            "type": "boolean"
          },
          "user_id": {
            "type": "string"
          },
          "pass_id": {
            "type": "string"
          },
          "level": {
            "type": "integer"
          },
          "track": {
            "type": "string",
            "enum": [
              "free",
              "premium"
            ]
          },
          "reward": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "title": {
                "type": "string"
              },
              "description": {
                "type": "string"
              }
            }
          },
          "claimed_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Tier": {
        "type": "object",
        "required": [
          "slug",
          "name",
          "min_xp",
          "multiplier",
          "benefits"
        ],
        "properties": {
          "slug": {
            "type": "string",
            "example": "gold"
          },
          "name": {
            "type": "string",
            "example": "Gold"
          },
          "min_xp": {
            "type": "integer",
            "minimum": 0,
            "example": 1000
          },
          "multiplier": {
            "type": "number",
            "minimum": 1,
            "maximum": 5,
            "example": 1.2
          },
          "color": {
            "type": [
              "string",
              "null"
            ],
            "example": "#CA8A04"
          },
          "icon": {
            "type": [
              "string",
              "null"
            ],
            "example": "crown"
          },
          "benefits": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "users": {
            "type": "integer",
            "description": "Users in this tier now (Secret Key only)."
          }
        }
      },
      "UserTier": {
        "type": "object",
        "properties": {
          "user_id": {
            "type": "string"
          },
          "enabled": {
            "type": "boolean"
          },
          "tier": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Tier"
              },
              {
                "type": "null"
              }
            ]
          },
          "next_tier": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Tier"
              },
              {
                "type": "null"
              }
            ]
          },
          "qualifying_xp": {
            "type": "integer"
          },
          "lifetime_xp": {
            "type": "integer"
          },
          "xp_to_next_tier": {
            "type": [
              "integer",
              "null"
            ]
          },
          "progress_percent": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "tier_qualified_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "at_risk": {
            "type": "boolean"
          },
          "at_risk_since": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "demotion_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "demotion_tier": {
            "type": [
              "string",
              "null"
            ]
          },
          "xp_to_keep_tier": {
            "type": "integer"
          },
          "qualification_window": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "lifetime",
                  "rolling",
                  "calendar"
                ]
              },
              "days": {
                "type": "integer"
              },
              "starts_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            }
          },
          "grace_period_days": {
            "type": "integer"
          }
        }
      },
      "UserStreak": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "streak_id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "frequency": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "daily",
                  "weekly",
                  "monthly"
                ]
              },
              "interval": {
                "type": "integer"
              }
            }
          },
          "current_streak": {
            "type": "integer"
          },
          "best_streak": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "broken"
            ]
          },
          "last_completion_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "next_deadline": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "broken_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "PointsBalance": {
        "type": "object",
        "description": "User's point balance",
        "required": [
          "user_id",
          "balance",
          "lifetime_earned"
        ],
        "properties": {
          "user_id": {
            "type": "string",
            "description": "User ID",
            "example": "507f1f77bcf86cd799439011"
          },
          "balance": {
            "type": "integer",
            "description": "Current available point balance",
            "example": 1500
          },
          "lifetime_earned": {
            "type": "integer",
            "description": "Total points earned since registration",
            "example": 3500
          }
        }
      },
      "AddPointsRequest": {
        "type": "object",
        "description": "Request to add points",
        "required": [
          "amount"
        ],
        "properties": {
          "amount": {
            "type": "integer",
            "description": "Amount of points to add",
            "minimum": 1,
            "example": 200
          },
          "reason": {
            "type": "string",
            "description": "Reason for adding points",
            "maxLength": 255,
            "example": "Referral bonus"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "PointsOperation": {
        "type": "object",
        "description": "Points operation result",
        "required": [
          "user_id",
          "previous_balance",
          "new_balance",
          "amount"
        ],
        "properties": {
          "user_id": {
            "type": "string",
            "example": "507f1f77bcf86cd799439011"
          },
          "previous_balance": {
            "type": "integer",
            "description": "Balance before the operation",
            "example": 1500
          },
          "new_balance": {
            "type": "integer",
            "description": "Balance after the operation",
            "example": 1700
          },
          "amount": {
            "type": "integer",
            "description": "Amount of points added/deducted",
            "example": 200
          }
        }
      },
      "DeductPointsRequest": {
        "type": "object",
        "description": "Request to deduct points",
        "required": [
          "amount"
        ],
        "properties": {
          "amount": {
            "type": "integer",
            "description": "Amount of points to deduct",
            "minimum": 1,
            "example": 100
          },
          "reason": {
            "type": "string",
            "description": "Reason for the deduction",
            "maxLength": 255,
            "example": "Reward chargeback"
          },
          "allow_negative": {
            "type": "boolean",
            "description": "Allow negative balance",
            "default": false
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "WalletProvider": {
        "type": "object",
        "properties": {
          "available": {
            "type": "boolean"
          },
          "unavailable_reason": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "wallet_disabled",
              "provider_not_configured",
              null
            ]
          },
          "add_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "Signed link for this user, valid for one hour"
          },
          "add_url_expires_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "pass": {
            "type": [
              "object",
              "null"
            ],
            "description": "The user's existing pass with this provider",
            "properties": {
              "id": {
                "type": "string"
              },
              "serial_number": {
                "type": "string"
              },
              "pass_type_identifier": {
                "type": "string",
                "description": "Apple only"
              },
              "device_registered": {
                "type": "boolean",
                "description": "Apple only — a device receives update pushes"
              },
              "object_id": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Google only — the user's loyalty object"
              },
              "class_id": {
                "type": "string",
                "description": "Google only"
              },
              "last_updated_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "created_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            }
          }
        }
      },
      "UserWallet": {
        "type": "object",
        "properties": {
          "user_id": {
            "type": "string"
          },
          "enabled": {
            "type": "boolean",
            "description": "Wallet passes enabled for the project"
          },
          "providers": {
            "type": "object",
            "properties": {
              "apple": {
                "$ref": "#/components/schemas/WalletProvider"
              },
              "google": {
                "$ref": "#/components/schemas/WalletProvider"
              }
            }
          }
        }
      },
      "Badge": {
        "type": "object",
        "description": "**Badge** (Achievement) represents a medal or trophy that users can unlock.\n\nBadges are **gamification** elements that encourage specific behaviors\nand create a sense of progression and achievement in the loyalty program.\n\n### Unlock Types\n\nBadges can be unlocked in two ways:\n\n1. **Automatically**: When the user meets the defined criteria\n   - E.g.: \"Complete 10 challenges\" → badge unlocked automatically\n\n2. **Manually via API**: For special cases or integrations\n   - E.g.: \"VIP Customer\" badge granted by staff\n\n### Automatic Criteria\n\n| Type | Description | Example |\n|------|-------------|---------|\n| `count_challenges` | Total challenges completed | \"Complete 50 challenges\" |\n| `streak_weeks` | Consecutive weeks with activity | \"3 consecutive weeks\" |\n| `specific_challenges` | Complete specific challenges | \"Complete all 5 Christmas challenges\" |\n| `manual` | API only | \"Founding Customer\" |\n\n### Rarity\n\nRarity affects the **visual presentation** and **perceived value**:\n- `common`: Basic badges, easy to get\n- `rare`: Require more effort\n- `epic`: Significant achievements\n- `legendary`: Extremely difficult or exclusive\n\n### Hidden Badges\n\nBadges with `is_hidden: true` do not appear in the public list.\nThey are revealed only when unlocked (surprise effect).\n",
        "required": [
          "id",
          "slug",
          "name",
          "description",
          "rarity",
          "criteria",
          "is_hidden",
          "active",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique badge identifier (MongoDB ObjectId)",
            "example": "507f1f77bcf86cd799439011"
          },
          "slug": {
            "type": "string",
            "description": "Human-readable unique identifier, used in URLs and integrations.\nFormat: lowercase letters, numbers, and hyphens.\n",
            "example": "first-challenge"
          },
          "name": {
            "type": "string",
            "description": "Display name of the badge",
            "example": "First Step"
          },
          "description": {
            "type": "string",
            "description": "Description explaining how to unlock the badge",
            "example": "Complete your first challenge"
          },
          "icon_url": {
            "type": "string",
            "format": "uri",
            "description": "URL of a custom icon/image (optional)"
          },
          "rarity": {
            "type": "string",
            "description": "Rarity level that affects visual presentation.\nHigher rarities are harder to achieve.\n",
            "enum": [
              "common",
              "rare",
              "epic",
              "legendary"
            ],
            "example": "common"
          },
          "style": {
            "type": "object",
            "description": "Visual settings of the badge for frontend rendering.\nUse to create visually unique badges.\n",
            "properties": {
              "variant": {
                "type": "string",
                "description": "Visual style of the badge container",
                "enum": [
                  "metallic",
                  "glass",
                  "neon",
                  "holographic",
                  "flat"
                ],
                "example": "metallic"
              },
              "background_color": {
                "type": "string",
                "description": "Background color (hexadecimal or CSS name)",
                "example": "#FFD700"
              },
              "icon_color": {
                "type": "string",
                "description": "Icon color",
                "example": "#FFFFFF"
              },
              "icon_name": {
                "type": "string",
                "description": "Lucide icon name (https://lucide.dev/icons)",
                "example": "trophy"
              }
            }
          },
          "criteria": {
            "type": "object",
            "description": "Criteria for automatic badge unlocking.\nWhen the user meets the criteria, the badge is automatically awarded.\n",
            "required": [
              "type",
              "threshold"
            ],
            "properties": {
              "type": {
                "type": "string",
                "description": "Type of criteria for automatic unlocking:\n- `count_challenges`: Total number of completed challenges\n- `streak_weeks`: Consecutive weeks with at least one activity\n- `specific_challenges`: Specific list of challenges that must be completed\n- `manual`: Not automatically unlocked (API only)\n",
                "enum": [
                  "count_challenges",
                  "streak_weeks",
                  "specific_challenges",
                  "manual"
                ],
                "example": "count_challenges"
              },
              "threshold": {
                "type": "integer",
                "description": "Value required to unlock.\nFor `count_challenges`: number of challenges.\nFor `streak_weeks`: number of weeks.\nFor `specific_challenges`: use 0 (uses challenge_ids).\n",
                "minimum": 0,
                "example": 1
              },
              "challenge_ids": {
                "type": "array",
                "description": "IDs of challenges that must be completed.\nUsed only when `type: specific_challenges`.\n",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "is_hidden": {
            "type": "boolean",
            "description": "If `true`, the badge does not appear in the list of available badges.\nIt is revealed as a surprise only when the user unlocks it.\n",
            "example": false
          },
          "active": {
            "type": "boolean",
            "description": "If `false`, the badge can no longer be unlocked.\nBadges already earned by users remain visible.\n",
            "example": true
          },
          "metadata": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true,
            "description": "Custom metadata to store additional information.\nCan be filtered via query param `metadata[key]=value`.\n"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "BadgeCreate": {
        "type": "object",
        "required": [
          "slug",
          "name",
          "description",
          "rarity",
          "criteria"
        ],
        "properties": {
          "slug": {
            "type": "string",
            "minLength": 3,
            "maxLength": 50,
            "pattern": "^[a-z0-9-]+$",
            "example": "first-challenge"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255,
            "example": "First Step"
          },
          "description": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000,
            "example": "Complete your first challenge"
          },
          "icon_url": {
            "type": "string",
            "format": "uri"
          },
          "rarity": {
            "type": "string",
            "enum": [
              "common",
              "rare",
              "epic",
              "legendary"
            ]
          },
          "style": {
            "type": "object",
            "properties": {
              "variant": {
                "type": "string",
                "enum": [
                  "metallic",
                  "glass",
                  "neon",
                  "holographic",
                  "flat"
                ]
              },
              "background_color": {
                "type": "string"
              },
              "icon_color": {
                "type": "string"
              },
              "icon_name": {
                "type": "string"
              }
            }
          },
          "criteria": {
            "type": "object",
            "required": [
              "type"
            ],
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "count_challenges",
                  "streak_weeks",
                  "specific_challenges",
                  "manual"
                ]
              },
              "threshold": {
                "type": "integer",
                "minimum": 0,
                "default": 0
              },
              "challenge_ids": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "is_hidden": {
            "type": "boolean",
            "default": false
          },
          "active": {
            "type": "boolean",
            "default": true
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "BadgeUpdate": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "description": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "icon_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "rarity": {
            "type": "string",
            "enum": [
              "common",
              "rare",
              "epic",
              "legendary"
            ]
          },
          "style": {
            "type": "object",
            "properties": {
              "variant": {
                "type": "string",
                "enum": [
                  "metallic",
                  "glass",
                  "neon",
                  "holographic",
                  "flat"
                ]
              },
              "background_color": {
                "type": "string"
              },
              "icon_color": {
                "type": "string"
              },
              "icon_name": {
                "type": "string"
              }
            }
          },
          "criteria": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "count_challenges",
                  "streak_weeks",
                  "specific_challenges",
                  "manual"
                ]
              },
              "threshold": {
                "type": "integer",
                "minimum": 0
              },
              "challenge_ids": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "is_hidden": {
            "type": "boolean"
          },
          "active": {
            "type": "boolean"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "AwardBadgeRequest": {
        "type": "object",
        "required": [
          "user_id"
        ],
        "properties": {
          "user_id": {
            "type": "string",
            "description": "ID of the user who will receive the badge",
            "example": "507f1f77bcf86cd799439011"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "AwardBadgeResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "UserBadge record ID"
          },
          "user_id": {
            "type": "string"
          },
          "badge_id": {
            "type": "string"
          },
          "badge": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "slug": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "description": {
                "type": "string"
              },
              "rarity": {
                "type": "string"
              }
            }
          },
          "awarded_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Challenge": {
        "type": "object",
        "description": "**Challenge** is the main engagement mechanic of the loyalty program.\n\nChallenges are **activities** that users complete to earn **points**.\nThey are the engine that drives participation and keeps users engaged.\n\n### Challenge Types\n\n| Type | How to Complete | Use Case |\n|------|-----------------|----------|\n| `qrcode` | Scan a physical QR Code | In-store check-in, in-person events |\n| `action` | Via tracking API or staff | Purchases, app interactions, external actions |\n| `survey` | Answer a survey | Feedback, NPS, market research |\n\n### Frequency\n\nControls how many times a challenge can be completed:\n\n| Unit | Behavior |\n|------|----------|\n| `once` | One time only (never available again) |\n| `always-available` | Always available, no limit |\n| `days`, `weeks`, etc. | Cooldown period between completions |\n\n**Example**: `unit: days, interval: 7` = can be completed once per week.\n\n### Requirements\n\nChallenges can have **prerequisites** to be unlocked:\n- Have a specific badge\n- Have minimum accumulated points\n- Have completed another challenge\n- Have redeemed a specific reward\n\nThis allows creating **progressive engagement journeys**.\n\n### Availability Period\n\nUse `start_date` and `end_date` to create:\n- Seasonal challenges (Black Friday, Christmas)\n- Limited-time promotions\n- Campaigns with a future start date\n",
        "required": [
          "id",
          "title",
          "description",
          "points",
          "type",
          "frequency",
          "requirements",
          "active",
          "hidden",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique challenge identifier (MongoDB ObjectId)",
            "example": "507f1f77bcf86cd799439011"
          },
          "title": {
            "type": "string",
            "description": "Challenge title displayed to the user",
            "example": "First Purchase"
          },
          "description": {
            "type": "string",
            "description": "Detailed description of the challenge.\nClearly explain what the user needs to do.\n",
            "example": "Make your first purchase and earn 100 points"
          },
          "points": {
            "type": "integer",
            "description": "Points awarded upon completing the challenge.\nThese points are automatically added to the user's balance.\n",
            "minimum": 0,
            "example": 100
          },
          "type": {
            "type": "string",
            "description": "Challenge type that defines how it is completed:\n- `qrcode`: User scans a physical QR Code\n- `action`: Completed via tracking API or by staff\n- `survey`: User answers a linked survey\n",
            "enum": [
              "qrcode",
              "action",
              "survey"
            ],
            "example": "action"
          },
          "action_key": {
            "type": "string",
            "description": "Key for automatic action tracking.\nUsed only with `type: action`.\n\nWhen you call `POST /actions/track` with this `action_type`,\nthe challenge is automatically completed if available.\n\n**Example**: Set `action_key: \"purchase_completed\"` and\ncall `/actions/track` with `action_type: \"purchase_completed\"`\nafter each purchase.\n",
            "example": "purchase_completed"
          },
          "conditions": {
            "type": "array",
            "maxItems": 10,
            "description": "Optional predicates evaluated against the action `properties`.\nEvery condition must match before this action challenge is applied.\n",
            "items": {
              "type": "object",
              "required": [
                "property",
                "operator"
              ],
              "properties": {
                "property": {
                  "type": "string",
                  "example": "amount"
                },
                "operator": {
                  "type": "string",
                  "enum": [
                    "eq",
                    "neq",
                    "gt",
                    "gte",
                    "lt",
                    "lte",
                    "in",
                    "contains",
                    "exists"
                  ],
                  "example": "gte"
                },
                "value": {
                  "description": "Expected value. Omit for `exists` to check for presence.",
                  "example": 100
                }
              }
            }
          },
          "frequency": {
            "type": "object",
            "description": "Defines how many times the challenge can be completed.\nCombines a time unit with an interval.\n",
            "required": [
              "unit",
              "interval"
            ],
            "properties": {
              "unit": {
                "type": "string",
                "description": "Frequency unit:\n- `once`: Can be completed only once (lifetime)\n- `always-available`: Always available, can be completed unlimited times with no wait\n- `minutes`, `hours`, `days`, `weeks`, `months`: Cooldown period\n",
                "enum": [
                  "once",
                  "minutes",
                  "hours",
                  "days",
                  "weeks",
                  "months",
                  "always-available"
                ],
                "example": "days"
              },
              "interval": {
                "type": "integer",
                "description": "Cooldown interval between completions.\nE.g.: `unit: days, interval: 7` = once per week.\nIgnored for `once` and `always-available`.\n",
                "minimum": 1,
                "example": 7
              }
            }
          },
          "requirements": {
            "type": "array",
            "description": "Requirements the user must meet for the challenge\nto become available (unlocked). **All** must be met.\n\nUse to create progression and engagement journeys.\n\n### Requirement Types\n\n| Type | Description | Additional Field |\n|------|-------------|------------------|\n| `has-badge` | Must have a badge | `badge_id` |\n| `min-points` | Must have N accumulated points | `min_value` |\n| `completed-challenge` | Must have completed another challenge | `challenge_id` |\n| `min-challenge-completions` | Must have completed N challenges | `min_value` |\n| `claimed-reward` | Must have redeemed a reward | `reward_id` |\n| `min-tier` | Must have reached a minimum tier | `tier_slug` |\n| `min-streak` | Must have a minimum streak in a streak definition | `streak_id`, `min_value` |\n",
            "items": {
              "type": "object",
              "required": [
                "type"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "description": "Requirement type",
                  "enum": [
                    "has-badge",
                    "min-points",
                    "completed-challenge",
                    "min-challenge-completions",
                    "claimed-reward",
                    "min-tier",
                    "min-streak"
                  ]
                },
                "badge_id": {
                  "type": "string",
                  "description": "Required badge ID (for type `has-badge`)"
                },
                "challenge_id": {
                  "type": "string",
                  "description": "ID of the challenge that must be completed (for type `completed-challenge`)"
                },
                "reward_id": {
                  "type": "string",
                  "description": "ID of the reward that must be redeemed (for type `claimed-reward`)"
                },
                "tier_slug": {
                  "type": "string",
                  "description": "Required tier slug (for type `min-tier`)"
                },
                "streak_id": {
                  "type": "string",
                  "description": "Streak definition ID (for type `min-streak`)"
                },
                "min_value": {
                  "type": "integer",
                  "description": "Minimum required value (for types `min-points`, `min-challenge-completions`, and `min-streak`)",
                  "minimum": 1
                }
              },
              "example": {
                "type": "min-points",
                "min_value": 500
              }
            }
          },
          "streak_ids": {
            "type": "array",
            "description": "IDs of streak definitions that should be incremented when this challenge\nis completed.\n",
            "items": {
              "type": "string"
            }
          },
          "start_date": {
            "type": "string",
            "format": "date-time",
            "description": "Availability start date/time (UTC).\nBefore this date, the challenge does not appear or shows as \"Coming Soon\".\n"
          },
          "end_date": {
            "type": "string",
            "format": "date-time",
            "description": "Availability end date/time (UTC).\nAfter this date, the challenge can no longer be completed.\n"
          },
          "active": {
            "type": "boolean",
            "description": "If `false`, the challenge is deactivated and cannot be completed.\nUseful for temporarily pausing challenges without deleting them.\n",
            "example": true
          },
          "hidden": {
            "type": "boolean",
            "description": "If `true`, the challenge does not appear in public listings.\nCan be used for secret challenges or challenges in testing.\n",
            "example": false
          },
          "redirect_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "URL to redirect to after completing the challenge.\nPrimarily used with `type: qrcode` to show\na \"Congratulations!\" page or special offer.\n",
            "example": "https://example.com/thanks"
          },
          "metadata": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true,
            "description": "Custom metadata to store additional information.\n\n**Usage examples:**\n- `category`: challenge category (e.g., \"purchases\", \"social\")\n- `campaign`: campaign name (e.g., \"black-friday-2024\")\n- `partner`: associated partner\n\nCan be filtered via `?metadata[key]=value` in queries.\n"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ChallengeCreate": {
        "type": "object",
        "required": [
          "title",
          "description",
          "points"
        ],
        "properties": {
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "description": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "points": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000
          },
          "type": {
            "type": "string",
            "enum": [
              "qrcode",
              "action",
              "survey"
            ],
            "default": "action"
          },
          "action_key": {
            "type": "string",
            "maxLength": 100
          },
          "conditions": {
            "type": "array",
            "maxItems": 10,
            "description": "Predicates evaluated against action `properties`; all must match.",
            "items": {
              "type": "object",
              "required": [
                "property",
                "operator"
              ],
              "properties": {
                "property": {
                  "type": "string"
                },
                "operator": {
                  "type": "string",
                  "enum": [
                    "eq",
                    "neq",
                    "gt",
                    "gte",
                    "lt",
                    "lte",
                    "in",
                    "contains",
                    "exists"
                  ]
                },
                "value": {}
              }
            }
          },
          "frequency": {
            "type": "object",
            "properties": {
              "unit": {
                "type": "string",
                "enum": [
                  "once",
                  "minutes",
                  "hours",
                  "days",
                  "weeks",
                  "months",
                  "always-available"
                ],
                "default": "once"
              },
              "interval": {
                "type": "integer",
                "minimum": 1,
                "default": 1
              }
            }
          },
          "requirements": {
            "type": "array",
            "description": "Requirements to unlock (see Challenge.requirements)",
            "items": {
              "type": "object",
              "required": [
                "type"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "has-badge",
                    "min-points",
                    "completed-challenge",
                    "min-challenge-completions",
                    "claimed-reward",
                    "min-tier",
                    "min-streak"
                  ]
                },
                "badge_id": {
                  "type": "string"
                },
                "challenge_id": {
                  "type": "string"
                },
                "reward_id": {
                  "type": "string"
                },
                "tier_slug": {
                  "type": "string"
                },
                "streak_id": {
                  "type": "string"
                },
                "min_value": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            }
          },
          "streak_ids": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "start_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "end_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "active": {
            "type": "boolean",
            "default": true
          },
          "hidden": {
            "type": "boolean",
            "default": false
          },
          "redirect_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "URL to redirect to after completion (only for type `qrcode`)"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "ChallengeUpdate": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "description": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "points": {
            "type": "integer",
            "minimum": 0
          },
          "action_key": {
            "type": "string",
            "maxLength": 100
          },
          "conditions": {
            "type": "array",
            "maxItems": 10,
            "description": "Predicates evaluated against action `properties`; all must match.",
            "items": {
              "type": "object",
              "required": [
                "property",
                "operator"
              ],
              "properties": {
                "property": {
                  "type": "string"
                },
                "operator": {
                  "type": "string",
                  "enum": [
                    "eq",
                    "neq",
                    "gt",
                    "gte",
                    "lt",
                    "lte",
                    "in",
                    "contains",
                    "exists"
                  ]
                },
                "value": {}
              }
            }
          },
          "frequency": {
            "type": "object",
            "properties": {
              "unit": {
                "type": "string",
                "enum": [
                  "once",
                  "minutes",
                  "hours",
                  "days",
                  "weeks",
                  "months",
                  "always-available"
                ]
              },
              "interval": {
                "type": "integer",
                "minimum": 1
              }
            }
          },
          "requirements": {
            "type": "array",
            "description": "Requirements to unlock (see Challenge.requirements)",
            "items": {
              "type": "object",
              "required": [
                "type"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "has-badge",
                    "min-points",
                    "completed-challenge",
                    "min-challenge-completions",
                    "claimed-reward",
                    "min-tier",
                    "min-streak"
                  ]
                },
                "badge_id": {
                  "type": "string"
                },
                "challenge_id": {
                  "type": "string"
                },
                "reward_id": {
                  "type": "string"
                },
                "tier_slug": {
                  "type": "string"
                },
                "streak_id": {
                  "type": "string"
                },
                "min_value": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            }
          },
          "streak_ids": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "start_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "end_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "active": {
            "type": "boolean"
          },
          "hidden": {
            "type": "boolean"
          },
          "redirect_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "URL to redirect to after completion (only for type `qrcode`)"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "CompleteChallengeRequest": {
        "type": "object",
        "required": [
          "user_id"
        ],
        "properties": {
          "user_id": {
            "type": "string",
            "description": "ID of the user who completed the challenge",
            "example": "507f1f77bcf86cd799439011"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "CompleteChallengeResponse": {
        "type": "object",
        "properties": {
          "completion_id": {
            "type": "string",
            "description": "Completion record ID"
          },
          "user_id": {
            "type": "string"
          },
          "challenge_id": {
            "type": "string"
          },
          "points_earned": {
            "type": "integer"
          },
          "new_balance": {
            "type": "integer"
          },
          "badges_awarded": {
            "type": "array",
            "description": "Badges unlocked with this completion",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "slug": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                }
              }
            }
          },
          "completed_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ChallengeAvailabilityChecks": {
        "type": "object",
        "description": "Availability of a challenge for one user, check by check.",
        "properties": {
          "available": {
            "type": "boolean"
          },
          "reasons": {
            "type": "object",
            "properties": {
              "is_active": {
                "type": "boolean"
              },
              "within_time_window": {
                "type": "boolean"
              },
              "frequency_allows": {
                "type": "boolean"
              },
              "requirements_met": {
                "type": "boolean"
              }
            }
          },
          "unmet_requirements": {
            "type": "array",
            "description": "Human-readable reasons for each unmet requirement.",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "QrCode": {
        "type": "object",
        "required": [
          "id",
          "name",
          "type",
          "target_id",
          "target_url",
          "app_path",
          "color",
          "background_color",
          "style",
          "active",
          "scans",
          "last_scan_at",
          "scan_url",
          "image_url",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "challenge",
              "url",
              "app_page",
              "guild"
            ]
          },
          "target_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "Challenge or guild ID (`challenge` and `guild` types)"
          },
          "target_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "Destination URL (`url` type)"
          },
          "app_path": {
            "type": [
              "string",
              "null"
            ],
            "description": "Hosted portal page (`app_page` type), such as `/user/menu`"
          },
          "color": {
            "type": "string",
            "example": "#000000"
          },
          "background_color": {
            "type": "string",
            "example": "#ffffff"
          },
          "style": {
            "type": "string",
            "enum": [
              "square",
              "dots",
              "rounded"
            ]
          },
          "active": {
            "type": "boolean",
            "description": "Inactive QR codes answer scans with `410 Gone`"
          },
          "scans": {
            "type": "integer",
            "description": "Lifetime scans"
          },
          "last_scan_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "scan_url": {
            "type": "string",
            "format": "uri",
            "description": "URL encoded in the QR (records the scan and redirects)"
          },
          "image_url": {
            "type": "object",
            "description": "Image endpoints (Secret Key required)",
            "properties": {
              "png": {
                "type": "string",
                "format": "uri"
              },
              "svg": {
                "type": "string",
                "format": "uri"
              }
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "QrCodeCreate": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "type"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "type": {
            "type": "string",
            "enum": [
              "challenge",
              "url",
              "app_page",
              "guild"
            ]
          },
          "target_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "Required for `challenge` and `guild`"
          },
          "target_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "Required for `url` (HTTP or HTTPS)"
          },
          "app_path": {
            "type": [
              "string",
              "null"
            ],
            "description": "For `app_page`. A hosted portal path (`/user/...` or `/guilds`); default `/user/menu`",
            "example": "/user/menu"
          },
          "color": {
            "type": "string",
            "pattern": "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$",
            "default": "#000000"
          },
          "background_color": {
            "type": "string",
            "pattern": "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$",
            "default": "#ffffff"
          },
          "style": {
            "type": "string",
            "enum": [
              "square",
              "dots",
              "rounded"
            ],
            "default": "square"
          },
          "active": {
            "type": "boolean",
            "default": true
          }
        }
      },
      "QrError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "type",
              "message"
            ],
            "properties": {
              "type": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "QrCodeUpdate": {
        "type": "object",
        "additionalProperties": false,
        "minProperties": 1,
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "type": {
            "type": "string",
            "enum": [
              "challenge",
              "url",
              "app_page",
              "guild"
            ]
          },
          "target_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "target_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "app_path": {
            "type": [
              "string",
              "null"
            ]
          },
          "color": {
            "type": "string",
            "pattern": "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"
          },
          "background_color": {
            "type": "string",
            "pattern": "^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$"
          },
          "style": {
            "type": "string",
            "enum": [
              "square",
              "dots",
              "rounded"
            ]
          },
          "active": {
            "type": "boolean"
          }
        }
      },
      "QrCodeScans": {
        "type": "object",
        "required": [
          "qrcode_id",
          "from",
          "to",
          "timezone",
          "total",
          "lifetime_scans",
          "last_scan_at",
          "by_day",
          "by_channel",
          "by_device",
          "by_browser",
          "by_os"
        ],
        "properties": {
          "qrcode_id": {
            "type": "string"
          },
          "from": {
            "type": "string",
            "format": "date-time"
          },
          "to": {
            "type": "string",
            "format": "date-time"
          },
          "timezone": {
            "type": "string",
            "example": "America/Sao_Paulo"
          },
          "total": {
            "type": "integer",
            "description": "Scans in the window (staff tests excluded)"
          },
          "lifetime_scans": {
            "type": "integer"
          },
          "last_scan_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "by_day": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "date": {
                  "type": "string",
                  "format": "date"
                },
                "scans": {
                  "type": "integer"
                }
              }
            }
          },
          "by_channel": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "channel": {
                  "type": "string",
                  "enum": [
                    "counter",
                    "table",
                    "whatsapp",
                    "unknown"
                  ]
                },
                "scans": {
                  "type": "integer"
                }
              }
            }
          },
          "by_device": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "device": {
                  "type": "string",
                  "example": "Mobile"
                },
                "scans": {
                  "type": "integer"
                }
              }
            }
          },
          "by_browser": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "browser": {
                  "type": "string",
                  "example": "Safari"
                },
                "scans": {
                  "type": "integer"
                }
              }
            }
          },
          "by_os": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "os": {
                  "type": "string",
                  "example": "iOS"
                },
                "scans": {
                  "type": "integer"
                }
              }
            }
          }
        }
      },
      "Reward": {
        "type": "object",
        "description": "**Reward** is the prize that users can redeem using their points.\n\nRewards are the **ultimate goal** of the loyalty program — the reason\nwhy users engage and complete challenges.\n\n### How Redemption Works\n\n1. User accumulates points by completing challenges\n2. User chooses a desired reward\n3. System checks: sufficient points + requirements met + availability\n4. Points are debited and a `RewardClaim` is created\n5. Business delivers the physical/digital reward\n\n### Monetary Cost\n\nThe `monetary_cost` field records how much the reward costs the\nbusiness (in currency). This allows:\n- Calculating program ROI\n- Cost per customer reports\n- Intelligent point pricing\n\n### Usage Rules\n\n| Field | Behavior |\n|-------|----------|\n| `single_use: true` | Can be redeemed only once per user |\n| `cooldown_days: 7` | After redeeming, must wait 7 days to redeem again |\n| `hide_if_locked: true` | Does not appear if the user does not meet the requirements |\n\n### Availability Period\n\nUse `start_date` and `end_date` to create rewards:\n- Seasonal (e.g., \"Christmas Panettone\" — December only)\n- Promotional (e.g., \"Black Friday Discount\" — 3 days only)\n- Future (e.g., announce before making available)\n\n### Requirements\n\nLike challenges, rewards can have prerequisites:\n- Have a specific badge (e.g., \"VIP only\")\n- Have completed a specific challenge\n- Have minimum accumulated points (lifetime, not current)\n",
        "required": [
          "id",
          "title",
          "description",
          "price",
          "monetary_cost",
          "single_use",
          "cooldown_days",
          "hide_if_locked",
          "active",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique reward identifier (MongoDB ObjectId)",
            "example": "507f1f77bcf86cd799439011"
          },
          "title": {
            "type": "string",
            "description": "Reward name displayed to the user",
            "example": "Free Coffee"
          },
          "description": {
            "type": "string",
            "description": "Detailed description of the reward.\nInclude information about how to claim, restrictions, validity, etc.\n",
            "example": "Redeem a free espresso at any location"
          },
          "price": {
            "type": "integer",
            "description": "Cost in points to redeem this reward.\nThese points will be debited from the user's balance.\n",
            "minimum": 0,
            "example": 500
          },
          "monetary_cost": {
            "type": "number",
            "description": "Actual monetary cost for the business (in currency).\nUsed for ROI calculations and financial reports.\nNot shown to the end user.\n",
            "minimum": 0,
            "example": 5.5
          },
          "single_use": {
            "type": "boolean",
            "description": "If `true`, each user can redeem this reward only once.\nIdeal for: welcome gifts, exclusive offers.\n",
            "example": false
          },
          "cooldown_days": {
            "type": "integer",
            "description": "Mandatory waiting days between redemptions by the same user.\nUse `0` to allow unlimited redemptions (no cooldown).\n\n**Example**: `cooldown_days: 30` = maximum once per month.\n",
            "minimum": 0,
            "example": 7
          },
          "start_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Availability start date/time (UTC).\nBefore this date, the reward cannot be redeemed.\n"
          },
          "end_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Availability end date/time (UTC).\nAfter this date, the reward can no longer be redeemed.\n"
          },
          "requirements": {
            "type": "array",
            "description": "Requirements the user must meet to redeem.\n**All** requirements must be met simultaneously.\n\nUse to create exclusive rewards or program progression.\n",
            "items": {
              "type": "object",
              "required": [
                "type"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "has-badge",
                    "min-points",
                    "completed-challenge",
                    "min-challenge-completions",
                    "claimed-reward",
                    "min-tier",
                    "min-streak"
                  ]
                },
                "badge_id": {
                  "type": "string",
                  "description": "Badge ID (for type `has-badge`)"
                },
                "challenge_id": {
                  "type": "string",
                  "description": "Challenge ID (for type `completed-challenge`)"
                },
                "reward_id": {
                  "type": "string",
                  "description": "Reward ID (for type `claimed-reward`)"
                },
                "tier_slug": {
                  "type": "string",
                  "description": "Tier slug (for type `min-tier`)"
                },
                "streak_id": {
                  "type": "string",
                  "description": "Streak definition ID (for type `min-streak`)"
                },
                "min_value": {
                  "type": "integer",
                  "description": "Minimum value (for types `min-points`, `min-challenge-completions`, and `min-streak`)",
                  "minimum": 1
                }
              }
            }
          },
          "hide_if_locked": {
            "type": "boolean",
            "description": "If `true`, the reward does not appear in listings when the\nuser does not meet the requirements.\n\nUse to keep the interface clean or create \"surprises\".\n",
            "example": false
          },
          "active": {
            "type": "boolean",
            "description": "If `false`, the reward is deactivated and cannot be redeemed.\nUseful for temporarily pausing without deleting.\n",
            "example": true
          },
          "metadata": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true,
            "description": "Custom metadata to store additional information.\n\n**Usage examples:**\n- `category`: category (e.g., \"beverages\", \"discounts\", \"products\")\n- `sku`: product code in the system\n- `supplier`: supplier\n\nCan be filtered via `?metadata[key]=value` in queries.\n"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "RewardCatalog": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Reward"
          },
          {
            "type": "object",
            "properties": {
              "reward_type": {
                "type": "string",
                "enum": [
                  "percentage",
                  "fixed_amount",
                  "free_item",
                  "custom"
                ]
              },
              "value": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "stock": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Total units (null = unlimited)"
              },
              "stock_remaining": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "`stock` minus redemptions (null = unlimited)"
              },
              "instructions": {
                "type": "string"
              },
              "campaign_id": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Campaign that owns this reward; edit and redeem it through the campaign"
              }
            }
          }
        ]
      },
      "RewardCreate": {
        "type": "object",
        "required": [
          "title",
          "description",
          "price"
        ],
        "properties": {
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "description": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "price": {
            "type": "integer",
            "minimum": 0
          },
          "monetary_cost": {
            "type": "number",
            "minimum": 0,
            "default": 0
          },
          "single_use": {
            "type": "boolean",
            "default": false
          },
          "cooldown_days": {
            "type": "integer",
            "minimum": 0,
            "default": 0
          },
          "start_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "end_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "requirements": {
            "type": "array",
            "description": "Requirements to redeem (see Reward.requirements)",
            "items": {
              "type": "object",
              "required": [
                "type"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "has-badge",
                    "min-points",
                    "completed-challenge",
                    "min-challenge-completions",
                    "claimed-reward",
                    "min-tier",
                    "min-streak"
                  ]
                },
                "badge_id": {
                  "type": "string"
                },
                "challenge_id": {
                  "type": "string"
                },
                "reward_id": {
                  "type": "string"
                },
                "tier_slug": {
                  "type": "string"
                },
                "streak_id": {
                  "type": "string"
                },
                "min_value": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            }
          },
          "hide_if_locked": {
            "type": "boolean",
            "default": false
          },
          "active": {
            "type": "boolean",
            "default": true
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "RewardCatalogInput": {
        "type": "object",
        "properties": {
          "reward_type": {
            "type": "string",
            "enum": [
              "percentage",
              "fixed_amount",
              "free_item",
              "custom"
            ],
            "default": "custom"
          },
          "value": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "maximum": 1000000,
            "description": "Required and positive for `percentage` (up to 100) and `fixed_amount`"
          },
          "stock": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "maximum": 10000000,
            "description": "Total units; null or omitted means unlimited"
          },
          "instructions": {
            "type": "string",
            "maxLength": 1000
          }
        }
      },
      "RewardError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "example": "reward_managed_by_campaign"
              },
              "message": {
                "type": "string"
              },
              "details": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        }
      },
      "RewardUpdate": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "description": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000
          },
          "price": {
            "type": "integer",
            "minimum": 0
          },
          "monetary_cost": {
            "type": "number",
            "minimum": 0
          },
          "single_use": {
            "type": "boolean"
          },
          "cooldown_days": {
            "type": "integer",
            "minimum": 0
          },
          "start_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "end_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "requirements": {
            "type": "array",
            "description": "Requirements to redeem (see Reward.requirements)",
            "items": {
              "type": "object",
              "required": [
                "type"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "has-badge",
                    "min-points",
                    "completed-challenge",
                    "min-challenge-completions",
                    "claimed-reward",
                    "min-tier",
                    "min-streak"
                  ]
                },
                "badge_id": {
                  "type": "string"
                },
                "challenge_id": {
                  "type": "string"
                },
                "reward_id": {
                  "type": "string"
                },
                "tier_slug": {
                  "type": "string"
                },
                "streak_id": {
                  "type": "string"
                },
                "min_value": {
                  "type": "integer",
                  "minimum": 1
                }
              }
            }
          },
          "hide_if_locked": {
            "type": "boolean"
          },
          "active": {
            "type": "boolean"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "RedeemRewardRequest": {
        "type": "object",
        "required": [
          "user_id"
        ],
        "properties": {
          "user_id": {
            "type": "string",
            "description": "ID of the user who is redeeming",
            "example": "507f1f77bcf86cd799439011"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "RedeemRewardResult": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Redemption record ID"
          },
          "user_id": {
            "type": "string"
          },
          "reward_id": {
            "type": "string"
          },
          "reward": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "title": {
                "type": "string"
              },
              "description": {
                "type": "string"
              },
              "price": {
                "type": "integer"
              },
              "stock_remaining": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Units left after this redemption (null = unlimited)"
              }
            }
          },
          "points_spent": {
            "type": "integer"
          },
          "user_balance_after": {
            "type": "integer"
          },
          "redeemed_at": {
            "type": "string",
            "format": "date-time"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "RewardAvailabilityResult": {
        "type": "object",
        "properties": {
          "available": {
            "type": "boolean"
          },
          "reward_id": {
            "type": "string"
          },
          "user_id": {
            "type": "string"
          },
          "checks": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string",
                  "enum": [
                    "redemption_channel",
                    "reward_active",
                    "time_window",
                    "sufficient_points",
                    "single_use",
                    "cooldown",
                    "stock",
                    "requirements"
                  ]
                },
                "passed": {
                  "type": "boolean"
                },
                "reason": {
                  "type": "string"
                },
                "details": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "summary": {
            "type": "object",
            "properties": {
              "total_checks": {
                "type": "integer"
              },
              "passed": {
                "type": "integer"
              },
              "failed": {
                "type": "integer"
              }
            }
          }
        }
      },
      "TrackActionRequest": {
        "type": "object",
        "description": "Request to track a user action.\n\n**Actions** are the integration mechanism between your system and the loyalty\nprogram. When something relevant happens (purchase, check-in, referral),\nyou notify the API and it automatically:\n\n1. Searches for challenges of type `action` that have the `action_key` field equal to the `action_type` sent\n2. Checks availability for the user\n3. Completes eligible challenges\n4. Awards points and evaluates badges\n\n### Setup\n\nTo use this endpoint, you need to:\n\n1. **Create a challenge** with `type: \"action\"` and set the `action_key` field\n   - E.g.: `POST /challenges` with `{ type: \"action\", action_key: \"purchase_completed\", ... }`\n\n2. **Call this endpoint** when the action occurs in your system\n   - E.g.: `POST /actions/track` with `{ action_type: \"purchase_completed\", ... }`\n\nThe system will match between `action_type` (sent here) and `action_key` (from the challenge).\n\n### Example Flow\n\n```\nYour System                      Experi API\n─────────────────────────────────────────────\nPurchase completed\n     │\n     ├──► POST /actions/track\n     │    { action_type: \"purchase\" }\n     │                                   │\n     │                    Search          │\n     │                    challenges with │\n     │                    action_key      │\n     │                    = \"purchase\"    │\n     │                                   │\n     │                    Complete        │\n     │                    available       │\n     │                    challenges      │\n     │                                   │\n     │◄── { challenges_completed: [...] }\n```\n",
        "required": [
          "user_id",
          "action_type"
        ],
        "properties": {
          "user_id": {
            "type": "string",
            "description": "Engine user ID or the `external_id` supplied when the user was created.\nPrefer `external_id` so your integration does not need to persist an\nadditional identifier.\n",
            "example": "customer_123"
          },
          "action_type": {
            "type": "string",
            "description": "Action identifier/type (1-100 characters).\n\nThis value will be compared with the `action_key` of challenges.\nChallenges with a matching `action_key` will be automatically completed.\n\n**Best practices:**\n- Use snake_case: `purchase_completed`, `friend_referred`\n- Be specific: `store_checkin` instead of just `checkin`\n- Keep consistency across systems\n",
            "minLength": 1,
            "maxLength": 100,
            "example": "purchase_completed"
          },
          "properties": {
            "type": "object",
            "description": "Additional data about the action (optional). Up to 50 top-level keys\nand 32 KB when serialized as JSON.\n\nUseful for:\n- Evaluating challenge `conditions`\n- Recording context (purchase amount, product, location)\n- Sending context through configured action webhooks\n\nOperational event logs retain property names, not their values. Values\nmay still be included in webhook delivery payloads for up to 30 days.\n",
            "additionalProperties": true,
            "maxProperties": 50,
            "example": {
              "order_id": "ORD-123",
              "amount": 150
            }
          },
          "timestamp": {
            "type": "string",
            "format": "date-time",
            "description": "Custom action timestamp (ISO 8601, UTC).\n\nIf not provided, uses the current time.\n\nUse to record retroactive actions or when your system's\ntimestamp differs from the API call time.\n",
            "example": "2024-01-15T14:30:00Z"
          }
        }
      },
      "TrackActionResponse": {
        "type": "object",
        "description": "Action tracking response, including completed challenges and earned badges.\n",
        "properties": {
          "success": {
            "type": "boolean",
            "description": "Whether the action was successfully tracked"
          },
          "user_id": {
            "type": "string",
            "description": "User ID"
          },
          "points_earned": {
            "type": "integer",
            "description": "Total points earned with this action (sum of all challenges)"
          },
          "challenges_completed": {
            "type": "array",
            "description": "List of challenges that were automatically completed by this action.\nEmpty if no challenge had a matching `action_key` or was available.\n",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "title": {
                  "type": "string"
                },
                "points": {
                  "type": "integer"
                }
              }
            }
          },
          "badges_earned": {
            "type": "array",
            "description": "Badges that were unlocked as a result of the completions.\nHappens when the user meets the criteria of a badge.\n",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "slug": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "rarity": {
                  "type": "string",
                  "enum": [
                    "common",
                    "uncommon",
                    "rare",
                    "epic",
                    "legendary"
                  ]
                }
              }
            }
          },
          "summary": {
            "type": "object",
            "properties": {
              "challenges_triggered": {
                "type": "integer"
              },
              "challenges_completed": {
                "type": "integer"
              },
              "badges_earned": {
                "type": "integer"
              },
              "total_points_earned": {
                "type": "integer"
              }
            }
          }
        }
      },
      "LeaderboardEntry": {
        "type": "object",
        "description": "A leaderboard position",
        "required": [
          "rank",
          "user_id",
          "user",
          "value"
        ],
        "properties": {
          "rank": {
            "type": "integer",
            "description": "Position (ties share the rank; 1 = first place)",
            "example": 1
          },
          "user_id": {
            "type": "string",
            "description": "User ID"
          },
          "user": {
            "type": "object",
            "required": [
              "id",
              "name"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "avatar_url": {
                "type": "string",
                "format": "uri",
                "description": "Present when the user has a picture"
              }
            }
          },
          "value": {
            "type": "integer",
            "description": "Balance (`points`), completions (`challenges`) or badges (`badges`)"
          }
        }
      },
      "Leaderboard": {
        "type": "object",
        "description": "**Leaderboard** (ranking) of users by one metric.\n\n- **All-time ranking (`all`)**: recognizes long-term engagement\n- **Monthly ranking**: lets new users compete with equal chances\n- **Weekly ranking**: creates urgency and frequent engagement\n",
        "required": [
          "type",
          "period",
          "period_start",
          "entries",
          "total_entries"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "points",
              "challenges",
              "badges"
            ],
            "description": "Leaderboard type (metric used for ranking)"
          },
          "period": {
            "type": "string",
            "enum": [
              "all",
              "month",
              "week"
            ],
            "description": "Period applied (always `all` for `points`)"
          },
          "period_start": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Start of the period in the project timezone (`null` for `all`)"
          },
          "entries": {
            "type": "array",
            "description": "Ordered positions",
            "items": {
              "$ref": "#/components/schemas/LeaderboardEntry"
            }
          },
          "total_entries": {
            "type": "integer",
            "description": "Number of entries returned"
          },
          "user_position": {
            "$ref": "#/components/schemas/LeaderboardEntry"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "type",
              "message"
            ],
            "properties": {
              "type": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "details": {}
            }
          }
        }
      },
      "GuildPerk": {
        "type": "object",
        "required": [
          "min_level",
          "type",
          "value",
          "label",
          "description",
          "active"
        ],
        "properties": {
          "min_level": {
            "type": "integer",
            "minimum": 1,
            "example": 3
          },
          "type": {
            "type": "string",
            "enum": [
              "challenge_points_multiplier",
              "xp_boost",
              "reward_discount"
            ],
            "example": "challenge_points_multiplier"
          },
          "value": {
            "type": "number",
            "description": "Multiplier (1–5) for `challenge_points_multiplier` and `xp_boost`;\nfraction (0–0.9) for `reward_discount`.\n",
            "example": 1.05
          },
          "label": {
            "type": [
              "string",
              "null"
            ],
            "example": "Bronze Momentum"
          },
          "description": {
            "type": [
              "string",
              "null"
            ],
            "example": "+5% challenge points for guild members."
          },
          "active": {
            "type": "boolean",
            "example": true
          }
        }
      },
      "Guild": {
        "type": "object",
        "description": "**Guild** (group or clan): users that accumulate XP together.\n",
        "required": [
          "id",
          "name",
          "slug",
          "description",
          "icon_url",
          "leader_id",
          "total_xp",
          "level",
          "next_level_xp",
          "max_members",
          "is_private",
          "is_official",
          "perks",
          "active_perks",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "example": "507f1f77bcf86cd799439070"
          },
          "name": {
            "type": "string",
            "example": "Night Owls"
          },
          "slug": {
            "type": "string",
            "example": "night-owls"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "icon_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "leader_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "`null` for guilds without a leader"
          },
          "total_xp": {
            "type": "number",
            "example": 2500
          },
          "level": {
            "type": "integer",
            "example": 6
          },
          "next_level_xp": {
            "type": "integer",
            "description": "Total XP needed for the next level",
            "example": 3600
          },
          "max_members": {
            "type": "integer",
            "example": 50
          },
          "member_count": {
            "type": "integer",
            "description": "Present in lists, details and after mutations",
            "example": 12
          },
          "is_private": {
            "type": "boolean",
            "description": "Joining from the hosted portal requires an invite"
          },
          "is_official": {
            "type": "boolean",
            "description": "Created by the project team (console or Studio)"
          },
          "perks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/GuildPerk"
            }
          },
          "active_perks": {
            "type": "array",
            "description": "Perks unlocked at the current level",
            "items": {
              "$ref": "#/components/schemas/GuildPerk"
            }
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "GuildPerkInput": {
        "type": "object",
        "required": [
          "min_level",
          "type",
          "value"
        ],
        "properties": {
          "min_level": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "description": "Alias `minLevel` accepted"
          },
          "type": {
            "type": "string",
            "enum": [
              "challenge_points_multiplier",
              "xp_boost",
              "reward_discount"
            ]
          },
          "value": {
            "type": "number",
            "exclusiveMinimum": 0,
            "description": "Multiplier between 1 and 5 for `challenge_points_multiplier` and\n`xp_boost`; fraction up to 0.9 for `reward_discount`.\n"
          },
          "label": {
            "type": "string",
            "maxLength": 60
          },
          "description": {
            "type": "string",
            "maxLength": 200
          },
          "active": {
            "type": "boolean",
            "default": true
          }
        }
      },
      "GuildCreate": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 3,
            "maxLength": 50
          },
          "slug": {
            "type": "string",
            "minLength": 3,
            "maxLength": 50,
            "pattern": "^[a-z0-9-]+$",
            "description": "Generated from the name when omitted"
          },
          "description": {
            "type": "string",
            "maxLength": 500
          },
          "icon_url": {
            "type": "string",
            "format": "uri",
            "description": "Aliases `avatarUrl` and `icon` accepted"
          },
          "is_private": {
            "type": "boolean",
            "default": false,
            "description": "Alias `isPrivate` accepted"
          },
          "leader_id": {
            "type": "string",
            "description": "User who becomes the leader (alias `leaderId` accepted)"
          },
          "max_members": {
            "type": "integer",
            "minimum": 1,
            "maximum": 9999,
            "default": 50,
            "description": "Alias `maxMembers` accepted"
          },
          "perks": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/GuildPerkInput"
            }
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "GuildUpdate": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 3,
            "maxLength": 50
          },
          "description": {
            "type": "string",
            "maxLength": 500
          },
          "icon_url": {
            "type": "string",
            "format": "uri"
          },
          "is_private": {
            "type": "boolean"
          },
          "max_members": {
            "type": "integer",
            "minimum": 1,
            "maximum": 9999
          },
          "perks": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/GuildPerkInput"
            }
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "GuildMember": {
        "type": "object",
        "description": "**Guild member**: the association of a user to a guild.\n",
        "required": [
          "id",
          "guild_id",
          "user_id",
          "role",
          "joined_at",
          "contributed_xp"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Membership identifier (use it as `starting_after`)"
          },
          "guild_id": {
            "type": "string"
          },
          "user_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "user": {
            "type": "object",
            "description": "Present when listing members",
            "required": [
              "id",
              "name",
              "avatar_url"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "avatar_url": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "uri"
              }
            }
          },
          "role": {
            "type": "string",
            "enum": [
              "member",
              "officer",
              "leader"
            ]
          },
          "joined_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "contributed_xp": {
            "type": "number",
            "description": "XP this user generated for the guild"
          }
        }
      },
      "CommunityGoalReward": {
        "type": "object",
        "description": "Reward granted on completion to each eligible contributor.",
        "required": [
          "points",
          "min_contribution",
          "reward_id"
        ],
        "properties": {
          "points": {
            "type": "integer",
            "minimum": 0,
            "description": "Points credited to each eligible contributor (0 = none)",
            "example": 100
          },
          "min_contribution": {
            "type": "integer",
            "minimum": 1,
            "description": "Minimum individual contribution, in the goal's metric unit",
            "example": 3
          },
          "reward_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "Reward granted for free (no points charged)",
            "example": null
          }
        }
      },
      "CommunityGoalRewardSummary": {
        "type": "object",
        "required": [
          "users_rewarded",
          "points_awarded",
          "rewards_granted",
          "distributed_at"
        ],
        "properties": {
          "users_rewarded": {
            "type": "integer",
            "example": 42
          },
          "points_awarded": {
            "type": "integer",
            "example": 4200
          },
          "rewards_granted": {
            "type": "integer",
            "example": 0
          },
          "distributed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "skipped_reason": {
            "type": "string",
            "enum": [
              "reward_not_found",
              "reward_inactive"
            ],
            "description": "Why the reward item could not be granted (points still are)"
          }
        }
      },
      "CommunityGoal": {
        "type": "object",
        "description": "Community-wide collaborative goal.",
        "required": [
          "id",
          "title",
          "metric_type",
          "target_value",
          "current_value",
          "progress_percent",
          "status",
          "active",
          "contributors_count",
          "start_date",
          "end_date",
          "completed_at",
          "failed_at",
          "reward",
          "reward_status",
          "reward_summary",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "example": "507f1f77bcf86cd799439060"
          },
          "title": {
            "type": "string",
            "example": "500 workouts this month"
          },
          "description": {
            "type": "string",
            "description": "Present when set",
            "example": "Hit the target together and everyone who joined earns a bonus."
          },
          "metric_type": {
            "type": "string",
            "enum": [
              "challenge-completions",
              "points-earned"
            ],
            "example": "challenge-completions"
          },
          "target_value": {
            "type": "integer",
            "example": 500
          },
          "current_value": {
            "type": "integer",
            "example": 324
          },
          "progress_percent": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100,
            "example": 64
          },
          "status": {
            "type": "string",
            "enum": [
              "scheduled",
              "active",
              "completed",
              "failed"
            ],
            "example": "active"
          },
          "active": {
            "type": "boolean",
            "description": "`false` pauses the goal (no contributions)",
            "example": true
          },
          "contributors_count": {
            "type": "integer",
            "example": 78
          },
          "start_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "end_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "completed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "failed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "When the deadline passed (or the goal was closed) without reaching the target"
          },
          "reward": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/CommunityGoalReward"
              },
              {
                "type": "null"
              }
            ]
          },
          "reward_status": {
            "type": "string",
            "enum": [
              "none",
              "pending",
              "distributed"
            ],
            "example": "none"
          },
          "reward_summary": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/CommunityGoalRewardSummary"
              },
              {
                "type": "null"
              }
            ]
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CommunityGoalRewardInput": {
        "type": "object",
        "properties": {
          "points": {
            "type": "integer",
            "minimum": 0,
            "maximum": 1000000,
            "default": 0,
            "description": "Points credited to each eligible contributor"
          },
          "min_contribution": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000000,
            "default": 1,
            "description": "Minimum individual contribution to be eligible"
          },
          "reward_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "ID of a reward of this project, granted for free to each eligible\ncontributor (emits `reward.redeemed` with `points_spent: 0`).\n"
          }
        }
      },
      "CommunityGoalCreate": {
        "type": "object",
        "required": [
          "title",
          "metric_type",
          "target_value"
        ],
        "properties": {
          "title": {
            "type": "string",
            "minLength": 3,
            "maxLength": 120
          },
          "description": {
            "type": "string",
            "maxLength": 500
          },
          "metric_type": {
            "type": "string",
            "enum": [
              "challenge-completions",
              "points-earned"
            ]
          },
          "target_value": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000000
          },
          "active": {
            "type": "boolean",
            "default": true
          },
          "start_date": {
            "type": "string",
            "format": "date-time",
            "description": "Future dates create a `scheduled` goal"
          },
          "end_date": {
            "type": "string",
            "format": "date-time",
            "description": "Must be after `start_date` and in the future"
          },
          "reward": {
            "$ref": "#/components/schemas/CommunityGoalRewardInput"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "CommunityGoalUpdate": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string",
            "minLength": 3,
            "maxLength": 120
          },
          "description": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 500
          },
          "metric_type": {
            "type": "string",
            "enum": [
              "challenge-completions",
              "points-earned"
            ]
          },
          "target_value": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100000000
          },
          "active": {
            "type": "boolean"
          },
          "start_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "end_date": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "reward": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/CommunityGoalRewardInput"
              },
              {
                "type": "null"
              }
            ]
          },
          "metadata": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true
          }
        }
      },
      "CommunityGoalLeaderboardEntry": {
        "type": "object",
        "required": [
          "rank",
          "user_id",
          "name",
          "value"
        ],
        "properties": {
          "rank": {
            "type": "integer",
            "example": 1
          },
          "user_id": {
            "type": "string",
            "example": "507f1f77bcf86cd799439011"
          },
          "name": {
            "type": [
              "string",
              "null"
            ],
            "example": "John Smith"
          },
          "avatar_url": {
            "type": "string",
            "format": "uri",
            "description": "Present when the user has a picture"
          },
          "value": {
            "type": "integer",
            "description": "The user's own contribution to the goal",
            "example": 42
          }
        }
      },
      "CountdownIncrement": {
        "type": "object",
        "required": [
          "challenge_id",
          "amount",
          "unit"
        ],
        "properties": {
          "challenge_id": {
            "type": "string",
            "description": "Challenge of this project whose completions move the end",
            "example": "507f1f77bcf86cd799439033"
          },
          "amount": {
            "type": "integer",
            "description": "Time added on each completion (negative shortens; never 0)",
            "example": 5
          },
          "unit": {
            "type": "string",
            "enum": [
              "days",
              "hours",
              "minutes",
              "seconds"
            ],
            "example": "minutes"
          }
        }
      },
      "Countdown": {
        "type": "object",
        "required": [
          "id",
          "name",
          "end_time",
          "active",
          "state",
          "remaining_seconds",
          "challenge_time_increments",
          "public_url",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "example": "507f1f77bcf86cd799439080"
          },
          "name": {
            "type": "string",
            "example": "Launch week"
          },
          "end_time": {
            "type": "string",
            "format": "date-time"
          },
          "active": {
            "type": "boolean"
          },
          "state": {
            "type": "string",
            "enum": [
              "running",
              "ended",
              "inactive"
            ],
            "description": "`inactive` when `active` is false; `ended` once `end_time` passed"
          },
          "remaining_seconds": {
            "type": "integer",
            "minimum": 0,
            "example": 86400
          },
          "challenge_time_increments": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CountdownIncrement"
            }
          },
          "public_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "Public screen of the countdown on the project's portal host",
            "example": "https://acme.experi.com.br/public-countdown/507f1f77bcf86cd799439080"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CountdownCreate": {
        "type": "object",
        "required": [
          "name",
          "end_time"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "end_time": {
            "type": "string",
            "format": "date-time"
          },
          "active": {
            "type": "boolean",
            "default": true
          },
          "challenge_time_increments": {
            "type": "array",
            "maxItems": 50,
            "default": [],
            "items": {
              "$ref": "#/components/schemas/CountdownIncrement"
            }
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "CountdownUpdate": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "end_time": {
            "type": "string",
            "format": "date-time"
          },
          "active": {
            "type": "boolean"
          },
          "challenge_time_increments": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "$ref": "#/components/schemas/CountdownIncrement"
            }
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "ReferralPromoter": {
        "type": "object",
        "required": [
          "id",
          "name",
          "referralCode"
        ],
        "properties": {
          "id": {
            "type": "string",
            "example": "507f1f77bcf86cd799439011"
          },
          "name": {
            "type": "string",
            "example": "John Smith"
          },
          "referralCode": {
            "type": "string",
            "example": "FRIEND01"
          }
        }
      },
      "ReferralValidationResponse": {
        "type": "object",
        "description": "Result of validating a referral code.",
        "required": [
          "valid"
        ],
        "properties": {
          "valid": {
            "type": "boolean",
            "example": true
          },
          "promoter": {
            "$ref": "#/components/schemas/ReferralPromoter"
          }
        }
      },
      "ReferralConfig": {
        "type": "object",
        "required": [
          "referrer_points",
          "referee_points",
          "conversion"
        ],
        "properties": {
          "referrer_points": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100000,
            "example": 50
          },
          "referee_points": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100000,
            "example": 50
          },
          "conversion": {
            "type": "string",
            "enum": [
              "first_challenge_completion"
            ],
            "description": "Moment the referral converts and both users are credited"
          }
        }
      },
      "SeasonPassCreate": {
        "type": "object",
        "required": [
          "name",
          "start_date",
          "end_date",
          "levels"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 3,
            "maxLength": 120
          },
          "description": {
            "type": "string",
            "maxLength": 500
          },
          "start_date": {
            "type": "string",
            "format": "date-time"
          },
          "end_date": {
            "type": "string",
            "format": "date-time"
          },
          "levels": {
            "type": "array",
            "minItems": 1,
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/SeasonPassLevel"
            }
          },
          "premium_price": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0
          },
          "premium_currency": {
            "type": "string",
            "enum": [
              "BRL",
              "points"
            ],
            "default": "points"
          },
          "active": {
            "type": "boolean",
            "default": true
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "SeasonPassUpdate": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "start_date": {
            "type": "string",
            "format": "date-time"
          },
          "end_date": {
            "type": "string",
            "format": "date-time"
          },
          "levels": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SeasonPassLevel"
            }
          },
          "premium_price": {
            "type": [
              "number",
              "null"
            ]
          },
          "premium_currency": {
            "type": "string",
            "enum": [
              "BRL",
              "points"
            ]
          },
          "active": {
            "type": "boolean"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "TierConfig": {
        "type": "object",
        "required": [
          "enabled",
          "qualification_window",
          "grace_period_days",
          "tiers"
        ],
        "properties": {
          "enabled": {
            "type": "boolean"
          },
          "qualification_window": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "lifetime",
                  "rolling",
                  "calendar"
                ]
              },
              "days": {
                "type": "integer",
                "description": "Window size for `rolling`."
              }
            }
          },
          "grace_period_days": {
            "type": "integer"
          },
          "tiers": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Tier"
            }
          }
        }
      },
      "TierConfigInput": {
        "type": "object",
        "required": [
          "enabled"
        ],
        "properties": {
          "enabled": {
            "type": "boolean"
          },
          "qualification_window": {
            "type": "object",
            "required": [
              "type"
            ],
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "lifetime",
                  "rolling",
                  "calendar"
                ]
              },
              "days": {
                "type": "integer",
                "minimum": 1,
                "maximum": 3650,
                "default": 365
              }
            }
          },
          "grace_period_days": {
            "type": "integer",
            "minimum": 0,
            "maximum": 365,
            "default": 30
          },
          "tiers": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "type": "object",
              "required": [
                "slug",
                "name",
                "min_xp"
              ],
              "properties": {
                "slug": {
                  "type": "string",
                  "pattern": "^[a-z0-9][a-z0-9-]*$"
                },
                "name": {
                  "type": "string",
                  "maxLength": 60
                },
                "min_xp": {
                  "type": "integer",
                  "minimum": 0
                },
                "multiplier": {
                  "type": "number",
                  "minimum": 1,
                  "maximum": 5,
                  "default": 1
                },
                "color": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "pattern": "^#[0-9a-fA-F]{6}$"
                },
                "icon": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "benefits": {
                  "type": "array",
                  "maxItems": 10,
                  "items": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      },
      "StreakFrequency": {
        "type": "object",
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "daily",
              "weekly",
              "monthly"
            ]
          },
          "interval": {
            "type": "integer",
            "minimum": 1,
            "maximum": 12,
            "default": 1,
            "description": "Periods between completions (2 = every other day)."
          },
          "tolerance_hours": {
            "type": "integer",
            "minimum": 0,
            "maximum": 720,
            "default": 24,
            "description": "Extra hours after the period ends before the streak breaks."
          }
        }
      },
      "Streak": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "icon": {
            "type": [
              "string",
              "null"
            ]
          },
          "frequency": {
            "$ref": "#/components/schemas/StreakFrequency"
          },
          "active": {
            "type": "boolean"
          },
          "challenge_ids": {
            "type": "array",
            "description": "Challenges whose completion advances this streak.",
            "items": {
              "type": "string"
            }
          },
          "stats": {
            "type": "object",
            "description": "Secret Key only.",
            "properties": {
              "participants": {
                "type": "integer"
              },
              "active_users": {
                "type": "integer"
              },
              "best_streak": {
                "type": "integer"
              }
            }
          },
          "metadata": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "StreakCreate": {
        "type": "object",
        "required": [
          "name",
          "frequency"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 3,
            "maxLength": 80
          },
          "description": {
            "type": "string",
            "maxLength": 300
          },
          "icon": {
            "type": "string",
            "maxLength": 100
          },
          "frequency": {
            "$ref": "#/components/schemas/StreakFrequency"
          },
          "active": {
            "type": "boolean",
            "default": true
          },
          "challenge_ids": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "type": "string"
            }
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "StreakUpdate": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 3,
            "maxLength": 80
          },
          "description": {
            "type": "string",
            "maxLength": 300
          },
          "icon": {
            "type": "string"
          },
          "frequency": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "daily",
                  "weekly",
                  "monthly"
                ]
              },
              "interval": {
                "type": "integer",
                "minimum": 1,
                "maximum": 12
              },
              "tolerance_hours": {
                "type": "integer",
                "minimum": 0,
                "maximum": 720
              }
            }
          },
          "active": {
            "type": "boolean"
          },
          "challenge_ids": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "type": "string"
            }
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "SurveyQuestion": {
        "type": "object",
        "description": "An individual survey question",
        "properties": {
          "question": {
            "type": "string",
            "description": "Question text displayed to the user",
            "example": "How do you rate our service?"
          },
          "type": {
            "type": "string",
            "description": "Question type that determines the response format:\n- `5-star-rating`: Star rating (1-5)\n- `rating-0-10`: Numeric scale (0-10), ideal for NPS\n- `short-text`: Short text field (single line)\n- `long-text`: Long text field (paragraph)\n- `integer`: Integer number\n- `date`: Date picker\n- `radio`: Single choice among options\n- `checkbox`: Multiple choice among options\n",
            "enum": [
              "5-star-rating",
              "rating-0-10",
              "short-text",
              "long-text",
              "integer",
              "date",
              "radio",
              "checkbox"
            ],
            "example": "5-star-rating"
          },
          "options": {
            "type": "array",
            "description": "Available options for selection.\nRequired for types `radio` and `checkbox`.\n",
            "items": {
              "type": "string"
            },
            "example": [
              "WhatsApp",
              "Email",
              "Phone",
              "Chat"
            ]
          },
          "allow_custom_option": {
            "type": "boolean",
            "description": "If `true`, adds an \"Other\" option where the user can type.\nValid only for types `radio` and `checkbox`.\n",
            "example": false
          },
          "required": {
            "type": "boolean",
            "description": "If `true`, the user must answer this question to\nsubmit the survey. If `false`, the answer is optional.\n",
            "example": true
          }
        }
      },
      "Survey": {
        "type": "object",
        "description": "**Survey** is a questionnaire that users can answer.\n\nSurveys are a powerful tool for:\n- Collecting customer **feedback**\n- Measuring **NPS** (Net Promoter Score)\n- Conducting **market research**\n- Learning more about user profiles\n\n### Integration with Challenges\n\nSurveys can be linked to challenges of type `survey`.\nWhen the user answers the survey, the challenge is completed\nautomatically and points are awarded.\n\nThis encourages participation in surveys!\n\n### Question Types\n\n| Type | Description | Response |\n|------|-------------|----------|\n| `5-star-rating` | 1-5 star rating | Number 1-5 |\n| `rating-0-10` | Score from 0 to 10 (NPS) | Number 0-10 |\n| `short-text` | Short text | String |\n| `long-text` | Long text/paragraph | String |\n| `integer` | Integer number | Number |\n| `date` | Date | ISO String |\n| `radio` | Single choice | String (option) |\n| `checkbox` | Multiple choice | Array of strings |\n\n### Survey States\n\n- **Draft**: `published_at` is null, not visible in the public API\n- **Published**: `published_at` has a date, visible and accepts responses\n- **Archived**: `archived_at` has a date, no longer accepts responses\n",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique survey identifier (MongoDB ObjectId)",
            "example": "507f1f77bcf86cd799439050"
          },
          "title": {
            "type": "string",
            "description": "Survey title displayed to the user",
            "example": "Satisfaction Survey"
          },
          "description": {
            "type": "string",
            "description": "Survey description/introduction",
            "example": "We want to hear your opinion about our services"
          },
          "questions": {
            "type": "array",
            "description": "Ordered list of survey questions",
            "items": {
              "$ref": "#/components/schemas/SurveyQuestion"
            }
          },
          "responses_count": {
            "type": "integer",
            "description": "Total number of responses received",
            "example": 42
          },
          "published_at": {
            "type": "string",
            "format": "date-time",
            "description": "Publication date/time (null if still a draft)"
          },
          "metadata": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true,
            "description": "Custom metadata to store additional information.\n\n**Usage examples:**\n- `campaign`: associated campaign\n- `target_audience`: target audience\n- `department`: responsible department\n\nCan be filtered via `?metadata[key]=value` in queries.\n"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "SurveyQuestionInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "question",
          "type"
        ],
        "properties": {
          "question": {
            "type": "string",
            "minLength": 1,
            "maxLength": 500
          },
          "type": {
            "type": "string",
            "enum": [
              "5-star-rating",
              "rating-0-10",
              "short-text",
              "long-text",
              "integer",
              "date",
              "radio",
              "checkbox"
            ]
          },
          "options": {
            "type": "array",
            "description": "Required for `radio` and `checkbox` (2 to 30 unique options); not allowed for other types.",
            "minItems": 2,
            "maxItems": 30,
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            }
          },
          "allow_custom_option": {
            "type": "boolean",
            "description": "Adds a free-text \"Other\" answer. Only for `radio` and `checkbox`."
          },
          "required": {
            "type": "boolean",
            "default": true
          }
        }
      },
      "SurveyCreate": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "title",
          "questions"
        ],
        "properties": {
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "description": {
            "type": "string",
            "maxLength": 2000
          },
          "questions": {
            "type": "array",
            "minItems": 1,
            "maxItems": 50,
            "items": {
              "$ref": "#/components/schemas/SurveyQuestionInput"
            }
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "SurveyError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "type",
              "message"
            ],
            "properties": {
              "type": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "SurveyUpdate": {
        "type": "object",
        "additionalProperties": false,
        "minProperties": 1,
        "properties": {
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "description": {
            "type": "string",
            "maxLength": 2000
          },
          "questions": {
            "type": "array",
            "description": "Replaces all questions. Locked after the first answer.",
            "minItems": 1,
            "maxItems": 50,
            "items": {
              "$ref": "#/components/schemas/SurveyQuestionInput"
            }
          },
          "metadata": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true
          }
        }
      },
      "SurveyResults": {
        "type": "object",
        "required": [
          "survey_id",
          "title",
          "from",
          "to",
          "timezone",
          "responses",
          "series",
          "questions"
        ],
        "properties": {
          "survey_id": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "from": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "to": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "timezone": {
            "type": "string",
            "description": "Workspace timezone used for daily series",
            "example": "America/Sao_Paulo"
          },
          "responses": {
            "type": "integer",
            "description": "Survey answers submitted in the window"
          },
          "series": {
            "type": "array",
            "description": "Answers per day (days without answers are omitted)",
            "items": {
              "type": "object",
              "properties": {
                "date": {
                  "type": "string",
                  "format": "date"
                },
                "responses": {
                  "type": "integer"
                }
              }
            }
          },
          "questions": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "question_index": {
                  "type": "integer"
                },
                "question": {
                  "type": "string"
                },
                "type": {
                  "type": "string"
                },
                "required": {
                  "type": "boolean"
                },
                "responses": {
                  "type": "integer"
                },
                "average": {
                  "type": [
                    "number",
                    "null"
                  ],
                  "description": "Rating and integer questions (2 decimals)"
                },
                "min": {
                  "type": [
                    "number",
                    "null"
                  ],
                  "description": "Integer questions only"
                },
                "max": {
                  "type": [
                    "number",
                    "null"
                  ],
                  "description": "Integer questions only"
                },
                "sum": {
                  "type": [
                    "number",
                    "null"
                  ],
                  "description": "Integer questions only"
                },
                "distribution": {
                  "type": "array",
                  "description": "Count per value for rating and integer questions",
                  "items": {
                    "type": "object",
                    "properties": {
                      "value": {
                        "type": "string"
                      },
                      "count": {
                        "type": "integer"
                      }
                    }
                  }
                },
                "nps": {
                  "type": [
                    "object",
                    "null"
                  ],
                  "description": "Only for `rating-0-10`",
                  "properties": {
                    "score": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "minimum": -100,
                      "maximum": 100
                    },
                    "promoters": {
                      "type": "integer"
                    },
                    "passives": {
                      "type": "integer"
                    },
                    "detractors": {
                      "type": "integer"
                    }
                  }
                },
                "options": {
                  "type": [
                    "array",
                    "null"
                  ],
                  "description": "Only for `radio` and `checkbox`",
                  "items": {
                    "type": "object",
                    "properties": {
                      "option": {
                        "type": "string"
                      },
                      "count": {
                        "type": "integer"
                      },
                      "custom": {
                        "type": "boolean",
                        "description": "`true` for free answers typed by users (\"Other\")"
                      }
                    }
                  }
                },
                "series": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "date": {
                        "type": "string",
                        "format": "date"
                      },
                      "responses": {
                        "type": "integer"
                      },
                      "average": {
                        "type": [
                          "number",
                          "null"
                        ]
                      },
                      "nps": {
                        "type": [
                          "integer",
                          "null"
                        ]
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "SurveyQuestionAnswer": {
        "type": "object",
        "description": "Answer for a specific survey question",
        "properties": {
          "question_index": {
            "type": "integer",
            "description": "Question index in the survey (0-based)"
          },
          "question": {
            "type": "string",
            "description": "Question text (denormalized for easy reading)"
          },
          "type": {
            "type": "string",
            "description": "Question type"
          },
          "answer": {
            "oneOf": [
              {
                "type": "string",
                "description": "For text, radio, date types"
              },
              {
                "type": "number",
                "description": "For rating and integer types"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "For checkbox type (multiple options)"
              }
            ],
            "description": "Answer value. The format depends on the question type:\n- `5-star-rating`, `rating-0-10`, `integer`: number\n- `short-text`, `long-text`, `date`, `radio`: string\n- `checkbox`: array of strings\n"
          }
        }
      },
      "SurveyAnswer": {
        "type": "object",
        "description": "Record of a complete response to a survey.\nContains all individual answers from a user.\n",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique response identifier"
          },
          "user_id": {
            "type": "string",
            "description": "ID of the user who responded"
          },
          "survey_id": {
            "type": "string",
            "description": "ID of the answered survey"
          },
          "challenge_id": {
            "type": "string",
            "description": "ID of the associated challenge (if the survey was linked to a challenge).\nNull if the survey was answered independently.\n"
          },
          "answers": {
            "type": "array",
            "description": "List of answers for each question",
            "items": {
              "$ref": "#/components/schemas/SurveyQuestionAnswer"
            }
          },
          "submitted_at": {
            "type": "string",
            "format": "date-time",
            "description": "Response submission date/time"
          }
        }
      },
      "Webhook": {
        "type": "object",
        "description": "**Webhook** allows you to receive real-time HTTP notifications when events\noccur on your Experi platform.\n\nWhen an event occurs (e.g., new user, challenge completed, reward redeemed),\nExperi sends a `POST` request to the configured URL with the event payload.\n\n### Security\n\nEach webhook has a `secret` (prefix `whsec_`) used to sign payloads\nvia HMAC-SHA256. Verify the signature on each received request to ensure\nit came from Experi (see \"Signature Verification\" below).\n\n### Lifecycle\n\n| Status | Description |\n|--------|-------------|\n| `active` | Receiving events normally |\n| `paused` | Manually paused — does not receive events |\n| `disabled` | Automatically disabled after 50 consecutive failures |\n\n### Retries\n\nWhen a delivery fails (timeout, HTTP 4xx/5xx error), Experi retries up to **3 times**\nwith progressive intervals: 1 minute, 10 minutes, 1 hour.\n\nAfter **50 consecutive failures**, the webhook is automatically disabled.\n\n### Signature Verification\n\nEach request includes the headers:\n\n| Header | Description |\n|--------|-------------|\n| `X-Experi-Signature` | `sha256={hmac}` — HMAC-SHA256 signature |\n| `X-Experi-Timestamp` | Unix timestamp of the signature |\n| `X-Experi-Event` | Event type (e.g., `user.created`) |\n| `X-Experi-Delivery` | Unique delivery ID (e.g., `evt_xxx`) |\n\nTo verify the signature:\n\n```javascript\nconst crypto = require('crypto');\n\nfunction verifyWebhookSignature(payload, signature, timestamp, secret) {\n  const signedPayload = `${timestamp}.${payload}`;\n  const expectedSignature = crypto\n    .createHmac('sha256', secret)\n    .update(signedPayload)\n    .digest('hex');\n  return `sha256=${expectedSignature}` === signature;\n}\n\n// In your webhook handler:\napp.post('/webhooks/experi', (req, res) => {\n  const signature = req.headers['x-experi-signature'];\n  const timestamp = req.headers['x-experi-timestamp'];\n  const payload = JSON.stringify(req.body);\n\n  if (!verifyWebhookSignature(payload, signature, timestamp, WEBHOOK_SECRET)) {\n    return res.status(401).send('Invalid signature');\n  }\n\n  // Process event...\n  console.log('Event:', req.body.type, req.body.data);\n  res.status(200).send('OK');\n});\n```\n\n### Payload\n\nAll webhook requests have the following format:\n\n```json\n{\n  \"id\": \"evt_abc123\",\n  \"type\": \"user.created\",\n  \"created_at\": \"2026-02-21T10:30:00Z\",\n  \"data\": {\n    \"id\": \"507f1f77bcf86cd799439011\",\n    \"name\": \"John Smith\",\n    \"email\": \"john@example.com\",\n    \"points\": 0\n  }\n}\n```\n",
        "required": [
          "id",
          "url",
          "secret",
          "events",
          "status",
          "failure_count",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique webhook identifier (MongoDB ObjectId)",
            "example": "507f1f77bcf86cd799439012"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "URL of the endpoint that will receive events via POST",
            "example": "https://my-server.com/webhooks/experi"
          },
          "description": {
            "type": "string",
            "description": "Optional description to identify the webhook",
            "example": "Main webhook — all events"
          },
          "secret": {
            "type": "string",
            "description": "Signing secret for HMAC-SHA256 payload verification.\nPrefix `whsec_`. Automatically generated on creation.\n",
            "example": "whsec_a1b2c3d4e5f6..."
          },
          "events": {
            "type": "array",
            "description": "List of subscribed event types. Use `[\"*\"]` to receive all.\n",
            "items": {
              "type": "string"
            },
            "example": [
              "user.created",
              "badge.earned",
              "reward.redeemed"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "paused",
              "disabled"
            ],
            "description": "Current webhook status:\n- `active`: Receiving events\n- `paused`: Manually paused\n- `disabled`: Disabled due to consecutive failures\n",
            "example": "active"
          },
          "failure_count": {
            "type": "integer",
            "description": "Consecutive failure counter. Reset after a successful delivery. The webhook is disabled upon reaching 50.",
            "minimum": 0,
            "example": 0
          },
          "last_delivery_at": {
            "type": "string",
            "format": "date-time",
            "description": "Date and time of the last delivery attempt (UTC)",
            "example": "2026-02-20T18:30:00Z"
          },
          "last_delivery_status": {
            "type": "string",
            "enum": [
              "success",
              "failure"
            ],
            "description": "Result of the last delivery",
            "example": "success"
          },
          "metadata": {
            "type": "object",
            "description": "Custom additional data in key-value format",
            "additionalProperties": true,
            "example": {
              "env": "production",
              "team": "backend"
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "Creation date and time (UTC)",
            "example": "2026-01-15T10:30:00Z"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "description": "Last update date and time (UTC)",
            "example": "2026-02-20T18:30:00Z"
          }
        }
      },
      "WebhookCreate": {
        "type": "object",
        "description": "Data to create a new webhook",
        "required": [
          "url"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "description": "URL of the endpoint that will receive events via POST",
            "example": "https://my-server.com/webhooks/experi"
          },
          "description": {
            "type": "string",
            "maxLength": 500,
            "description": "Optional description to identify the webhook",
            "example": "Main webhook"
          },
          "events": {
            "type": "array",
            "description": "Event types to subscribe to. Use `[\"*\"]` for all events.\nIf omitted, defaults to `[\"*\"]`.\n",
            "items": {
              "type": "string",
              "enum": [
                "*",
                "user.created",
                "user.updated",
                "user.deleted",
                "challenge.completed",
                "badge.earned",
                "badge.revoked",
                "reward.redeemed",
                "points.added",
                "points.deducted",
                "survey.answered",
                "action.tracked"
              ]
            },
            "default": [
              "*"
            ],
            "example": [
              "user.created",
              "badge.earned"
            ]
          },
          "metadata": {
            "type": "object",
            "description": "Custom additional data",
            "additionalProperties": true
          }
        }
      },
      "WebhookUpdate": {
        "type": "object",
        "description": "Data to update a webhook. Only the sent fields are changed.",
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "description": "New endpoint URL",
            "example": "https://new-server.com/webhooks/experi"
          },
          "description": {
            "type": "string",
            "maxLength": 500,
            "description": "New description"
          },
          "events": {
            "type": "array",
            "description": "New list of event types to subscribe to",
            "items": {
              "type": "string",
              "enum": [
                "*",
                "user.created",
                "user.updated",
                "user.deleted",
                "challenge.completed",
                "badge.earned",
                "badge.revoked",
                "reward.redeemed",
                "points.added",
                "points.deducted",
                "survey.answered",
                "action.tracked"
              ]
            },
            "example": [
              "user.created",
              "user.updated"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "paused"
            ],
            "description": "New status. Only `active` and `paused` are allowed via API.\nThe `disabled` status is automatically assigned by the system.\n"
          },
          "metadata": {
            "type": "object",
            "description": "New additional data (replaces the previous metadata)",
            "additionalProperties": true
          }
        }
      },
      "CampaignReward": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "monetary_cost": {
            "type": "number"
          },
          "single_use": {
            "type": "boolean"
          },
          "cooldown_days": {
            "type": "integer"
          },
          "catalog_reward_id": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "CampaignSurvey": {
        "type": "object",
        "required": [
          "title",
          "questions"
        ],
        "properties": {
          "title": {
            "type": "string",
            "minLength": 3,
            "maxLength": 255
          },
          "description": {
            "type": "string",
            "maxLength": 2000
          },
          "questions": {
            "type": "array",
            "minItems": 1,
            "maxItems": 50,
            "items": {
              "type": "object",
              "required": [
                "question",
                "type"
              ],
              "properties": {
                "question": {
                  "type": "string",
                  "maxLength": 500
                },
                "type": {
                  "type": "string",
                  "enum": [
                    "5-star-rating",
                    "rating-0-10",
                    "short-text",
                    "long-text",
                    "integer",
                    "date",
                    "radio",
                    "checkbox"
                  ]
                },
                "options": {
                  "type": "array",
                  "description": "Required (2–30) for `radio` and `checkbox`",
                  "items": {
                    "type": "string"
                  }
                },
                "allow_custom_option": {
                  "type": "boolean"
                },
                "required": {
                  "type": "boolean",
                  "default": true
                }
              }
            }
          }
        }
      },
      "Campaign": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string",
            "enum": [
              "campaign"
            ]
          },
          "goal": {
            "type": "string",
            "enum": [
              "return",
              "feedback",
              "referral"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "active",
              "paused",
              "archived"
            ]
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "channels": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "counter",
                "table",
                "whatsapp"
              ]
            }
          },
          "start_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "end_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "visits_required": {
            "type": "integer",
            "description": "Present when `goal` is `return`"
          },
          "visit_cooldown_hours": {
            "type": "integer",
            "description": "Present when `goal` is `return`"
          },
          "reward": {
            "description": "Present for `return` (always) and `feedback` (null when absent)",
            "oneOf": [
              {
                "$ref": "#/components/schemas/CampaignReward"
              },
              {
                "type": "null"
              }
            ]
          },
          "survey": {
            "description": "Present when `goal` is `feedback`",
            "allOf": [
              {
                "$ref": "#/components/schemas/CampaignSurvey"
              }
            ]
          },
          "completion_points": {
            "type": "integer",
            "description": "Present when `goal` is `feedback`"
          },
          "promoter_reward_points": {
            "type": "integer",
            "description": "Present when `goal` is `referral`"
          },
          "referred_reward_points": {
            "type": "integer",
            "description": "Present when `goal` is `referral`"
          },
          "conversion_event": {
            "type": "string",
            "enum": [
              "first-visit",
              "first-campaign-completion"
            ],
            "description": "Present when `goal` is `referral`"
          },
          "assets": {
            "type": "object",
            "properties": {
              "challenge_id": {
                "type": "string"
              },
              "reward_id": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "catalog_reward_id": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "survey_id": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "qr_code_id": {
                "type": "string"
              }
            }
          },
          "metrics": {
            "type": [
              "object",
              "null"
            ],
            "description": "Lifetime counts (null with a public key)",
            "properties": {
              "scans": {
                "type": "integer"
              },
              "participants": {
                "type": "integer"
              },
              "completions": {
                "type": "integer",
                "description": "Complete cycles (return), responses (feedback) or conversions (referral)"
              },
              "rewards_claimed": {
                "type": "integer"
              }
            }
          },
          "version": {
            "type": "integer"
          },
          "published_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "paused_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "archived_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CampaignRewardInput": {
        "type": "object",
        "required": [
          "title"
        ],
        "properties": {
          "title": {
            "type": "string",
            "minLength": 3,
            "maxLength": 80
          },
          "description": {
            "type": "string",
            "minLength": 3,
            "maxLength": 300
          },
          "monetary_cost": {
            "type": "number",
            "minimum": 0,
            "maximum": 1000000
          },
          "single_use": {
            "type": "boolean"
          },
          "cooldown_days": {
            "type": "integer",
            "minimum": 0,
            "maximum": 3650
          },
          "catalog_reward_id": {
            "type": "string",
            "description": "Copy an active catalog reward (stock included) instead of the fields above"
          }
        }
      },
      "CampaignCreate": {
        "type": "object",
        "required": [
          "goal",
          "title"
        ],
        "properties": {
          "goal": {
            "type": "string",
            "enum": [
              "return",
              "feedback",
              "referral"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "draft"
            ],
            "default": "active"
          },
          "title": {
            "type": "string",
            "minLength": 3,
            "maxLength": 80
          },
          "description": {
            "type": "string",
            "maxLength": 300
          },
          "channels": {
            "type": "array",
            "description": "QR distribution channels (default `[\"counter\"]`)",
            "minItems": 1,
            "maxItems": 3,
            "items": {
              "type": "string",
              "enum": [
                "counter",
                "table",
                "whatsapp"
              ]
            }
          },
          "start_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "end_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "visits_required": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "description": "`return` only (required)"
          },
          "visit_cooldown_hours": {
            "type": "integer",
            "minimum": 0,
            "maximum": 720,
            "default": 20,
            "description": "`return` only"
          },
          "reward": {
            "description": "Required for `return`; optional (or null) for `feedback`",
            "oneOf": [
              {
                "$ref": "#/components/schemas/CampaignRewardInput"
              },
              {
                "type": "null"
              }
            ]
          },
          "survey": {
            "description": "`feedback` only (required)",
            "allOf": [
              {
                "$ref": "#/components/schemas/CampaignSurvey"
              }
            ]
          },
          "completion_points": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000,
            "default": 1,
            "description": "`feedback` only"
          },
          "promoter_reward_points": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000,
            "description": "`referral` only (required)"
          },
          "referred_reward_points": {
            "type": "integer",
            "minimum": 1,
            "maximum": 1000,
            "description": "`referral` only (required)"
          },
          "conversion_event": {
            "type": "string",
            "enum": [
              "first-visit",
              "first-campaign-completion"
            ],
            "default": "first-visit",
            "description": "`referral` only"
          }
        }
      },
      "CampaignUpdate": {
        "type": "object",
        "description": "Any field of the stored goal (see CampaignCreate), all optional.",
        "properties": {
          "title": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "channels": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "counter",
                "table",
                "whatsapp"
              ]
            }
          },
          "start_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "end_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "visits_required": {
            "type": "integer"
          },
          "visit_cooldown_hours": {
            "type": "integer"
          },
          "reward": {
            "type": [
              "object",
              "null"
            ],
            "description": "Partial for `return`; full object or null (removes it) for `feedback`"
          },
          "survey": {
            "type": "object"
          },
          "completion_points": {
            "type": "integer"
          },
          "promoter_reward_points": {
            "type": "integer"
          },
          "referred_reward_points": {
            "type": "integer"
          },
          "conversion_event": {
            "type": "string",
            "enum": [
              "first-visit",
              "first-campaign-completion"
            ]
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "ReturnProgress": {
        "type": "object",
        "properties": {
          "total_visits": {
            "type": "integer"
          },
          "cycle_visits": {
            "type": "integer"
          },
          "visits_required": {
            "type": "integer"
          },
          "rewards_available": {
            "type": "integer"
          },
          "rewards_claimed": {
            "type": "integer"
          },
          "next_reward_in": {
            "type": "integer"
          },
          "last_visit_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_reward_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "next_visit_available_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Null when a visit can be recorded now"
          }
        }
      },
      "ReferralConversion": {
        "type": "object",
        "properties": {
          "converted": {
            "type": "boolean"
          },
          "campaign_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "promoter_user_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "promoter_points": {
            "type": "integer"
          },
          "referred_points": {
            "type": "integer"
          }
        }
      },
      "CampaignVisit": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "campaign_visit"
            ]
          },
          "campaign_id": {
            "type": "string"
          },
          "user_id": {
            "type": "string"
          },
          "goal": {
            "type": "string",
            "enum": [
              "return",
              "referral"
            ]
          },
          "created": {
            "type": "boolean"
          },
          "completion_id": {
            "type": "string",
            "description": "`return` only"
          },
          "points_earned": {
            "type": "integer",
            "description": "`return` only"
          },
          "reward_unlocked": {
            "type": "boolean",
            "description": "`return` only: this visit closed a cycle"
          },
          "progress": {
            "$ref": "#/components/schemas/ReturnProgress"
          },
          "referral_conversion": {
            "$ref": "#/components/schemas/ReferralConversion"
          }
        }
      },
      "CampaignError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "example": "visit_cooldown"
              },
              "message": {
                "type": "string"
              },
              "details": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        }
      },
      "CampaignProgress": {
        "type": "object",
        "description": "`return`: fields of ReturnProgress. `feedback`: `responded`,\n`responded_at`, `reward_available`, `reward_claimed_at`. `referral`:\n`referral_code`, `invites_pending`, `invites_converted`, `referred`.\n",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "campaign_progress"
            ]
          },
          "campaign_id": {
            "type": "string"
          },
          "user_id": {
            "type": "string"
          },
          "goal": {
            "type": "string",
            "enum": [
              "return",
              "feedback",
              "referral"
            ]
          },
          "total_visits": {
            "type": "integer"
          },
          "cycle_visits": {
            "type": "integer"
          },
          "visits_required": {
            "type": "integer"
          },
          "rewards_available": {
            "type": "integer"
          },
          "rewards_claimed": {
            "type": "integer"
          },
          "next_reward_in": {
            "type": "integer"
          },
          "last_visit_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_reward_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "next_visit_available_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "responded": {
            "type": "boolean"
          },
          "responded_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "reward_available": {
            "type": "boolean"
          },
          "reward_claimed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "referral_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "invites_pending": {
            "type": "integer"
          },
          "invites_converted": {
            "type": "integer"
          },
          "referred": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "campaign_id": {
                "type": "string"
              },
              "promoter_user_id": {
                "type": "string"
              },
              "status": {
                "type": "string",
                "enum": [
                  "pending",
                  "converted"
                ]
              },
              "conversion_event": {
                "type": "string",
                "enum": [
                  "first-visit",
                  "first-campaign-completion"
                ]
              },
              "attributed_at": {
                "type": "string",
                "format": "date-time"
              },
              "converted_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            }
          }
        }
      },
      "CampaignRedemption": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "campaign_redemption"
            ]
          },
          "campaign_id": {
            "type": "string"
          },
          "user_id": {
            "type": "string"
          },
          "goal": {
            "type": "string",
            "enum": [
              "return",
              "feedback"
            ]
          },
          "created": {
            "type": "boolean"
          },
          "claim_id": {
            "type": "string"
          },
          "progress": {
            "description": "Return progress after the redemption (null for feedback)",
            "oneOf": [
              {
                "$ref": "#/components/schemas/ReturnProgress"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "CampaignResults": {
        "type": "object",
        "properties": {
          "campaign_id": {
            "type": "string"
          },
          "range": {
            "type": "object",
            "properties": {
              "from": {
                "type": "string",
                "format": "date-time"
              },
              "to": {
                "type": "string",
                "format": "date-time"
              },
              "timezone": {
                "type": "string"
              },
              "generated_at": {
                "type": "string",
                "format": "date-time"
              }
            }
          },
          "totals": {
            "type": "object",
            "properties": {
              "scans": {
                "type": "integer"
              },
              "participants": {
                "type": "integer"
              },
              "actions": {
                "type": "integer"
              },
              "visits": {
                "type": "integer"
              },
              "returning_users": {
                "type": "integer"
              },
              "users_reaching_goal": {
                "type": "integer"
              },
              "completions": {
                "type": "integer"
              },
              "rewards_claimed": {
                "type": "integer"
              },
              "redeeming_users": {
                "type": "integer"
              },
              "estimated_reward_cost": {
                "type": "number"
              },
              "feedback_responses": {
                "type": "integer"
              },
              "referrals_converted": {
                "type": "integer"
              }
            }
          },
          "funnel": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "stage": {
                  "type": "string",
                  "enum": [
                    "scan",
                    "participant",
                    "completion",
                    "reward"
                  ]
                },
                "value": {
                  "type": "integer"
                },
                "conversion_from_previous": {
                  "type": [
                    "number",
                    "null"
                  ],
                  "description": "Percent of the previous stage (null between scans and users)"
                }
              }
            }
          },
          "daily": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "date": {
                  "type": "string",
                  "format": "date"
                },
                "scans": {
                  "type": "integer"
                },
                "participants": {
                  "type": "integer"
                },
                "actions": {
                  "type": "integer"
                },
                "visits": {
                  "type": "integer"
                },
                "completions": {
                  "type": "integer"
                },
                "rewards_claimed": {
                  "type": "integer"
                }
              }
            }
          },
          "by_channel": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "channel": {
                  "type": "string",
                  "enum": [
                    "counter",
                    "table",
                    "whatsapp",
                    "unknown"
                  ]
                },
                "scans": {
                  "type": "integer"
                },
                "actions": {
                  "type": "integer"
                },
                "visits": {
                  "type": "integer"
                },
                "completions": {
                  "type": "integer"
                }
              }
            }
          },
          "activation": {
            "type": "object",
            "properties": {
              "published": {
                "type": "boolean"
              },
              "first_participation": {
                "type": "boolean"
              },
              "goal_reached": {
                "type": "boolean"
              },
              "first_redemption": {
                "type": "boolean"
              },
              "reward_required": {
                "type": "boolean"
              }
            }
          },
          "review": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "target_participants": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "target_completions": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            }
          }
        }
      },
      "CampaignQrCodes": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "campaign_qrcodes"
            ]
          },
          "campaign_id": {
            "type": "string"
          },
          "qr_code_id": {
            "type": "string"
          },
          "active": {
            "type": "boolean",
            "description": "Scans of an inactive campaign show that it is unavailable"
          },
          "channels": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "channel": {
                  "type": "string",
                  "enum": [
                    "counter",
                    "table",
                    "whatsapp"
                  ]
                },
                "url": {
                  "type": "string"
                },
                "preview_url": {
                  "type": "string"
                },
                "image": {
                  "type": "object",
                  "properties": {
                    "format": {
                      "type": "string",
                      "enum": [
                        "png"
                      ]
                    },
                    "data_url": {
                      "type": "string"
                    }
                  }
                },
                "scans": {
                  "type": "integer"
                },
                "last_scan_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                }
              }
            }
          }
        }
      },
      "AnalyticsOverview": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "analytics_overview"
            ]
          },
          "range": {
            "type": "object",
            "properties": {
              "from": {
                "type": "string",
                "format": "date-time"
              },
              "to": {
                "type": "string",
                "format": "date-time"
              },
              "timezone": {
                "type": "string"
              },
              "generated_at": {
                "type": "string",
                "format": "date-time"
              }
            }
          },
          "totals": {
            "type": "object",
            "properties": {
              "active_users": {
                "type": "integer"
              },
              "redeeming_users": {
                "type": "integer"
              },
              "completions": {
                "type": "integer"
              },
              "redemptions": {
                "type": "integer"
              },
              "points_issued": {
                "type": "integer"
              },
              "points_spent": {
                "type": "integer"
              },
              "new_users": {
                "type": "integer"
              },
              "total_users": {
                "type": "integer"
              }
            }
          },
          "rates": {
            "type": "object",
            "properties": {
              "activation": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "redemption": {
                "type": [
                  "number",
                  "null"
                ]
              }
            }
          },
          "daily": {
            "type": "array",
            "description": "One entry per calendar day of the range (zeros included)",
            "items": {
              "type": "object",
              "properties": {
                "date": {
                  "type": "string",
                  "format": "date"
                },
                "active_users": {
                  "type": "integer"
                },
                "completions": {
                  "type": "integer"
                },
                "redemptions": {
                  "type": "integer"
                },
                "points_issued": {
                  "type": "integer"
                },
                "points_spent": {
                  "type": "integer"
                },
                "new_users": {
                  "type": "integer"
                }
              }
            }
          }
        }
      },
      "TrackedEvent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "action.tracked"
            ]
          },
          "request_id": {
            "type": "string"
          },
          "action_type": {
            "type": "string"
          },
          "user_id": {
            "type": "string"
          },
          "property_keys": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "outcome": {
            "type": "string",
            "enum": [
              "processed",
              "rejected",
              "failed"
            ]
          },
          "status_code": {
            "type": "integer"
          },
          "duration_ms": {
            "type": "integer"
          },
          "effects": {
            "type": "object",
            "properties": {
              "challenges_completed": {
                "type": "integer"
              },
              "badges_earned": {
                "type": "integer"
              },
              "points_earned": {
                "type": "integer"
              }
            }
          },
          "error_type": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WinBackThresholds": {
        "type": "object",
        "description": "Days without interaction that start each level (increasing)",
        "required": [
          "low",
          "medium",
          "high",
          "lost"
        ],
        "properties": {
          "low": {
            "type": "integer",
            "minimum": 1,
            "maximum": 365
          },
          "medium": {
            "type": "integer",
            "minimum": 1,
            "maximum": 365
          },
          "high": {
            "type": "integer",
            "minimum": 1,
            "maximum": 365
          },
          "lost": {
            "type": "integer",
            "minimum": 1,
            "maximum": 730
          }
        }
      },
      "WinBackConfig": {
        "type": "object",
        "properties": {
          "enabled": {
            "type": "boolean",
            "description": "Daily automatic detection"
          },
          "thresholds": {
            "$ref": "#/components/schemas/WinBackThresholds"
          },
          "last_detection_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "WinBackUser": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": [
              "string",
              "null"
            ]
          },
          "external_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "risk_level": {
            "type": "string",
            "enum": [
              "low",
              "medium",
              "high",
              "lost"
            ]
          },
          "days_since_last_interaction": {
            "type": "integer"
          },
          "last_interaction_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_dispatch_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "dispatch_count": {
            "type": "integer"
          }
        }
      },
      "WinBackDispatch": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "user_id": {
            "type": "string"
          },
          "campaign_id": {
            "type": "string"
          },
          "channel": {
            "type": "string",
            "enum": [
              "whatsapp",
              "email",
              "push"
            ]
          },
          "source": {
            "type": "string",
            "enum": [
              "api",
              "studio",
              "console"
            ]
          },
          "risk_level": {
            "type": "string",
            "enum": [
              "none",
              "low",
              "medium",
              "high",
              "lost"
            ],
            "description": "User level when the invitation was recorded"
          },
          "days_since_last_interaction": {
            "type": "integer"
          },
          "converted": {
            "type": "boolean"
          },
          "converted_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "AutomationCondition": {
        "type": "object",
        "required": [
          "operator"
        ],
        "properties": {
          "field": {
            "type": "string",
            "example": "user.points"
          },
          "operator": {
            "type": "string",
            "enum": [
              "eq",
              "neq",
              "gt",
              "gte",
              "lt",
              "lte",
              "contains",
              "is_weekend",
              "time_between"
            ]
          },
          "value": {
            "description": "Value to compare (number for gt/gte/lt/lte, \"HH:mm-HH:mm\" for time_between)"
          }
        }
      },
      "AutomationAction": {
        "type": "object",
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "add_points",
              "deduct_points",
              "award_badge",
              "log_event",
              "send_webhook"
            ]
          },
          "params": {
            "type": "object",
            "additionalProperties": true,
            "example": {
              "amount": 10,
              "reason": "Bonus"
            }
          }
        }
      },
      "Automation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "trigger": {
            "type": "object",
            "properties": {
              "event_type": {
                "type": "string"
              }
            }
          },
          "conditions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AutomationCondition"
            }
          },
          "actions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AutomationAction"
            }
          },
          "enabled": {
            "type": "boolean"
          },
          "priority": {
            "type": "integer"
          },
          "execution_count": {
            "type": "integer"
          },
          "failure_count": {
            "type": "integer",
            "description": "Consecutive failures (reset on success)"
          },
          "disabled_after_failures": {
            "type": "boolean"
          },
          "last_executed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "metadata": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "AutomationInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "trigger",
          "actions"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 3,
            "maxLength": 120
          },
          "description": {
            "type": "string",
            "maxLength": 500
          },
          "trigger": {
            "type": "object",
            "required": [
              "event_type"
            ],
            "properties": {
              "event_type": {
                "type": "string",
                "description": "Any webhook event type",
                "example": "challenge.completed"
              }
            }
          },
          "conditions": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "$ref": "#/components/schemas/AutomationCondition"
            }
          },
          "actions": {
            "type": "array",
            "minItems": 1,
            "maxItems": 5,
            "items": {
              "$ref": "#/components/schemas/AutomationAction"
            }
          },
          "enabled": {
            "type": "boolean",
            "default": true
          },
          "priority": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000,
            "default": 100
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "AutomationUpdate": {
        "type": "object",
        "additionalProperties": false,
        "minProperties": 1,
        "properties": {
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "trigger": {
            "type": "object",
            "properties": {
              "event_type": {
                "type": "string"
              }
            }
          },
          "conditions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AutomationCondition"
            }
          },
          "actions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AutomationAction"
            }
          },
          "enabled": {
            "type": "boolean"
          },
          "priority": {
            "type": "integer"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "AutomationExecution": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "automation_id": {
            "type": "string"
          },
          "event_id": {
            "type": "string"
          },
          "event_type": {
            "type": "string"
          },
          "user_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "matched",
              "skipped",
              "failed"
            ]
          },
          "skip_reason": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "conditions_not_met",
              "self_trigger",
              "max_depth",
              "no_user",
              null
            ]
          },
          "conditions_matched": {
            "type": "boolean"
          },
          "actions": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string"
                },
                "success": {
                  "type": "boolean"
                },
                "error": {
                  "type": "string"
                },
                "details": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "duration_ms": {
            "type": "integer"
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          },
          "origin": {
            "type": [
              "object",
              "null"
            ],
            "description": "Automation chain that produced the triggering event",
            "properties": {
              "rule_ids": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "depth": {
                "type": "integer"
              }
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Invalid or missing API key",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "example": "invalid_api_key"
                    },
                    "message": {
                      "type": "string",
                      "example": "Invalid API key provided"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "BadRequest": {
        "description": "Invalid request data",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "example": "validation_error"
                    },
                    "message": {
                      "type": "string",
                      "example": "Invalid request body"
                    },
                    "details": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "path": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          },
                          "message": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "Forbidden": {
        "description": "Endpoint requires a Secret Key",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "example": "public_key_not_allowed"
                    },
                    "message": {
                      "type": "string",
                      "example": "This endpoint requires a secret API key"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "Conflict": {
        "description": "Conflict (e.g.: resource already exists)",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "example": "conflict"
                    },
                    "message": {
                      "type": "string",
                      "example": "Resource already exists"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "NotFound": {
        "description": "Resource not found",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "example": "not_found"
                    },
                    "message": {
                      "type": "string",
                      "example": "Resource not found"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "QrCodeNotFound": {
        "description": "QR code not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/QrError"
            },
            "example": {
              "error": {
                "type": "not_found",
                "message": "QR code '507f1f77bcf86cd799439070' not found"
              }
            }
          }
        }
      },
      "QrCodeInUse": {
        "description": "The QR code belongs to an Experi Studio campaign or mission",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/QrError"
            },
            "example": {
              "error": {
                "type": "qrcode_in_use",
                "message": "This QR code belongs to an Experi Studio campaign. Archive the campaign instead."
              }
            }
          }
        }
      },
      "GuildForbidden": {
        "description": "Secret key required, or the plan does not include guilds",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "examples": {
              "publicKey": {
                "value": {
                  "error": {
                    "type": "public_key_not_allowed",
                    "message": "This endpoint requires a secret API key (sk_live_xxx)"
                  }
                }
              },
              "plan": {
                "value": {
                  "error": {
                    "type": "plan_upgrade_required",
                    "message": "Guilds are not included in the current plan"
                  }
                }
              }
            }
          }
        }
      },
      "UserNotFound": {
        "description": "User not found in this project",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "type": "user_not_found",
                "message": "User not found in this project"
              }
            }
          }
        }
      },
      "GuildNotFound": {
        "description": "Guild not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "type": "guild_not_found",
                "message": "Guild not found"
              }
            }
          }
        }
      },
      "MemberNotFound": {
        "description": "Guild or member not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "examples": {
              "guild": {
                "value": {
                  "error": {
                    "type": "guild_not_found",
                    "message": "Guild not found"
                  }
                }
              },
              "member": {
                "value": {
                  "error": {
                    "type": "member_not_found",
                    "message": "User is not a member of this guild"
                  }
                }
              }
            }
          }
        }
      },
      "LeadershipTransferRequired": {
        "description": "The leader must transfer the leadership first",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "type": "leadership_transfer_required",
                "message": "Leader must transfer leadership before leaving"
              }
            }
          }
        }
      },
      "GoalBadRequest": {
        "description": "Invalid body or dates",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "examples": {
              "validation": {
                "value": {
                  "error": {
                    "type": "validation_error",
                    "message": "Invalid request body",
                    "details": [
                      {
                        "path": [
                          "target_value"
                        ],
                        "message": "Number must be greater than 0"
                      }
                    ]
                  }
                }
              },
              "dates": {
                "value": {
                  "error": {
                    "type": "invalid_dates",
                    "message": "The goal deadline is already in the past"
                  }
                }
              }
            }
          }
        }
      },
      "GoalRewardNotFound": {
        "description": "The reward item does not belong to this project",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "type": "reward_not_found",
                "message": "reward.reward_id does not match a reward of this project"
              }
            }
          }
        }
      },
      "GoalNotFound": {
        "description": "Community goal not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "type": "community_goal_not_found",
                "message": "Community goal '507f1f77bcf86cd799439060' not found"
              }
            }
          }
        }
      },
      "CountdownForbidden": {
        "description": "Secret key required, or the plan does not include countdowns",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "examples": {
              "publicKey": {
                "value": {
                  "error": {
                    "type": "public_key_not_allowed",
                    "message": "This endpoint requires a secret API key (sk_live_xxx)"
                  }
                }
              },
              "plan": {
                "value": {
                  "error": {
                    "type": "plan_upgrade_required",
                    "message": "Countdowns are not included in the current plan"
                  }
                }
              }
            }
          }
        }
      },
      "ChallengeNotFound": {
        "description": "A linked challenge does not belong to this project",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "type": "challenge_not_found",
                "message": "One or more challenge_id values do not match a challenge of this project",
                "details": {
                  "challenge_ids": [
                    "507f1f77bcf86cd799439033"
                  ]
                }
              }
            }
          }
        }
      },
      "CountdownNotFound": {
        "description": "Countdown not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "type": "countdown_not_found",
                "message": "Countdown '507f1f77bcf86cd799439080' not found"
              }
            }
          }
        }
      },
      "SurveyNotFound": {
        "description": "Survey not found (or not published, or archived)",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/SurveyError"
            },
            "example": {
              "error": {
                "type": "survey_not_found",
                "message": "Survey '507f1f77bcf86cd799439050' not found"
              }
            }
          }
        }
      }
    }
  }
}