openapi: 3.0.3
info:
  title: Overloop AI API
  version: "2.0"
  x-logo:
    url: logo.svg
    altText: Overloop AI
    href: https://overloop.ai
  description: |
    The Overloop AI API lets you programmatically manage prospects, organizations, campaigns, sourcings, conversations, and more.

    Use the sidebar to navigate between the **Getting Started** guides and the endpoint references.

  contact:
    name: Overloop AI
    url: https://overloop.ai
servers:
  - url: https://api.overloop.ai/public/v2
    description: Production

security:
  - ApiKeyAuth: []

x-tagGroups:
  - name: ""
    tags:
      - CLI & Agents
  - name: Getting Started
    tags:
      - Authentication
      - Response Format
      - Pagination, Sorting & Filtering
      - Expanding Relations
      - Errors
  - name: Core Resources
    tags:
      - Prospects
      - Organizations
      - Lists
  - name: Outreach
    tags:
      - Campaigns
      - Campaign Steps
      - Campaign Enrollments
      - Sourcings
      - Sending Addresses
  - name: Communication
    tags:
      - Conversations
  - name: Settings
    tags:
      - Users
      - Custom Fields
      - Merge Tags
      - Exclusion List
      - Account

tags:
  # -- CLI & Agents --
  - name: CLI & Agents
    description: |
      Don't want to call the API directly? We offer two ready-made tools that wrap every endpoint documented below.

      <div style="display: flex; gap: 24px; margin: 24px 0;">
        <div style="flex: 1; border: 1px solid #e2e8f0; border-radius: 12px; padding: 24px;">
          <h4 style="margin: 0 0 4px 0;">Overloop CLI</h4>
          <small style="color: #718096;">overloop-cli</small>
          <p style="color: #4a5568; font-size: 14px;">Command-line interface for developers and AI agents. Manage prospects, campaigns, sourcings, and more from the terminal.</p>
          <code style="background: #1a202c; color: #e2e8f0; padding: 10px 16px; border-radius: 8px; display: block; font-size: 13px;">npm install -g overloop-cli</code>
        </div>
        <div style="flex: 1; border: 1px solid #e2e8f0; border-radius: 12px; padding: 24px;">
          <h4 style="margin: 0 0 4px 0;">Overloop MCP Server</h4>
          <small style="color: #718096;">overloop-mcp</small>
          <p style="color: #4a5568; font-size: 14px;">Model Context Protocol server for AI agents. Plug Overloop into Claude Desktop, Cursor, and any MCP-compatible client.</p>
          <code style="background: #1a202c; color: #e2e8f0; padding: 10px 16px; border-radius: 8px; display: block; font-size: 13px;">npx overloop-mcp</code>
        </div>
      </div>

      <div style="border: 1px solid #e2e8f0; border-radius: 12px; padding: 24px; margin: 0 0 24px 0;">
        <h4 style="margin: 0 0 8px 0;">For AI Agents</h4>
        <p style="color: #4a5568; font-size: 14px;">Install the Overloop skill for your AI agent (Cursor, Claude Code, OpenClaw, etc.):</p>
        <code style="background: #1a202c; color: #e2e8f0; padding: 10px 16px; border-radius: 8px; display: block; font-size: 13px; margin: 12px 0;">npx skills add sortlist/overloop-cli</code>
        <p style="color: #4a5568; font-size: 14px; margin-bottom: 0;">This installs a <a href="https://github.com/sortlist/overloop-cli/blob/main/SKILL.md">SKILL.md</a> that gives your agent full knowledge of the CLI commands, patterns, and workflows.</p>
      </div>

      Both packages are open source: [CLI source](https://github.com/sortlist/overloop-cli) · [MCP source](https://github.com/sortlist/overloop-mcp)

  # -- Getting Started --
  - name: Authentication
    description: |
      All API requests require an API key passed in the `Authorization` header:

      ```
      Authorization: your_api_key
      ```

      You can find your API key in your [Overloop account settings](https://app.overloop.ai/integrations/api). Each user in your account has their own API key. Actions performed via the API are attributed to the user whose key is used.

      **The key carries that user's permissions.** A user who may not delete prospects,
      organizations or campaigns in the app gets `403` on the matching `DELETE` here. A
      read-only user can read everything (`GET`) and is refused every write.

      **Base URL:**

      ```
      https://api.overloop.ai/public/v2/
      ```

      All endpoints described in this documentation are relative to this base URL.

  - name: Response Format
    description: |
      The API uses flat JSON responses — no JSON:API envelopes or wrappers.

      **Single resource** — the object is returned directly:

      ```json
      {
        "id": 1,
        "email": "vincenzo@overloop.com",
        "first_name": "Vincenzo",
        "organization_id": 42,
        "created_at": "2024-01-15T10:30:00Z"
      }
      ```

      **Collection** — an array under `data` with `pagination` metadata:

      ```json
      {
        "data": [
          { "id": 1, "email": "vincenzo@overloop.com", ... },
          { "id": 2, "email": "john@example.com", ... }
        ],
        "pagination": {
          "page": 1,
          "per_page": 100,
          "total": 523,
          "total_pages": 6
        }
      }
      ```

      All dates are returned in **ISO 8601** format (e.g., `2024-01-15T10:30:00Z`).

  - name: Pagination, Sorting & Filtering
    description: |
      ## Pagination

      All collection endpoints are paginated. Use the `page` and `per_page` query parameters to navigate through results.

      | Parameter  | Default | Max  | Description        |
      |------------|---------|------|--------------------|
      | `page`     | 1       | —    | Page number        |
      | `per_page` | 100     | 1000 | Results per page   |

      **Example:**
      ```
      GET /prospects?page=2&per_page=50
      ```

      The response always includes a `pagination` object:
      ```json
      {
        "data": [...],
        "pagination": {
          "page": 2,
          "per_page": 50,
          "total": 523,
          "total_pages": 11
        }
      }
      ```

      ## Sorting

      Use the `sort` query parameter with comma-separated field names. Prefix a field with `-` for descending order.

      ```
      GET /prospects?sort=-created_at,first_name
      ```

      This sorts by `created_at` descending, then by `first_name` ascending.

      Available sort fields are documented on each endpoint.

      ## Filtering

      Use `filter[field]=value` query parameters to filter collections.

      ```
      GET /prospects?filter[country]=Belgium&filter[industry]=IT
      ```

      Available filter fields are documented on each endpoint.

  - name: Expanding Relations
    description: |
      By default, related objects are returned as IDs (e.g., `organization_id: 42`). Use the `expand` query parameter to inline the full related object instead.

      ```
      GET /prospects/123?expand=organization,owner
      ```

      **Without expand:**
      ```json
      {
        "id": 123,
        "email": "vincenzo@overloop.com",
        "organization_id": 42,
        "owner_id": 1
      }
      ```

      **With `expand=organization,owner`:**
      ```json
      {
        "id": 123,
        "email": "vincenzo@overloop.com",
        "organization": {
          "id": 42,
          "name": "Overloop",
          "website": "https://overloop.ai"
        },
        "owner": {
          "id": 1,
          "name": "Vincenzo",
          "email": "vincenzo@overloop.com"
        }
      }
      ```

      Available expandable relations are documented on each endpoint.

  - name: Errors
    description: |
      The API uses standard HTTP status codes and returns structured error responses.

      **Single error** (authentication, not found, server error):
      ```json
      {
        "error": {
          "type": "not_found",
          "message": "Couldn't find Lead with 'id'=999"
        }
      }
      ```

      **Validation errors** (one or more field-level errors):
      ```json
      {
        "errors": [
          { "field": "email", "message": "has already been taken" },
          { "field": "first_name", "message": "can't be blank" }
        ]
      }
      ```

      ## Status codes

      | Status | Type               | Description                                    |
      |--------|--------------------|------------------------------------------------|
      | 200    | —                  | Success                                        |
      | 201    | —                  | Resource created                               |
      | 400    | `invalid_request`  | Malformed request body or missing parameters   |
      | 401    | `unauthorized`     | Missing or invalid API key                     |
      | 403    | `forbidden`        | Insufficient permissions or inactive account   |
      | 404    | `not_found`        | Resource not found                             |
      | 422    | `validation_error` | Invalid parameters (see field-level errors)    |
      | 500    | `server_error`     | Internal server error                          |

  - name: Custom Fields
    description: |
      Custom fields let you store additional data on prospects and organizations beyond the standard attributes. They are defined in your account settings and identified by a code starting with `c_` (e.g., `c_company_size`, `c_lead_source`).

      Use `GET /custom_fields` to retrieve the definitions configured in your account. Then use the field `identifier` as an attribute key when creating or updating prospects and organizations. Custom field values are also included in responses.

      **Example — creating a prospect with custom fields:**
      ```json
      POST /prospects
      {
        "email": "vincenzo@overloop.com",
        "first_name": "Vincenzo",
        "c_company_size": "50-200",
        "c_lead_source": "Conference"
      }
      ```

      ## Value formats by type

      | Value Type       | Format                                           | Example                      |
      |------------------|--------------------------------------------------|------------------------------|
      | `text`           | String                                           | `"Enterprise"`               |
      | `text_long`      | String (multiline)                               | `"Notes about this lead..."` |
      | `url`            | String (URL)                                     | `"https://example.com"`      |
      | `phone`          | String                                           | `"+32 470 123456"`           |
      | `numeric`        | Number (integer or float)                        | `42` or `99.5`               |
      | `boolean`        | Boolean                                          | `true` or `false`            |
      | `date`           | String (`YYYY-MM-DD`)                            | `"2024-01-15"`               |
      | `datetime`       | String (ISO 8601)                                | `"2024-01-15T10:30:00Z"`    |
      | `list_single`    | String (must match an option, case-sensitive)    | `"Hot"`                      |
      | `list_multiple`  | Array of strings                                 | `["Hot", "Enterprise"]`      |

  # -- Core Resources --
  - name: Prospects
    description: |
      Prospects represent the contacts in your Overloop account. Each prospect belongs to your company and can be assigned to a team member (owner), associated with an organization, and added to lists.

      Prospects can be identified by their numeric `id` or by their `email` address in the URL path.

  - name: Organizations
    description: |
      Organizations represent companies in your Overloop account. Prospects can be linked to an organization via the `organization_id` field.

  # -- Outreach --
  - name: Campaigns
    description: |
      Campaigns are outbound sequences that send emails and LinkedIn messages to prospects automatically. Each campaign contains a sequence of steps (email, delay, LinkedIn actions, conditions, etc.).

      ## Creating a campaign

      The API supports two patterns for building campaigns:

      **Pattern 1 — Inline steps (recommended for linear sequences):**

      Create the campaign with all its steps in a single request. Steps are automatically chained in order.

      ```json
      POST /campaigns
      {
        "name": "Outbound Q1",
        "sender_id": 42,
        "sending_days": ["monday", "tuesday", "wednesday", "thursday", "friday"],
        "start_sending_minutes": 540,
        "end_sending_minutes": 1020,
        "timezone": "Europe/Brussels",
        "steps": [
          { "type": "email", "config": { "subject": "Hi {{first_name}}", "content": "<p>...</p>" } },
          { "type": "delay", "config": { "days_delay": 3 } },
          { "type": "email", "config": { "subject": "Following up", "content": "<p>...</p>" } }
        ]
      }
      ```

      **Pattern 2 — Individual step management (for editing and branching):**

      Use the `/campaigns/:id/steps` endpoints to add, update, or remove steps one at a time. This is useful for complex campaigns with conditions and branching.

      ## Sourcing patterns

      There are two ways to connect a sourcing to a campaign:

      **Pattern A — Standalone sourcing as trigger.** Create a sourcing independently via `POST /sourcings`, then reference it with `sourcing_id` and `--auto-enroll` when creating/updating a campaign. The sourcing remains independent (`campaign.sourcing_id` is not set); the campaign simply uses it as an enrollment trigger.

      **Pattern B — Campaign-embedded sourcing (recommended for new campaigns).** Pass `search_criteria` (and optionally `sourcing_limit`) directly when creating/updating a campaign. The API creates a sourcing that is owned by the campaign (`campaign.sourcing_id` is set, `created_from: "campaign"`). Auto-enrollment is enabled automatically.

  - name: Campaign Steps
    description: |
      Steps are the building blocks of a campaign sequence. Each step has a `type` (email, delay, condition, LinkedIn action, etc.) and a `config` object with type-specific settings.

      Steps are connected via `previous_step_id` to form a chain. For linear sequences, each step points to the one before it. For branching (conditions), child steps use `position: 0` for the "yes" branch and `position: 1` for the "no" branch.

      **Important:** When creating steps individually via `POST /campaigns/{id}/steps`, you **must** set `previous_step_id` on each step (except the first root step) to chain them together. Steps without a `previous_step_id` are created as orphan root nodes and will not appear in the Overloop UI sequence editor. The recommended approach is to use inline `steps` in `POST /campaigns` which handles chaining automatically.

  - name: Campaign Enrollments
    description: Enroll prospects into a campaign, or disenroll them. Enrollment starts the prospect through the campaign's step sequence.

  - name: Sourcings
    description: |
      Sourcings automatically discover prospects from the Overloop database based on search criteria (location, industry, job title, etc.). They work in two modes:

      **Standalone** — create a sourcing independently to discover and add prospects to your account.

      **Campaign-linked** — attach a sourcing to a campaign so discovered prospects are automatically enrolled in the campaign sequence.

  # -- Communication --
  - name: Conversations
    description: |
      Conversations are email and LinkedIn threads between your team and prospects. They are created automatically when messages are sent or received. Use the API to list, view, archive, and assign conversations.

  # -- Settings --
  - name: Users
    description: View and list team members in your Overloop account. Use `GET /me` to identify the current API key owner.

  - name: Lists
    description: |
      Lists are used to group prospects. A prospect can belong to multiple lists. When creating or updating a prospect, pass list names in the `lists` array — lists are created automatically if they don't exist.

  - name: Exclusion List
    description: |
      The exclusion list prevents emails from being sent to specific addresses or domains. Items can be individual email addresses or entire domains. When a prospect's email matches an exclusion list entry, they are marked as "excluded" and won't receive outbound emails.

  - name: Sending Addresses
    description: |
      Sending addresses are the email accounts connected to your Overloop account for sending outbound emails. Use the `sender_id` (the user who owns the sending address) when creating campaigns.

  - name: Account
    description: View your Overloop account information, including plan details and remaining credits.

paths:
  # ===== Prospects =====
  /prospects:
    get:
      tags: [Prospects]
      summary: List prospects
      description: Returns a paginated list of prospects. Supports sorting, filtering, and search.
      parameters:
        - $ref: '#/components/parameters/page'
        - $ref: '#/components/parameters/per_page'
        - $ref: '#/components/parameters/sort'
        - $ref: '#/components/parameters/expand'
        - name: search
          in: query
          schema: { type: string }
          description: Search by name or email
        - name: filter[email]
          in: query
          schema: { type: string }
        - name: filter[first_name]
          in: query
          schema: { type: string }
        - name: filter[last_name]
          in: query
          schema: { type: string }
        - name: filter[country]
          in: query
          schema: { type: string }
        - name: filter[industry]
          in: query
          schema: { type: string }
        - name: filter[archived]
          in: query
          schema: { type: string }
        - name: filter[list_id]
          in: query
          schema: { type: integer }
        - name: filter[sourcing_id]
          in: query
          schema: { type: string, format: uuid }
          description: Filter prospects sourced by a specific sourcing. Returns only prospects linked to this sourcing via the sourcing pipeline.
      responses:
        '200':
          description: A paginated list of prospects
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: '#/components/schemas/Prospect' }
                  pagination: { $ref: '#/components/schemas/Pagination' }
    post:
      tags: [Prospects]
      summary: Create a prospect
      description: |
        Creates a new prospect. If `owner_id` is not set, the API key owner is assigned.

        A prospect whose email or LinkedIn profile already exists is rejected with `422`.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ProspectCreate' }
            example:
              email: vincenzo@overloop.com
              first_name: Vincenzo
              last_name: Ruggiero
              jobtitle: CEO
              country: Belgium
              lists: ["CEO", "BE"]
              c_custom_field_a: Hot lead
      responses:
        '201':
          description: Prospect created
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Prospect' }
        '422':
          description: Validation error
          content:
            application/json:
              schema: { $ref: '#/components/schemas/ValidationErrors' }

  /prospects/{id}:
    get:
      tags: [Prospects]
      summary: Retrieve a prospect
      description: Retrieve a prospect by ID or email address.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string }
          description: Prospect ID or email address
        - $ref: '#/components/parameters/expand'
      responses:
        '200':
          description: The prospect
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Prospect' }
        '404':
          $ref: '#/components/responses/NotFound'
    patch:
      tags: [Prospects]
      summary: Update a prospect
      description: Updates the specified prospect. Only provided fields are changed.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ProspectCreate' }
      responses:
        '200':
          description: Prospect updated
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Prospect' }
        '422':
          description: Validation error
          content:
            application/json:
              schema: { $ref: '#/components/schemas/ValidationErrors' }
    delete:
      tags: [Prospects]
      summary: Delete a prospect
      description: |
        Permanently deletes a prospect, along with their conversations and replies.

        Requires the API key owner to have delete permission for prospects; `403` otherwise.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
      responses:
        '200':
          description: Prospect deleted
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DeleteResponse' }

  # ===== Organizations =====
  /organizations:
    get:
      tags: [Organizations]
      summary: List organizations
      parameters:
        - $ref: '#/components/parameters/page'
        - $ref: '#/components/parameters/per_page'
        - $ref: '#/components/parameters/sort'
        - $ref: '#/components/parameters/expand'
        - name: search
          in: query
          schema: { type: string }
        - name: filter[name]
          in: query
          schema: { type: string }
        - name: filter[country]
          in: query
          schema: { type: string }
      responses:
        '200':
          description: A paginated list of organizations
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: '#/components/schemas/Organization' }
                  pagination: { $ref: '#/components/schemas/Pagination' }
    post:
      tags: [Organizations]
      summary: Create an organization
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/OrganizationCreate' }
            example:
              name: Overloop
              website: https://overloop.ai
              country: Belgium
              lists: ["IT", "Belgium"]
      responses:
        '201':
          description: Organization created
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Organization' }
        '422':
          description: Validation error
          content:
            application/json:
              schema: { $ref: '#/components/schemas/ValidationErrors' }

  /organizations/{id}:
    get:
      tags: [Organizations]
      summary: Retrieve an organization
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
        - $ref: '#/components/parameters/expand'
      responses:
        '200':
          description: The organization
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Organization' }
    patch:
      tags: [Organizations]
      summary: Update an organization
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/OrganizationCreate' }
      responses:
        '200':
          description: Organization updated
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Organization' }
    delete:
      tags: [Organizations]
      summary: Delete an organization
      description: |
        Requires the API key owner to have delete permission for this resource; `403` otherwise.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
      responses:
        '200':
          description: Organization deleted
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DeleteResponse' }

  # ===== Campaigns =====
  /campaigns:
    get:
      tags: [Campaigns]
      summary: List campaigns
      parameters:
        - $ref: '#/components/parameters/page'
        - $ref: '#/components/parameters/per_page'
        - $ref: '#/components/parameters/sort'
        - $ref: '#/components/parameters/expand'
        - name: filter[status]
          in: query
          schema: { type: string, enum: ['on', 'off'] }
        - name: search
          in: query
          schema: { type: string }
      responses:
        '200':
          description: A paginated list of campaigns
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: '#/components/schemas/Campaign' }
                  pagination: { $ref: '#/components/schemas/Pagination' }
    post:
      tags: [Campaigns]
      summary: Create a campaign
      description: |
        Creates a new campaign. The campaign is created in `off` status.

        You can provide an inline `steps` array to create a complete campaign sequence
        in one request. Steps are automatically chained in order.

        You can also source prospects automatically using two patterns:

        **Pattern A (standalone trigger):** Pass `sourcing_id` + `only_allow_manual_enrollment: false` to use an existing standalone sourcing as the enrollment trigger.

        **Pattern B (embedded sourcing):** Pass `search_criteria` (and optionally `sourcing_limit`) to create a sourcing owned by the campaign. Auto-enrollment is enabled automatically.

        Campaigns are created with the same exit triggers the apps use, so a prospect who
        replies or whose address hard-bounces leaves the sequence. They are created `off`;
        activate with `PATCH /campaigns/{id}` and `status: "on"`.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/CampaignCreate' }
            example:
              name: Outbound Q1
              sender_id: 42
              sending_days: [monday, tuesday, wednesday, thursday, friday]
              start_sending_minutes: 540
              end_sending_minutes: 1020
              timezone: Europe/Brussels
              steps:
                - type: email
                  config: { subject: "Hi {{first_name}}", content: "<p>Looking forward to connecting.</p>" }
                - type: delay
                  config: { days_delay: 3 }
                - type: email
                  config: { subject: "Following up", content: "<p>Just checking in.</p>" }
      responses:
        '201':
          description: Campaign created
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Campaign' }
        '422':
          description: Validation error

  /campaigns/{id}:
    get:
      tags: [Campaigns]
      summary: Retrieve a campaign
      description: Use `expand=steps,sourcing` to include steps and sourcing inline.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
        - $ref: '#/components/parameters/expand'
      responses:
        '200':
          description: The campaign
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Campaign' }
    patch:
      tags: [Campaigns]
      summary: Update a campaign
      description: |
        Update campaign settings. Pass `status: "on"` to activate or `status: "off"` to pause.
        Pass a `steps` array to replace all existing steps.

        **`status: "on"` runs the same guardrails as the app** and answers `422` with a code
        rather than activating a campaign that cannot send: `no_nodes`,
        `cannot_run_more_campaigns` (plan limit), `subscription_cannot_use_outbound`,
        `subscription_cannot_use_linkedin_automation`, `automation_already_started`, or a
        validation error naming the step at fault. Surface the message; the campaign is
        untouched.

        Note that a sending address and enrolled prospects are *not* guardrails: a campaign
        missing either starts successfully and then sends nothing.

        **Replacing `steps` disenrolls the prospects already in the campaign.** When anyone is
        enrolled the request is refused with `422` unless you also pass
        `confirm_disenroll: true`. Settings sent alongside a refused `steps` payload are not
        applied either.

        Settings and steps are applied in one transaction. The status transition runs after it,
        so a refused activation leaves the settings saved.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/CampaignCreate'
                - type: object
                  properties:
                    confirm_disenroll:
                      type: boolean
                      default: false
                      description: |
                        Required when replacing `steps` on a campaign that has enrolled
                        prospects: the replacement disenrolls them.
      responses:
        '200':
          description: Campaign updated
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Campaign' }
        '422':
          description: |
            Refused. A status transition that failed its guardrails, a `steps` replacement
            without `confirm_disenroll`, or an invalid payload.
    delete:
      tags: [Campaigns]
      summary: Delete a campaign
      description: |
        Requires the API key owner to have delete permission for this resource; `403` otherwise.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
      responses:
        '200':
          description: Campaign deleted
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DeleteResponse' }

  # ===== Campaign Step Types =====
  /campaigns/step_types:
    get:
      tags: [Campaign Steps]
      summary: List available step types
      description: |
        Returns all step types available when building a campaign, organized by category.
        Use this to discover what types of steps can be added and their default configuration.
      responses:
        '200':
          description: Available step types grouped by category
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        group: { type: string, description: "Group identifier." }
                        group_label: { type: string, description: "Human-readable group name." }
                        steps:
                          type: array
                          items:
                            type: object
                            properties:
                              type: { type: string, description: "The step type value to use when creating a step." }
                              label: { type: string, description: "Human-readable step name." }
                              description: { type: string, description: "What this step does." }
                              default_config: { type: object, description: "Suggested default configuration for this step type." }

  # ===== Campaign Stats =====
  /campaigns/{id}/stats:
    get:
      tags: [Campaigns]
      summary: Get campaign performance stats
      description: |
        Returns comprehensive performance metrics for a campaign, including email
        delivery stats, open/click/reply rates, LinkedIn action counts, enrollment
        breakdowns, and reply sentiment analysis.

        Metrics are computed from cached aggregation tables and may lag real-time
        activity by a few minutes. The `last_updated_at` field indicates when the
        underlying data was last refreshed.
      operationId: getCampaignStats
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
          description: Campaign ID
      responses:
        '200':
          description: Campaign stats
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/CampaignStats'
        '404':
          description: Campaign not found
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Error' }

  # ===== Campaign Steps =====
  /campaigns/{campaign_id}/steps:
    get:
      tags: [Campaign Steps]
      summary: List campaign steps
      parameters:
        - name: campaign_id
          in: path
          required: true
          schema: { type: integer }
        - $ref: '#/components/parameters/page'
        - $ref: '#/components/parameters/per_page'
        - $ref: '#/components/parameters/sort'
      responses:
        '200':
          description: A paginated list of steps
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: '#/components/schemas/Step' }
                  pagination: { $ref: '#/components/schemas/Pagination' }
    post:
      tags: [Campaign Steps]
      summary: Add a step to a campaign
      description: |
        Add a step to the campaign. **You must set `previous_step_id`** to chain it after an existing step (except for the first root step). Without proper chaining, steps will not appear in the Overloop UI.
        For condition branches, set `position: 0` (yes) or `position: 1` (no).
      parameters:
        - name: campaign_id
          in: path
          required: true
          schema: { type: integer }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/StepCreate' }
            example:
              type: email
              previous_step_id: abc-123
              config:
                subject: "Hi {{first_name}}"
                content: "<p>Hello</p>"
      responses:
        '201':
          description: Step created
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Step' }

  /campaigns/{campaign_id}/steps/{id}:
    get:
      tags: [Campaign Steps]
      summary: Retrieve a campaign step
      parameters:
        - name: campaign_id
          in: path
          required: true
          schema: { type: integer }
        - name: id
          in: path
          required: true
          schema: { type: string }
      responses:
        '200':
          description: The step
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Step' }
    patch:
      tags: [Campaign Steps]
      summary: Update a campaign step
      description: |
        `config` is merged onto the stored configuration, so sending only the keys you want to
        change leaves the rest alone — updating an email step's `subject` keeps its `content`.
      parameters:
        - name: campaign_id
          in: path
          required: true
          schema: { type: integer }
        - name: id
          in: path
          required: true
          schema: { type: string }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/StepCreate' }
      responses:
        '200':
          description: Step updated
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Step' }
    delete:
      tags: [Campaign Steps]
      summary: Remove a campaign step
      parameters:
        - name: campaign_id
          in: path
          required: true
          schema: { type: integer }
        - name: id
          in: path
          required: true
          schema: { type: string }
      responses:
        '200':
          description: Step deleted
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DeleteResponse' }

  # ===== Campaign Enrollments =====
  /campaigns/{campaign_id}/enrollments:
    get:
      tags: [Campaign Enrollments]
      summary: List campaign enrollments
      parameters:
        - name: campaign_id
          in: path
          required: true
          schema: { type: integer }
        - $ref: '#/components/parameters/page'
        - $ref: '#/components/parameters/per_page'
        - $ref: '#/components/parameters/sort'
        - $ref: '#/components/parameters/expand'
      responses:
        '200':
          description: A paginated list of enrollments
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: '#/components/schemas/CampaignEnrollment' }
                  pagination: { $ref: '#/components/schemas/Pagination' }
    post:
      tags: [Campaign Enrollments]
      summary: Enroll a prospect into a campaign
      parameters:
        - name: campaign_id
          in: path
          required: true
          schema: { type: integer }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [prospect_id]
              properties:
                prospect_id:
                  type: integer
                  description: ID of the prospect to enroll.
                step_id:
                  type: string
                  description: Start at a specific step (defaults to the first step).
                reenroll:
                  type: boolean
                  default: false
                  description: "When `true`, re-enroll the prospect even if they are already enrolled or have completed the campaign."
                start_at:
                  type: string
                  format: date-time
                  description: "Schedule the enrollment to start at a future time. If omitted, starts immediately."
            example:
              prospect_id: 123
      responses:
        '201':
          description: Enrollment created
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CampaignEnrollment' }

  /campaigns/{campaign_id}/enrollments/{id}:
    get:
      tags: [Campaign Enrollments]
      summary: Retrieve a campaign enrollment
      parameters:
        - name: campaign_id
          in: path
          required: true
          schema: { type: integer }
        - name: id
          in: path
          required: true
          schema: { type: integer }
        - $ref: '#/components/parameters/expand'
      responses:
        '200':
          description: The enrollment
          content:
            application/json:
              schema: { $ref: '#/components/schemas/CampaignEnrollment' }
    delete:
      tags: [Campaign Enrollments]
      summary: Disenroll from a campaign
      parameters:
        - name: campaign_id
          in: path
          required: true
          schema: { type: integer }
        - name: id
          in: path
          required: true
          schema: { type: integer }
      responses:
        '200':
          description: Enrollment removed
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DeleteResponse' }

  /campaigns/{campaign_id}/enrollments/bulk:
    post:
      tags: [Campaign Enrollments]
      summary: Bulk enroll prospects into a campaign
      description: |
        Enroll up to **100 prospects** in a single request. Each prospect is enrolled individually
        so per-prospect validation (duplicates, archived, blacklisted) still applies.

        The response always includes a `summary` with counts and a `results` array with the
        outcome for each prospect. Partial success is possible — some may enroll while others fail.
      parameters:
        - name: campaign_id
          in: path
          required: true
          schema: { type: integer }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [prospect_ids]
              properties:
                prospect_ids:
                  type: array
                  description: Array of prospect IDs to enroll (max 100).
                  items: { type: string, format: uuid }
                  maxItems: 100
                step_id:
                  type: string
                  format: uuid
                  description: Start at a specific step instead of the first one.
                reenroll:
                  type: boolean
                  default: false
                  description: Re-enroll prospects that have already been through the campaign.
                start_at:
                  type: string
                  format: date-time
                  description: Schedule enrollment for a future time (ISO 8601).
            example:
              prospect_ids: ["uuid-1", "uuid-2", "uuid-3"]
              reenroll: false
      responses:
        '200':
          description: Enrollment results (may include partial failures)
          content:
            application/json:
              schema:
                type: object
                properties:
                  summary:
                    type: object
                    properties:
                      total: { type: integer, example: 3 }
                      enrolled: { type: integer, example: 2 }
                      failed: { type: integer, example: 1 }
                  results:
                    type: array
                    items:
                      type: object
                      properties:
                        prospect_id: { type: string }
                        status:
                          type: string
                          enum: [enrolled, failed]
                        enrollment_id:
                          type: string
                          description: Present when status is `enrolled`.
                        error:
                          type: string
                          description: Present when status is `failed`.
        '422':
          description: All enrollments failed, or invalid request
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Error' }

  # ===== Sourcings =====
  /sourcings/search_options:
    get:
      tags: [Sourcings]
      summary: List available search criteria options
      description: |
        Returns all available values for sourcing search criteria fields such as locations, industries, company sizes, management levels, departments, and technologies.

        **Without parameters**: returns all options for all fields at once. Locations include all regions and countries. Technologies include the first 50 alphabetically.

        **With `field` parameter**: returns options for a specific field. Combine with `q` to search within that field.

        Searchable fields (support `q` parameter): `locations`, `industries`, `technologies`.

        Static fields (always return the full list): `company_sizes`, `management_levels`, `departments`.

        Note: `job_titles` and `technologies` also accept user-provided custom values in `search_criteria` — these dropdowns are suggestions, not strict constraints.
      parameters:
        - name: field
          in: query
          required: false
          schema:
            type: string
            enum: [locations, industries, technologies, company_sizes, management_levels, departments]
          description: "Return options for a specific field only."
        - name: q
          in: query
          required: false
          schema: { type: string }
          description: "Search query to filter options within the selected field. Only applicable to `locations`, `industries`, and `technologies`."
      responses:
        '200':
          description: Available options
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    oneOf:
                      - type: object
                        description: "All fields (when no `field` parameter is provided)"
                        properties:
                          company_sizes:
                            type: array
                            items: { type: string }
                            example: ["Myself Only", "1-10 employees", "11-50 employees", "51-200 employees"]
                          management_levels:
                            type: array
                            items: { type: string }
                            example: ["Owner", "Founder", "C-Level", "Director", "Manager"]
                          departments:
                            type: array
                            items: { type: string }
                            example: ["Sales", "Marketing", "Engineering and Technical"]
                          locations:
                            type: array
                            items:
                              type: object
                              properties:
                                id: { type: integer }
                                name: { type: string }
                                type: { type: string, enum: [Region, Country, State, City] }
                            example:
                              - { id: 10, "name": "Europe", "type": "Region" }
                              - { id: 22, "name": "Belgium", "type": "Country" }
                          industries:
                            type: array
                            items:
                              type: object
                              properties:
                                id: { type: integer }
                                name: { type: string }
                                alternates: { type: array, items: { type: string } }
                            example:
                              - { id: 631, name: "Information Technology", alternates: ["Computer Software", "Computer Hardware"] }
                          technologies:
                            type: array
                            items: { type: string }
                            example: ["AWS", "Docker", "HubSpot CRM"]
                      - type: array
                        description: "Single field results (when `field` parameter is provided)"
  /sourcings:
    get:
      tags: [Sourcings]
      summary: List sourcings
      parameters:
        - $ref: '#/components/parameters/page'
        - $ref: '#/components/parameters/per_page'
        - $ref: '#/components/parameters/sort'
        - name: filter[status]
          in: query
          schema: { type: string, enum: [active, paused] }
        - name: search
          in: query
          schema: { type: string }
      responses:
        '200':
          description: A paginated list of sourcings
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: '#/components/schemas/Sourcing' }
                  pagination: { $ref: '#/components/schemas/Pagination' }
    post:
      tags: [Sourcings]
      summary: Create a sourcing
      description: Create a standalone sourcing to discover prospects from the Overloop database.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/SourcingCreate' }
            example:
              name: Sales Leaders - Belgium (Small Companies)
              search_criteria:
                job_titles: ["sales manager", "account executive", "sales representative"]
                locations: [{"id": 22, "name": "Belgium", "type": "Country"}]
                size: ["1-10 employees", "11-50 employees"]
                departments: ["Sales"]
                management_level: ["Manager", "Director"]
              sourcing_limit:
                period: total
                quantity: 50
              find_emails: true
              create_on_email_search_failure: false
      responses:
        '201':
          description: Sourcing created
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Sourcing' }

  /sourcings/{id}:
    get:
      tags: [Sourcings]
      summary: Retrieve a sourcing
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
        - $ref: '#/components/parameters/expand'
      responses:
        '200':
          description: The sourcing
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Sourcing' }
    patch:
      tags: [Sourcings]
      summary: Update a sourcing
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/SourcingCreate' }
      responses:
        '200':
          description: Sourcing updated
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Sourcing' }
    delete:
      tags: [Sourcings]
      summary: Delete a sourcing
      description: |
        Permanently deletes the sourcing, stops its prospect polling, and unlinks it from the
        campaign that used it as an enrollment trigger.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        '200':
          description: Sourcing deleted
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DeleteResponse' }

  /sourcings/{id}/start:
    post:
      tags: [Sourcings]
      summary: Start a sourcing
      description: Activate a paused sourcing to resume prospect discovery.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        '200':
          description: Sourcing activated
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Sourcing' }

  /sourcings/{id}/pause:
    post:
      tags: [Sourcings]
      summary: Pause a sourcing
      description: Pause an active sourcing to temporarily stop prospect discovery.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        '200':
          description: Sourcing paused
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Sourcing' }

  /sourcings/{id}/clone:
    post:
      tags: [Sourcings]
      summary: Clone a sourcing
      description: Create a copy of the sourcing with paused status.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        '201':
          description: Sourcing cloned
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Sourcing' }

  /sourcings/estimate:
    post:
      tags: [Sourcings]
      summary: Estimate prospect match count
      description: |
        Preview how many prospects match the given `search_criteria` **without creating a sourcing or consuming credits**.

        The response includes:
        - `estimated_count` — total matching prospects in the database.
        - `estimated_count_after_rejection` — conservative estimate after ~25 % deduplication / rejection.
        - `preview` — up to 5 sample prospect profiles so you can verify the criteria make sense.

        Use this before `POST /sourcings` to validate criteria and avoid wasted iterations.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [search_criteria]
              properties:
                search_criteria:
                  $ref: '#/components/schemas/SearchCriteria'
            example:
              search_criteria:
                job_titles: ["CEO"]
                locations:
                  - { id: 22, name: "Belgium", type: "Country" }
                company_sizes: ["1-10 employees", "11-50 employees"]
      responses:
        '200':
          description: Estimate result
          content:
            application/json:
              schema:
                type: object
                properties:
                  estimated_count:
                    type: integer
                    description: Total matching prospects in the database.
                    example: 2450
                  estimated_count_after_rejection:
                    type: integer
                    description: Conservative estimate after deduplication / rejection (~75 % of total).
                    example: 1837
                  preview:
                    type: array
                    description: Up to 5 sample prospect profiles.
                    items:
                      type: object
                      properties:
                        first_name: { type: string }
                        last_name: { type: string }
                        full_name: { type: string }
                        jobtitle: { type: string }
                        headline: { type: string }
                        company_name: { type: string }
                        country: { type: string }
                        company_industry: { type: string }
                        linkedin_profile_url: { type: string }
        '422':
          description: Invalid search criteria
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Error' }

  # ===== Conversations =====
  /conversations:
    get:
      tags: [Conversations]
      summary: List conversations
      parameters:
        - $ref: '#/components/parameters/page'
        - $ref: '#/components/parameters/per_page'
        - $ref: '#/components/parameters/sort'
        - $ref: '#/components/parameters/expand'
        - name: archived
          in: query
          schema: { type: boolean }
          description: Filter by archived status
        - name: search
          in: query
          schema: { type: string }
      responses:
        '200':
          description: A paginated list of conversations
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: '#/components/schemas/Conversation' }
                  pagination: { $ref: '#/components/schemas/Pagination' }

  /conversations/{id}:
    get:
      tags: [Conversations]
      summary: Retrieve a conversation
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
        - $ref: '#/components/parameters/expand'
      responses:
        '200':
          description: The conversation
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Conversation' }
    patch:
      tags: [Conversations]
      summary: Update a conversation
      description: Update the conversation name.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string }
      responses:
        '200':
          description: Conversation updated
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Conversation' }

  /conversations/{id}/archive:
    post:
      tags: [Conversations]
      summary: Archive a conversation
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
      responses:
        '200':
          description: Conversation archived
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Conversation' }

  /conversations/{id}/unarchive:
    post:
      tags: [Conversations]
      summary: Unarchive a conversation
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
      responses:
        '200':
          description: Conversation unarchived
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Conversation' }

  /conversations/{id}/assign:
    post:
      tags: [Conversations]
      summary: Assign a conversation
      description: Assign the conversation to a team member.
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [owner_id]
              properties:
                owner_id: { type: integer, description: User ID to assign to }
      responses:
        '200':
          description: Conversation assigned
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Conversation' }

  # ===== Settings: Users =====
  /me:
    get:
      tags: [Users]
      summary: Get current user
      description: Returns the user associated with the API key.
      parameters:
        - $ref: '#/components/parameters/expand'
      responses:
        '200':
          description: The current user
          content:
            application/json:
              schema: { $ref: '#/components/schemas/User' }

  /users:
    get:
      tags: [Users]
      summary: List users
      parameters:
        - $ref: '#/components/parameters/page'
        - $ref: '#/components/parameters/per_page'
        - $ref: '#/components/parameters/sort'
        - $ref: '#/components/parameters/expand'
        - name: filter[disabled]
          in: query
          schema: { type: boolean }
        - name: search
          in: query
          schema: { type: string }
      responses:
        '200':
          description: A paginated list of users
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: '#/components/schemas/User' }
                  pagination: { $ref: '#/components/schemas/Pagination' }

  /users/{id}:
    get:
      tags: [Users]
      summary: Retrieve a user
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
        - $ref: '#/components/parameters/expand'
      responses:
        '200':
          description: The user
          content:
            application/json:
              schema: { $ref: '#/components/schemas/User' }

  # ===== Settings: Lists =====
  /lists:
    get:
      tags: [Lists]
      summary: List lists
      parameters:
        - $ref: '#/components/parameters/page'
        - $ref: '#/components/parameters/per_page'
        - $ref: '#/components/parameters/sort'
        - name: search
          in: query
          schema: { type: string }
      responses:
        '200':
          description: A paginated list of lists
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: '#/components/schemas/List' }
                  pagination: { $ref: '#/components/schemas/Pagination' }
    post:
      tags: [Lists]
      summary: Create a list
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ListCreate' }
            example:
              name: Belgium Prospects
      responses:
        '201':
          description: List created
          content:
            application/json:
              schema: { $ref: '#/components/schemas/List' }

  /lists/{id}:
    get:
      tags: [Lists]
      summary: Retrieve a list
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
      responses:
        '200':
          description: The list
          content:
            application/json:
              schema: { $ref: '#/components/schemas/List' }
    patch:
      tags: [Lists]
      summary: Update a list
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string }
      responses:
        '200':
          description: List updated
          content:
            application/json:
              schema: { $ref: '#/components/schemas/List' }
    delete:
      tags: [Lists]
      summary: Delete a list
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
      responses:
        '200':
          description: List deleted
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DeleteResponse' }

  # ===== Settings: Custom Fields =====
  /custom_fields:
    get:
      tags: [Custom Fields]
      summary: List custom fields
      parameters:
        - name: type
          in: query
          schema: { type: string, enum: [prospects, organizations] }
          description: Filter by record type
      responses:
        '200':
          description: All custom fields
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: '#/components/schemas/CustomField' }

  # ===== Settings: Exclusion List =====
  /exclusion_list:
    get:
      tags: [Exclusion List]
      summary: List exclusion list items
      parameters:
        - $ref: '#/components/parameters/page'
        - $ref: '#/components/parameters/per_page'
        - $ref: '#/components/parameters/sort'
        - name: filter[item_type]
          in: query
          schema: { type: string, enum: [email, domain] }
        - name: search
          in: query
          schema: { type: string }
      responses:
        '200':
          description: A paginated list of exclusion items
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: '#/components/schemas/ExclusionListItem' }
                  pagination: { $ref: '#/components/schemas/Pagination' }
    post:
      tags: [Exclusion List]
      summary: Add to exclusion list
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ExclusionListItemCreate' }
            example:
              value: competitor@example.com
              item_type: email
      responses:
        '201':
          description: Item added
          content:
            application/json:
              schema: { $ref: '#/components/schemas/ExclusionListItem' }

  /exclusion_list/{id}:
    delete:
      tags: [Exclusion List]
      summary: Remove from exclusion list
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: integer }
      responses:
        '200':
          description: Item removed
          content:
            application/json:
              schema: { $ref: '#/components/schemas/DeleteResponse' }

  # ===== Settings: Merge Tags =====
  /merge_tags:
    get:
      tags: [Merge Tags]
      summary: List available merge tags
      description: |
        Returns all merge tags (template variables) available for use in email subjects,
        email bodies, and LinkedIn messages within campaign steps.

        Tags use **Liquid template syntax**: `{{ variable_name }}`. For prospect and
        organization fields, always use the `| default: ''` filter to gracefully handle
        missing data: `{{ prospect_firstname | default: '' }}`.

        Tags are organized into groups:
        - **prospect** — Prospect fields (`prospect_firstname`, `prospect_email`, etc.)
        - **organization** — Organization fields (`organization_name`, `organization_website`, etc.)
        - **sender** — Campaign sender fields (`sender_name`, `sender_email`, etc.)
        - **owner** — Prospect owner fields (`owner_name`, `owner_email`, etc.)
        - **company** — Your account-level fields (`company_name`, `company_website`)
        - **campaign** — Campaign context (`automation_name`, `now_in_campaign_timezone`)
        - **thread** — Email threading (`thread_subject`)
        - **condition** — Day-of-week booleans for conditional content (`is_monday`, `is_weekday`, etc.)
        - **custom_field** — Account-specific custom fields

        **Note:** The `lead_` prefix is a legacy alias for `prospect_` — both resolve to the same value.
        Prefer the `prospect_` prefix for clarity.
      operationId: listMergeTags
      responses:
        '200':
          description: List of all available merge tags
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/MergeTag'
              example:
                data:
                  - tag: prospect_firstname
                    group: prospect
                    description: "Prospect's first name"
                    example: "{{ prospect_firstname | default: '' }}"
                  - tag: sender_name
                    group: sender
                    description: "Sender's full name (campaign sender)"
                    example: "{{ sender_name }}"
                  - tag: is_weekday
                    group: condition
                    description: "true if today is a weekday (Mon-Fri)"
                    example: "{% if is_weekday %}...{% endif %}"

  # ===== Settings: Sending Addresses =====
  /sending_addresses:
    get:
      tags: [Sending Addresses]
      summary: List sending addresses
      description: Returns all working (connected) sending addresses for your account.
      parameters:
        - $ref: '#/components/parameters/expand'
      responses:
        '200':
          description: All sending addresses
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items: { $ref: '#/components/schemas/SendingAddress' }

  # ===== Settings: Account =====
  /account:
    get:
      tags: [Account]
      summary: Get account info
      responses:
        '200':
          description: Account information
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Account' }

components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: Your Overloop API key

  parameters:
    page:
      name: page
      in: query
      schema: { type: integer, default: 1 }
      description: Page number
    per_page:
      name: per_page
      in: query
      schema: { type: integer, default: 100, maximum: 1000 }
      description: Results per page
    sort:
      name: sort
      in: query
      schema: { type: string }
      description: "Comma-separated fields. Prefix with `-` for descending (e.g., `-created_at,name`)"
    expand:
      name: expand
      in: query
      schema: { type: string }
      description: "Comma-separated relations to expand inline (e.g., `organization,owner`)"

  responses:
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              type: not_found
              message: "Couldn't find record"

  schemas:
    Pagination:
      type: object
      properties:
        page: { type: integer, example: 1 }
        per_page: { type: integer, example: 100 }
        total: { type: integer, example: 523 }
        total_pages: { type: integer, example: 6 }

    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            type: { type: string }
            message: { type: string }

    ValidationErrors:
      type: object
      properties:
        errors:
          type: array
          items:
            type: object
            properties:
              field: { type: string }
              message: { type: string }

    DeleteResponse:
      type: object
      properties:
        id: { type: integer }
        type: { type: string }
        deleted: { type: boolean, example: true }

    # ===== Resource Schemas =====

    Prospect:
      type: object
      properties:
        id: { type: integer }
        email: { type: string }
        first_name: { type: string }
        last_name: { type: string }
        description: { type: string, nullable: true }
        jobtitle: { type: string, nullable: true }
        linkedin_profile: { type: string, nullable: true }
        phone: { type: string, nullable: true }
        title: { type: string, nullable: true }
        country: { type: string, nullable: true }
        state: { type: string, nullable: true }
        zip: { type: string, nullable: true }
        city: { type: string, nullable: true }
        industry: { type: string, nullable: true }
        domain: { type: string, nullable: true }
        organisation_name: { type: string, nullable: true }
        avatar_url: { type: string, nullable: true, description: "Profile picture URL." }
        email_status: { type: string, enum: [found, searching, search_failed, user_edited, not_searched], nullable: true }
        created_from: { type: string, enum: [web, extension, api, import] }
        lists: { type: array, items: { type: string } }
        excluded: { type: boolean }
        opened: { type: boolean }
        opened_at: { type: string, format: date-time, nullable: true }
        open_count: { type: integer }
        clicked: { type: boolean }
        clicked_at: { type: string, format: date-time, nullable: true }
        click_count: { type: integer }
        replied: { type: boolean }
        replied_at: { type: string, format: date-time, nullable: true }
        email_reply_count: { type: integer }
        linkedin_reply_count: { type: integer }
        bounced: { type: boolean }
        last_emailed_at: { type: string, format: date-time, nullable: true }
        archived: { type: boolean }
        archived_reason: { type: string, nullable: true }
        url: { type: string }
        creator_id: { type: integer }
        owner_id: { type: integer, nullable: true }
        organization_id: { type: integer, nullable: true }
        created_at: { type: string, format: date-time }
        updated_at: { type: string, format: date-time }

    ProspectCreate:
      type: object
      properties:
        email: { type: string }
        first_name: { type: string }
        last_name: { type: string }
        description: { type: string }
        jobtitle: { type: string }
        linkedin_profile: { type: string }
        phone: { type: string }
        title: { type: string }
        country: { type: string }
        state: { type: string }
        zip: { type: string }
        city: { type: string }
        industry: { type: string }
        avatar_url: { type: string, description: "Profile picture URL." }
        lists: { type: array, items: { type: string }, description: "List names (created if they don't exist)" }
        owner_id: { type: integer, description: "User ID of the owner (defaults to API key owner)" }
        organization_id: { type: integer }

    Organization:
      type: object
      properties:
        id: { type: integer }
        name: { type: string }
        website: { type: string, nullable: true }
        phone: { type: string, nullable: true }
        email: { type: string, nullable: true }
        linkedin_url: { type: string, nullable: true, description: "LinkedIn company page URL." }
        country: { type: string, nullable: true }
        state: { type: string, nullable: true }
        zip: { type: string, nullable: true }
        city: { type: string, nullable: true }
        address: { type: string, nullable: true }
        description: { type: string, nullable: true }
        size: { type: integer, nullable: true, description: "Number of employees." }
        size_range: { type: string, nullable: true, description: "Employee count range, e.g. \"51-200\"." }
        founded_on: { type: string, format: date, nullable: true, description: "Founding date (ISO 8601)." }
        industries:
          type: array
          items: { type: string }
          description: "Free-text industry labels."
        specialities:
          type: array
          items: { type: string }
          description: "Free-text speciality labels."
        open_roles:
          type: array
          items: { type: string }
          description: "Free-text open role titles."
        lists: { type: array, items: { type: string } }
        owner_id: { type: integer, nullable: true }
        creator_id: { type: integer }
        updater_id: { type: integer }
        created_at: { type: string, format: date-time }
        updated_at: { type: string, format: date-time }

    OrganizationCreate:
      type: object
      properties:
        name: { type: string }
        website: { type: string }
        phone: { type: string }
        email: { type: string }
        linkedin_url: { type: string, description: "LinkedIn company page URL." }
        country: { type: string }
        state: { type: string }
        zip: { type: string }
        city: { type: string }
        address: { type: string }
        description: { type: string }
        size: { type: integer, description: "Number of employees." }
        size_range: { type: string, description: "Employee count range, e.g. \"51-200\"." }
        founded_on: { type: string, format: date, description: "Founding date (ISO 8601)." }
        industries:
          type: array
          items: { type: string }
          description: "Free-text industry labels."
        specialities:
          type: array
          items: { type: string }
          description: "Free-text speciality labels."
        open_roles:
          type: array
          items: { type: string }
          description: "Free-text open role titles."
        lists: { type: array, items: { type: string } }
        owner_id: { type: integer }

    CampaignStats:
      type: object
      description: Comprehensive performance metrics for a campaign.
      properties:
        campaign_id:
          type: string
          format: uuid
          description: Campaign ID.
        campaign_name:
          type: string
          description: Campaign name.
        campaign_status:
          type: string
          enum: [on, off]
          description: Current campaign status.
        prospects:
          type: object
          description: Prospect counts.
          properties:
            total:
              type: integer
              description: Total prospects that have ever been in this campaign.
            active:
              type: integer
              description: Prospects currently active in the campaign.
            contacted:
              type: integer
              description: Unique prospects who received at least one message.
        enrollments:
          type: object
          description: Enrollment status breakdown (unique prospect counts).
          properties:
            active: { type: integer, description: "Currently enrolled." }
            completed: { type: integer, description: "Reached the end of the campaign." }
            exited: { type: integer, description: "Left via an exit condition." }
            errored: { type: integer, description: "Stuck on a failed step." }
            waiting: { type: integer, description: "Active but waiting (not in review or error)." }
            scheduled: { type: integer, description: "Scheduled for future enrollment." }
            in_review: { type: integer, description: "Paused at a review step." }
            disenrolled: { type: integer, description: "Manually disenrolled." }
        email:
          type: object
          description: Email delivery and engagement metrics.
          properties:
            sent: { type: integer, description: "Total email messages sent (may exceed unique contacts if a prospect received multiple emails)." }
            contacted: { type: integer, description: "Unique prospects contacted by email." }
            opened: { type: integer, description: "Unique prospects who opened at least one email." }
            clicked: { type: integer, description: "Unique prospects who clicked a link." }
            replied: { type: integer, description: "Unique prospects who replied." }
            bounced: { type: integer, description: "Unique prospects whose email bounced." }
            opted_out: { type: integer, description: "Unique prospects who opted out / unsubscribed." }
            visited: { type: integer, description: "Unique prospects who visited (via tracking)." }
            open_rate: { type: number, format: float, description: "Percentage: opened / contacted × 100." }
            click_rate: { type: number, format: float, description: "Percentage: clicked / contacted × 100." }
            reply_rate: { type: number, format: float, description: "Percentage: replied / contacted × 100." }
            bounce_rate: { type: number, format: float, description: "Percentage: bounced / contacted × 100." }
        reply_sentiment:
          type: object
          description: Sentiment analysis of email replies.
          properties:
            positive: { type: integer, description: "Replies classified as positive." }
            neutral: { type: integer, description: "Replies classified as neutral." }
            negative: { type: integer, description: "Replies classified as negative." }
        linkedin:
          type: object
          description: LinkedIn action metrics (unique prospect counts).
          properties:
            actions_performed: { type: integer, description: "Prospects who had at least one LinkedIn action performed." }
            visited: { type: integer, description: "Prospects whose LinkedIn profile was visited." }
            messaged: { type: integer, description: "Prospects who received a LinkedIn message." }
            invited: { type: integer, description: "Prospects who were sent a connection invite." }
            replied: { type: integer, description: "Prospects who replied to a LinkedIn message." }
        linkedin_reply_sentiment:
          type: object
          description: Sentiment analysis of LinkedIn replies.
          properties:
            positive: { type: integer, description: "LinkedIn replies classified as positive." }
            neutral: { type: integer, description: "LinkedIn replies classified as neutral." }
            negative: { type: integer, description: "LinkedIn replies classified as negative." }
        enrollment_sources:
          type: object
          description: Enrollment counts by source.
          properties:
            overloop_database: { type: integer, description: "Enrolled via Overloop prospect database sourcing." }
            event_trigger: { type: integer, description: "Enrolled via event triggers (e.g. CRM sync)." }
            linkedin_extension: { type: integer, description: "Enrolled via the LinkedIn Chrome extension." }
            existing_prospects: { type: integer, description: "Enrolled from existing prospects in the account." }
            csv_import: { type: integer, description: "Enrolled via CSV import." }
        last_updated_at:
          type: string
          format: date-time
          nullable: true
          description: When the underlying cached metrics were last refreshed. May lag real-time by a few minutes.

    Campaign:
      type: object
      properties:
        id: { type: integer }
        name: { type: string, description: "Display name of the campaign." }
        status:
          type: string
          enum: ['on', 'off']
          description: "Whether the campaign is actively running (`on`) or paused (`off`). Newly created campaigns default to `off`."
        sending_days:
          type: array
          items: { type: string, enum: [monday, tuesday, wednesday, thursday, friday, saturday, sunday] }
          description: "Days of the week when the campaign is allowed to send messages."
        start_sending_minutes:
          type: integer
          description: |
            Start of the daily sending window, expressed as **minutes from midnight** in the campaign's timezone.
            For example: `480` = 08:00, `540` = 09:00, `600` = 10:00.
        end_sending_minutes:
          type: integer
          description: |
            End of the daily sending window, expressed as **minutes from midnight** in the campaign's timezone.
            For example: `1020` = 17:00, `1080` = 18:00, `1140` = 19:00.
        timezone:
          type: string
          description: "IANA timezone identifier (e.g. `Europe/Brussels`, `America/New_York`, `Etc/UTC`). Determines when `start_sending_minutes`/`end_sending_minutes` are evaluated."
        only_allow_manual_enrollment:
          type: boolean
          description: |
            When `true`, prospects can only be enrolled via the API or the UI (manual enrollment).
            When `false`, the campaign automatically enrolls sourced prospects. Requires either a linked `sourcing_id` (Pattern A or B).
            Defaults to `true` for API-created campaigns.
        automatically_reenroll:
          type: boolean
          description: "When `true`, prospects that finish the campaign will be automatically re-enrolled from the beginning."
        automatically_send_messages:
          type: boolean
          description: |
            Autopilot mode. When `true`, all messages (emails and LinkedIn messages) generated by this campaign
            are sent automatically without manual review. When `false` (default), messages are queued as pending
            and require manual approval before being sent.
        automatically_send_follow_ups:
          type: boolean
          description: |
            Follow-up autopilot. When `true`, follow-up messages (2nd email onwards in a thread, or subsequent
            LinkedIn messages) are sent automatically, even if the main autopilot is off. Useful when you want to
            manually review the first outreach but auto-send the follow-ups.
        pitch_settings:
          type: object
          description: |
            AI pitch configuration used to generate email and LinkedIn message content.
            When not provided on creation, defaults are copied from your account-level AI pitch settings.
          properties:
            website_url: { type: string, description: "Your company's website URL, used as the default CTA link." }
            selling_description: { type: string, description: "A description of the product/service you are selling." }
            pain_points: { type: string, description: "Pain points your product/service addresses." }
            benefits: { type: string, description: "Key features and benefits of your product/service." }
            proof_points: { type: string, description: "Social proof, case studies, or metrics." }
            campaign_intent: { type: string, description: "Specific intent or highlight for this campaign (e.g. a product launch, webinar invite)." }
        message_personalization_settings:
          type: object
          description: |
            AI writing style configuration. When not provided on creation, defaults are copied from your account-level AI writing style settings.
          properties:
            language: { type: string, description: "Language to write in (e.g. `english (United States)`, `french`)." }
            formality: { type: string, enum: [casual, friendly, professional, formal], description: "Level of formality." }
            tone_of_voice: { type: string, description: "Tone of voice (e.g. `persuasive`, `informative`, `empathetic`)." }
            length: { type: string, enum: [short, medium, long], description: "Desired message length." }
        creator_id: { type: integer, description: "ID of the user who created this campaign." }
        sender_id: { type: integer, description: "ID of the user whose sending address is used. Defaults to the campaign creator." }
        sourcing_id: { type: string, format: uuid, nullable: true, description: "ID of the campaign's embedded sourcing (Pattern B), or `null` if sourcing is standalone (Pattern A) or no sourcing is linked." }
        created_at: { type: string, format: date-time }
        updated_at: { type: string, format: date-time }
        steps:
          type: array
          items: { $ref: '#/components/schemas/Step' }
          description: "Only present when `expand=steps`."

    CampaignCreate:
      type: object
      required: [name, sending_days, start_sending_minutes, end_sending_minutes]
      properties:
        name: { type: string, description: "Display name of the campaign." }
        sender_id: { type: integer, description: "ID of the user whose sending address will be used. Defaults to the authenticated user." }
        timezone: { type: string, default: "UTC", description: "IANA timezone identifier (e.g. `Europe/Brussels`). Defaults to the API key owner's timezone, or `UTC`." }
        sending_days:
          type: array
          items: { type: string, enum: [monday, tuesday, wednesday, thursday, friday, saturday, sunday] }
          description: "Days of the week when the campaign is allowed to send messages."
        start_sending_minutes:
          type: integer
          default: 540
          description: "Start of the daily sending window in minutes from midnight (e.g. `540` = 09:00)."
          example: 540
        end_sending_minutes:
          type: integer
          description: "End of the daily sending window in minutes from midnight (e.g. `1020` = 17:00)."
          example: 1020
        only_allow_manual_enrollment:
          type: boolean
          default: true
          description: |
            When `true` (default for API), prospects must be enrolled manually via the API or UI.

            Set to `false` to enable automatic enrollment. Requires either `sourcing_id` (Pattern A) or `search_criteria` (Pattern B).
        automatically_reenroll:
          type: boolean
          default: false
          description: "When `true`, prospects that finish the campaign are automatically re-enrolled."
        automatically_send_messages:
          type: boolean
          default: false
          description: "Autopilot. When `true`, all messages are sent automatically without manual review."
        automatically_send_follow_ups:
          type: boolean
          default: false
          description: "Follow-up autopilot. When `true`, follow-up messages are sent automatically even if main autopilot is off."
        pitch_settings:
          type: object
          description: "Override AI pitch settings for this campaign. If omitted, account-level defaults are used."
          properties:
            website_url: { type: string }
            selling_description: { type: string }
            pain_points: { type: string }
            benefits: { type: string }
            proof_points: { type: string }
            campaign_intent: { type: string }
        message_personalization_settings:
          type: object
          description: "Override AI writing style for this campaign. If omitted, account-level defaults are used."
          properties:
            language: { type: string }
            formality: { type: string, enum: [casual, friendly, professional, formal] }
            tone_of_voice: { type: string }
            length: { type: string, enum: [short, medium, long] }
        status: { type: string, enum: ['on', 'off'], description: "Only applicable on update. Set to `on` to activate the campaign." }
        steps:
          type: array
          description: |
            Inline steps array for creating a simple linear campaign in a single request. Steps are automatically chained in order.
            For branching campaigns, create the campaign first and then add steps individually via `POST /campaigns/{id}/steps`.
          items: { $ref: '#/components/schemas/StepCreate' }
        search_criteria:
          $ref: '#/components/schemas/SearchCriteria'
          description: |
            **Pattern B (embedded sourcing).** Pass search criteria to create a sourcing owned by the campaign.
            Auto-enrollment is enabled automatically. The campaign's `sourcing_id` will be set to the newly created sourcing.
            Use `GET /sourcings/search_options` to discover valid values for locations, industries, etc.
        sourcing_limit:
          oneOf:
            - type: integer
            - type: object
              properties:
                period: { type: string, enum: [day, week, month] }
                quantity: { type: integer }
          description: "Max prospects to source (Pattern B). Pass an integer (e.g. `50`) or an object like `{\"period\": \"day\", \"quantity\": 20}`. Defaults to `{\"period\": \"day\", \"quantity\": 20}` if omitted."
        sourcing_id:
          type: string
          format: uuid
          description: |
            **Pattern A (standalone trigger).** Link an existing standalone sourcing as the enrollment trigger.
            Requires `only_allow_manual_enrollment: false`. The campaign does NOT own this sourcing — it only uses it as a trigger.

    Step:
      type: object
      properties:
        id: { type: string, format: uuid }
        type:
          type: string
          description: "The step type. See `StepCreate` for the full list and descriptions."
        position:
          type: integer
          description: |
            Determines which branch a step belongs to after a `condition` step.
            - `0` (default) — the "Yes" branch (condition is met), or any linear step
            - `1` — the "No" branch (condition is not met)

            Only meaningful for direct children of a `condition` step. All other steps should use `0`.
        previous_step_id:
          type: string
          format: uuid
          nullable: true
          description: "ID of the parent step. `null` for the first (root) step in the sequence."
        config: { type: object, description: "Step-type-specific configuration. See `StepCreate` for details." }
        skip_on_failure:
          type: boolean
          description: "When `true`, if this step fails it is skipped and the flow continues to the next step instead of stopping."
        created_at: { type: string, format: date-time }
        updated_at: { type: string, format: date-time }

    StepCreate:
      type: object
      required: [type]
      properties:
        type:
          type: string
          description: |
            The step type. A campaign accepts these ten and no others; anything else is
            rejected with `422`. They are the same set the Overloop apps offer, so a campaign
            built through this API can be opened and edited in either of them.

            **Messaging:**
            - `email` — Send an email. Use `generate_with_ai: true` in config for AI-generated content, or provide `subject` and `content` for a template.
            - `linkedin_send_message` — Send a LinkedIn message.
            - `linkedin_send_invitation` — Send a LinkedIn connection request.

            **Flow control:**
            - `delay` — Wait before proceeding. Config: `{ "days_delay": 3 }` or `{ "hours_delay": 12 }`.
            - `condition` — Branch based on a filter. The "Yes" branch (position 0) is taken when the condition matches; the "No" branch (position 1) otherwise. Config: `{ "records_segment": { "filters": {...} } }`.

            **LinkedIn actions:**
            - `linkedin_visit_profile` — Visit the prospect's LinkedIn profile.
            - `linkedin_check_connection` — Check if connected on LinkedIn.

            **Other actions:**
            - `add_to_tags` — Add the prospect to one or more lists. Config: `{ "tag_ids": [1, 2] }`.
            - `remove_from_tags` — Take the prospect off one or more lists. Config: `{ "tag_ids": [1, 2] }`.
            - `enroll_campaign` — Hand the prospect to another campaign. The prospect leaves this one, so the step is only valid as the last of a branch.

            The workflow-only step types (`note`, `review`, `edit`, `enroll`, `goto_step`,
            `search_email`, `assign_conversation`, `archive_conversation`, `share`, the
            notification types and the CRM/Slack types) are **not** accepted on a campaign.
            `email_and_linkedin_condition` is not accepted either: it is a template packing
            device, not a step anyone authors.
          enum: [email, delay, condition, add_to_tags, remove_from_tags, enroll_campaign, linkedin_visit_profile, linkedin_send_invitation, linkedin_send_message, linkedin_check_connection]
        position:
          type: integer
          default: 0
          description: |
            Only relevant when adding a step as a direct child of a `condition` step:
            - `0` — attach to the "Yes" branch (condition met)
            - `1` — attach to the "No" branch (condition not met)
        previous_step_id:
          type: string
          format: uuid
          nullable: true
          description: "ID of the parent step this step follows. Omit or set to `null` for the first step."
        config:
          type: object
          description: |
            Step-type-specific configuration. Key examples:

            **`email`:**
            - `{ "generate_with_ai": true }` — Let AI write the content using campaign pitch settings.
            - `{ "subject": "Hello {{first_name}}", "content": "<p>Your message here.</p>" }` — Use a fixed template. Supports merge tags like `{{first_name}}`, `{{last_name}}`, `{{company}}`.

            **`delay`:**
            - `{ "days_delay": 3 }` — Wait 3 days.
            - `{ "hours_delay": 12 }` — Wait 12 hours.

            **`condition`:**
            ```json
            {
              "records_segment": {
                "filters": {
                  "operator": "and",
                  "groups": [{
                    "operator": "and",
                    "filters": {
                      "email": { "isnotnull": null }
                    }
                  }]
                }
              }
            }
            ```
            Supported filter operators: `is`, `isnot`, `contains`, `doesnotcontain`, `isnull`, `isnotnull`, `istrue`, `isfalse`, `after`, `before`.
            Filterable fields: any prospect field (`email`, `first_name`, `last_name`, `phone`, `jobtitle`, `country`, `city`, `industry`, etc.) or custom fields (prefixed with `c_`).

            **`linkedin_send_message`:**
            - `{ "generate_with_ai": true }` — AI-generated LinkedIn message.
            - `{ "message": "Hi {{first_name}}, ..." }` — Fixed template. **Use `message`, not `content`.** If `content` is provided it will be automatically migrated to `message`.

            **`linkedin_send_invitation`:**
            - `{ "message": "I'd love to connect!" }` — Optional connection note (max 300 chars). **Use `message`, not `content`.**

            **`add_to_tags`:**
            - `{ "tag_ids": [1, 2, 3] }` — List IDs to add the prospect to.

            **`goto_step`:**
            - `{ "node_id": "<step-uuid>" }` — ID of the step to jump to.
        skip_on_failure:
          type: boolean
          default: false
          description: "When `true`, if this step fails it is skipped and execution continues to the next step."

    CampaignEnrollment:
      type: object
      properties:
        id: { type: integer }
        automation_id: { type: integer, description: "ID of the campaign." }
        prospect_id: { type: integer, description: "ID of the enrolled prospect." }
        start_at: { type: string, format: date-time, nullable: true, description: "Scheduled start time. If `null`, the enrollment started immediately." }
        disenrolled_at: { type: string, format: date-time, nullable: true, description: "When the prospect was disenrolled. `null` if still active." }
        disenrollment_reason:
          type: string
          nullable: true
          description: |
            Reason for disenrollment, if applicable. Values include:
            - `leaf` — completed all steps
            - `exit_trigger` — matched an exit condition
            - `manual` — manually removed
            - `bounced` — email bounced
        throttled: { type: boolean, description: "Whether this enrollment is currently throttled (waiting for rate limits)." }
        created_at: { type: string, format: date-time }
        updated_at: { type: string, format: date-time }

    SearchCriteria:
      type: object
      description: |
        Filters used to find prospects in Overloop's 400M+ prospect database.
        All fields are optional — combine them to narrow down your ideal prospect profile.
        Many array fields support **exclusion**: pass an object `{"name": "value", "excluded": true}` instead of a plain string to exclude that value from results.
      properties:
        job_titles:
          type: array
          description: |
            Job title keywords to match against the prospect's current title, headline, and experience.
            Supports inclusion and exclusion.
          items:
            oneOf:
              - type: string
              - type: object
                properties:
                  name: { type: string }
                  excluded: { type: boolean }
          example: ["sales manager", "account executive", {"name": "intern", "excluded": true}]
        prospect_keywords:
          type: array
          description: |
            General keywords to search across multiple profile fields: job title, headline, description, skills, experience, certifications, and education.
            Use this for broad matching when a specific field filter is too narrow.
          items:
            oneOf:
              - type: string
              - type: object
                properties:
                  name: { type: string }
                  excluded: { type: boolean }
          example: ["SaaS", "B2B"]
        locations:
          type: array
          description: |
            Geographic locations to filter prospects by. Each location **must be an object** with `id`, `name`, and `type`.

            Use `GET /sourcings/search_options?field=locations` (with optional `q` parameter) to discover valid values.

            ```json
            [
              {"id": 22, "name": "Belgium", "type": "Country"},
              {"id": 1376, "name": "Brussels-Capital Region", "type": "State"}
            ]
            ```

            Supported types: `Country`, `Region`, `State`, `City`.

            **Plain strings are not accepted** and will return a 422 validation error.
          items:
            type: object
            required: [id, name, type]
            properties:
              id: { type: integer, description: "Internal location ID from search_options." }
              name: { type: string, description: "Location name." }
              type: { type: string, enum: [Country, Region, State, City] }
              excluded: { type: boolean, default: false, description: "Set to true to exclude this location." }
          example: [{"id": 22, "name": "Belgium", "type": "Country"}, {"id": 75, "name": "France", "type": "Country"}]
        industries:
          type: array
          description: |
            Industry filters for the prospect's current company. Each industry **must be an object** with `id` and `name`.

            Use `GET /sourcings/search_options?field=industries` (with optional `q` parameter) to discover valid values. The response includes `alternates` (e.g. LinkedIn industry names) for reference, but you must use the API `name`, not alternates, when creating a sourcing.

            ```json
            [
              {"id": 575, "name": "Information Technology"},
              {"id": 541, "name": "Accounting & Financial Services"}
            ]
            ```

            **Plain strings are not accepted** and will return a 422 validation error.
          items:
            type: object
            required: [id, name]
            properties:
              id: { type: integer, description: "Internal industry ID from search_options." }
              name: { type: string, description: "Industry name from search_options." }
              selected_alternates: { type: array, items: { type: string }, description: "Specific sub-industries to include." }
              excluded_alternates: { type: array, items: { type: string }, description: "Specific sub-industries to exclude." }
          example: [{"id": 575, "name": "Information Technology"}, {"id": 552, "name": "Business Consulting"}]
        size:
          type: array
          description: |
            Company size ranges for the prospect's current employer.
            Values must match the predefined list below. Use `GET /sourcings/search_options?field=company_sizes` to retrieve valid values.
            Supports inclusion and exclusion.
          items:
            oneOf:
              - type: string
              - type: object
                properties:
                  name: { type: string }
                  excluded: { type: boolean }
          enum:
            - Myself Only
            - 1-10 employees
            - 11-50 employees
            - 51-200 employees
            - 201-500 employees
            - 501-1000 employees
            - 1001-5000 employees
            - 5001-10,000 employees
            - 10,001+ employees
          example: ["1-10 employees", "11-50 employees"]
        management_level:
          type: array
          description: |
            Seniority / management level of the prospect.
            Values must match the predefined list below. Use `GET /sourcings/search_options?field=management_levels` to retrieve valid values.
            Supports inclusion and exclusion.
          items:
            oneOf:
              - type: string
              - type: object
                properties:
                  name: { type: string }
                  excluded: { type: boolean }
          enum:
            - Owner
            - Founder
            - C-Level
            - Partner
            - Vice President
            - Head
            - Director
            - Manager
            - Senior
            - Mid
            - Junior
            - Intern
            - Other
          example: ["Manager", "Director", "Vice President"]
        departments:
          type: array
          description: |
            Functional area / department of the prospect.
            Values must match the predefined list below. Use `GET /sourcings/search_options?field=departments` to retrieve valid values.
            Supports inclusion and exclusion.
          items:
            oneOf:
              - type: string
              - type: object
                properties:
                  name: { type: string }
                  excluded: { type: boolean }
          enum:
            - Administrative
            - Consulting
            - Customer Service
            - C-Suite
            - Design
            - Education
            - Engineering and Technical
            - Finance & Accounting
            - Human Resources
            - Legal
            - Marketing
            - Medical
            - Operations
            - Product
            - Project Management
            - Real Estate
            - Research
            - Sales
            - Trades
          example: ["Sales", "Marketing"]
        skills:
          type: array
          description: |
            Skills listed on the prospect's profile.
            Supports inclusion and exclusion.
          items:
            oneOf:
              - type: string
              - type: object
                properties:
                  name: { type: string }
                  excluded: { type: boolean }
          example: ["Salesforce", "CRM", "Lead Generation"]
        technologies:
          type: array
          description: |
            Technologies used by the prospect's current company.
            Triggers a two-stage search: first finds companies using these technologies, then finds employees at those companies.
            Supports inclusion and exclusion.
          items:
            oneOf:
              - type: string
              - type: object
                properties:
                  name: { type: string }
                  excluded: { type: boolean }
          example: ["HubSpot", "Salesforce"]
        open_roles:
          type: array
          description: |
            Filter by companies that are currently recruiting for specific roles.
            Pass an empty array `[]` to match any company that has open job postings.
            Supports inclusion and exclusion.
          items:
            oneOf:
              - type: string
              - type: object
                properties:
                  name: { type: string }
                  excluded: { type: boolean }
          example: ["Software Engineer", "Data Scientist"]
        last_funding_round:
          type: object
          description: |
            Filter by the prospect's company last funding round.
          properties:
            types:
              type: array
              items: { type: string }
              description: "Funding round types (e.g. `Seed`, `Series A`, `Series B`, `IPO`)."
            date_start:
              type: string
              format: date
              description: "Only include companies whose last round was after this date (ISO 8601)."
            date_end:
              type: string
              format: date
              description: "Only include companies whose last round was before this date (ISO 8601)."
          example:
            types: ["Series A", "Series B"]
            date_start: "2024-01-01"
        company_filtering:
          type: boolean
          description: |
            When `true`, restricts the search to a specific list of companies provided in `company_filtering_list`.
            Other company-level filters (technologies, industries, size, open roles, last funding round) are ignored when this is enabled.
          default: false
        company_filtering_list:
          type: string
          description: |
            A newline-separated list of company names, domains, or LinkedIn URLs to restrict the search to.
            Only used when `company_filtering` is `true`. Maximum 10,000 characters.
          example: "overloop.com\nhubspot.com\nsalesforce.com"

    Sourcing:
      type: object
      properties:
        id: { type: string, format: uuid }
        name: { type: string, description: "Display name of the sourcing." }
        status: { type: string, enum: [active, paused], description: "`active` when sourcing is running, `paused` when stopped. Sourcings are created in `paused` status by default." }
        search_criteria:
          $ref: '#/components/schemas/SearchCriteria'
        sourcing_limit:
          type: object
          description: "Controls how many prospects to source and over what time period."
          properties:
            period:
              type: string
              enum: [total, day, week]
              description: |
                Time period for the limit:
                - `total` — source up to `quantity` prospects in total, then stop.
                - `day` — source up to `quantity` prospects per day.
                - `week` — source up to `quantity` prospects per week.
            quantity: { type: integer, description: "Maximum number of prospects to source per period." }
        find_emails: { type: boolean, description: "When `true`, Overloop automatically searches for the email address of each sourced prospect." }
        create_on_email_search_failure: { type: boolean, description: "When `true`, creates the prospect even if no email address is found. When `false` (default), prospects without a found email are skipped." }
        is_running: { type: boolean, description: "Whether the sourcing is currently actively polling for new prospects." }
        created_from: { type: string, enum: [manual, campaign], description: "`manual` for standalone sourcings, `campaign` for sourcings linked to a campaign." }
        creator_id: { type: integer, description: "ID of the user who created this sourcing." }
        created_at: { type: string, format: date-time }
        updated_at: { type: string, format: date-time }

    SourcingCreate:
      type: object
      properties:
        name: { type: string, description: "Display name for the sourcing." }
        search_criteria:
          $ref: '#/components/schemas/SearchCriteria'
        sourcing_limit:
          type: object
          description: "Controls how many prospects to source."
          properties:
            period: { type: string, enum: [total, day, week], default: total, description: "Time window: `total`, `day`, or `week`." }
            quantity: { type: integer, default: 20, description: "Maximum prospects to source per period." }
        find_emails: { type: boolean, default: true, description: "Search for email addresses of sourced prospects." }
        create_on_email_search_failure: { type: boolean, default: false, description: "Create prospect even if email search fails." }
      required: [name, search_criteria]

    Conversation:
      type: object
      properties:
        id: { type: integer }
        name: { type: string }
        original_name: { type: string }
        created_from: { type: string, enum: [in.bcc, in.mail, out.mail, linkedin, automation_message] }
        shared: { type: boolean }
        archived_at: { type: string, format: date-time, nullable: true }
        last_activity_at: { type: string, format: date-time, nullable: true }
        owner_id: { type: integer }
        prospect_ids: { type: array, items: { type: integer } }
        created_at: { type: string, format: date-time }
        updated_at: { type: string, format: date-time }

    User:
      type: object
      properties:
        id: { type: integer }
        name: { type: string }
        email: { type: string }
        role: { type: string, enum: [admin, user, read_only] }
        phone_number: { type: string, nullable: true }
        disabled: { type: boolean }
        timezone: { type: string }
        company_id: { type: integer }
        created_at: { type: string, format: date-time }
        updated_at: { type: string, format: date-time }

    List:
      type: object
      properties:
        id: { type: integer }
        name: { type: string }
        created_at: { type: string, format: date-time }
        updated_at: { type: string, format: date-time }

    ListCreate:
      type: object
      required: [name]
      properties:
        name: { type: string }

    CustomField:
      type: object
      properties:
        id: { type: string, format: uuid }
        identifier: { type: string, description: "Use this as the attribute key (e.g., c_custom_field_a)" }
        name: { type: string }
        type: { type: string, enum: [prospects, organizations] }
        value_type: { type: string, enum: [numeric, text, text_long, phone, url, boolean, list_single, list_multiple, datetime, date] }
        options: { type: array, items: { type: string }, description: "Available options for list_single and list_multiple types" }

    ExclusionListItem:
      type: object
      properties:
        id: { type: integer }
        value: { type: string }
        item_type: { type: string, enum: [email, domain] }
        created_at: { type: string, format: date-time }

    ExclusionListItemCreate:
      type: object
      required: [value, item_type]
      properties:
        value: { type: string, description: "Email address or domain to exclude" }
        item_type: { type: string, enum: [email, domain] }

    MergeTag:
      type: object
      properties:
        tag:
          type: string
          description: The variable name to use inside `{{ }}` delimiters.
        group:
          type: string
          enum: [prospect, organization, sender, owner, company, campaign, thread, condition, custom_field]
          description: Category of the merge tag.
        description:
          type: string
          description: Human-readable description of what this tag resolves to.
        example:
          type: string
          description: Ready-to-use example with proper Liquid syntax and default filter.

    SendingAddress:
      type: object
      properties:
        id: { type: string, format: uuid }
        email: { type: string }
        from_name: { type: string }
        provider: { type: string }
        working: { type: boolean }
        user_id: { type: integer }
        created_at: { type: string, format: date-time }
        updated_at: { type: string, format: date-time }

    Account:
      type: object
      properties:
        id: { type: integer }
        name: { type: string }
        website: { type: string, nullable: true }
        phone_number: { type: string, nullable: true }
        billing_name: { type: string, nullable: true }
        address: { type: string, nullable: true }
        country: { type: string, nullable: true }
        vat: { type: string, nullable: true }
        plan_name: { type: string }
        plan_code: { type: string }
        remaining_credits: { type: integer }
        created_at: { type: string, format: date-time }
        updated_at: { type: string, format: date-time }
