openapi: 3.0.3
info:
  title: Easerix Forms API
  description: |
    Form endpoints (backend/services/products/forms): projects, forms,
    submissions with a spam pipeline (honeypot, rate limit, Turnstile,
    heuristics, async AI adjudication), delivery destinations, and the public
    unauthenticated ingest endpoint that is the product itself. Responses are
    camelCase. All /v1 routes require a bearer JWT with org claims and the
    "forms" tool enabled (authkit); the root /{id} ingest routes are public.
    Form ids are 6-char nanoids, not UUIDs.
    Authored from the shipping Gin handlers — this spec records reality.
  version: 1.0.0
  contact:
    name: Perizer Labs
    url: https://easerix.com
servers:
  - url: https://f.easerix.com
    description: Production
tags:
  - name: system
    description: Health, liveness, and CORS preflight
  - name: projects
    description: Form projects (folders)
  - name: forms
    description: Form endpoints
  - name: submissions
    description: Submission inbox and spam triage
  - name: destinations
    description: Delivery destinations (email delivered in v1; others modeled)
  - name: turnstile
    description: Domains a workspace has proved it controls, for the shared Turnstile widget
  - name: integrations
    description: >-
      A form's deliveries to outside apps (Slack first) and replaying a failed one. Connecting an app and
      listing a workspace's connections are the integrations service's (contracts/openapi/integrations.v1.yaml).
  - name: summary
    description: Account-wide aggregates
  - name: ingest
    description: Public submission endpoints (no auth)

security:
  - bearer: []

paths:
  /health:
    get:
      operationId: health
      tags: [system]
      summary: Liveness probe
      description: Unauthenticated liveness check used by the platform and monitors.
      security: []
      responses:
        "200":
          description: Service is up
          content:
            application/json:
              schema:
                type: object

  /v1/projects:
    get:
      operationId: listProjects
      tags: [projects]
      summary: List projects
      description: >-
        A page of the projects the caller can read: their own (active-org-scoped;
        legacy rows without org_id stay visible) plus any shared with the
        organization by a teammate. formCount, activeFormCount and status count
        only the forms that caller can read. Searched, filtered, sorted and
        paged on the server with limit and offset; total counts every project
        the filters match, on every page, and an offset past the end is an empty
        page with that total, not an error. Without limit a page is 500
        projects, what this endpoint always returned. Ties in any sort keep
        their places from one page to the next (newest first, then id).
      parameters:
        - name: scope
          in: query
          description: >-
            all (default) — everything readable · mine — only the caller's own
            · shared — only teammates' org-shared projects (excludes own).
          schema:
            type: string
            enum: [all, mine, shared]
        - name: q
          in: query
          description: >-
            Text to find in the project's name, case-insensitive, anywhere in
            it. % and _ are literal.
          schema: { type: string, maxLength: 200 }
        - name: status
          in: query
          description: >-
            Only projects with this status: active (some form is on), paused
            (it has forms and every one is off) or empty (no forms). all, or
            absent, is every project.
          schema: { type: string, enum: [all, active, paused, empty], default: all }
        - name: sort
          in: query
          description: >-
            newest (default) by creation time · name, case-insensitive A to Z ·
            forms, most forms first.
          schema: { type: string, enum: [newest, name, forms], default: newest }
        - name: limit
          in: query
          schema: { type: integer, minimum: 1, maximum: 500, default: 500 }
          description: Page size, a whole number from 1. Larger than 500 is clamped to 500. Given but not usable (0, negative, not a number) is a 400. Left out means 500.
        - name: offset
          in: query
          schema: { type: integer, minimum: 0, default: 0 }
          description: >-
            How many projects to skip: (page - 1) * limit. A whole number, 0 or more; given but not usable is a 400. Left out means 0.
      responses:
        "200":
          description: A page of projects
          content:
            application/json:
              schema:
                type: object
                required: [projects, limit, offset, total]
                properties:
                  projects:
                    type: array
                    items: { $ref: "#/components/schemas/Project" }
                  limit: { type: integer, description: The page size in effect }
                  offset: { type: integer, description: How many projects were skipped }
                  total:
                    type: integer
                    format: int64
                    description: Every project the filters match, on every page
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/ToolDisabled" }
    post:
      operationId: createProject
      tags: [projects]
      summary: Create a project
      description: Name defaults to "Untitled project", color to "#2563eb".
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string }
                color: { type: string }
      responses:
        "201":
          description: Project created
          content:
            application/json:
              schema:
                type: object
                required: [project]
                properties:
                  project: { $ref: "#/components/schemas/Project" }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/ToolDisabled" }
        "500": { $ref: "#/components/responses/ServerError" }

  /v1/projects/{pid}:
    parameters:
      - { name: pid, in: path, required: true, schema: { type: string } }
    get:
      operationId: getProject
      tags: [projects]
      summary: Project detail
      description: >-
        One project with its form count. Readable: the caller's own or one a
        teammate shared with the organization.
      responses:
        "200":
          description: Project
          content:
            application/json:
              schema:
                type: object
                required: [project]
                properties:
                  project: { $ref: "#/components/schemas/Project" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/ToolDisabled" }
        "404": { $ref: "#/components/responses/NotFound" }
    patch:
      operationId: updateProject
      tags: [projects]
      summary: Rename, recolor, or share a project
      description: >-
        Partial update of name/color/visibility. Owner-only — a project shared
        with the caller by a teammate is readable but returns 403 here.
        visibility must be private or org.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string }
                color: { type: string }
                visibility: { type: string, enum: [private, org] }
      responses:
        "200":
          description: Updated project
          content:
            application/json:
              schema:
                type: object
                required: [project]
                properties:
                  project: { $ref: "#/components/schemas/Project" }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }
    delete:
      operationId: deleteProject
      tags: [projects]
      summary: Delete a project
      description: >-
        Owner-only; refused while the project still contains forms. A project
        shared with the caller returns 403.
      responses:
        "200":
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  message: { type: string }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }
        "409":
          description: Project still contains forms ("move or delete this project's forms first")
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /v1/forms:
    get:
      operationId: listForms
      tags: [forms]
      summary: List forms
      description: >-
        A page of the forms the caller can read: their own (active-org-scoped;
        legacy rows without org_id stay visible) plus any shared with the
        organization by a teammate. Searched, filtered, sorted and paged on the
        server with limit and offset; total counts every form the filters match,
        on every page, and an offset past the end is an empty page with that
        total, not an error. Without limit a page is 500 forms, what this
        endpoint always returned. Ties in any sort keep their places from one
        page to the next (newest first, then id).
      parameters:
        - name: q
          in: query
          description: >-
            Text to find in the form's name, case-insensitive, anywhere in it.
            % and _ are literal.
          schema: { type: string, maxLength: 200 }
        - { name: projectId, in: query, schema: { type: string } }
        - name: scope
          in: query
          description: >-
            all (default) — everything readable · mine — only the caller's own
            · shared — only teammates' org-shared forms (excludes own).
          schema:
            type: string
            enum: [all, mine, shared]
        - name: status
          in: query
          description: >-
            Only forms that are switched on (active) or off (paused). all, or
            absent, is every form.
          schema: { type: string, enum: [all, active, paused], default: all }
        - name: visibility
          in: query
          description: >-
            Only forms that are shared with the workspace (org) or that only
            their owner can see (private; a form from before sharing existed
            counts as private). Absent is every form. With limit=1 it tells
            whether anything is shared, from the total.
          schema: { type: string, enum: [private, org] }
        - name: sort
          in: query
          description: >-
            newest (default) by creation time · name, case-insensitive A to Z ·
            submissions, most submissions first (spam included, as the count is).
          schema: { type: string, enum: [newest, name, submissions], default: newest }
        - $ref: "#/components/parameters/PageLimit"
        - name: offset
          in: query
          schema: { type: integer, minimum: 0, default: 0 }
          description: >-
            How many forms to skip: (page - 1) * limit. A whole number, 0 or more; given but not usable is a 400. Left out means 0.
      responses:
        "200":
          description: A page of forms
          content:
            application/json:
              schema:
                type: object
                required: [forms, limit, offset, total]
                properties:
                  forms:
                    type: array
                    items: { $ref: "#/components/schemas/Form" }
                  limit: { type: integer, description: The page size in effect }
                  offset: { type: integer, description: How many forms were skipped }
                  total:
                    type: integer
                    format: int64
                    description: Every form the filters match, on every page
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/ToolDisabled" }
    post:
      operationId: createForm
      tags: [forms]
      summary: Create a form endpoint
      description: >-
        Name defaults to "Untitled form". projectId must belong to the caller
        when given; otherwise the oldest project is used and a "Default"
        project is auto-created if none exist. Created with successBehavior
        json, honeypot on, spamProvider none, contentFilter medium,
        aiFilter off, active true, visibility private. targetEmails is
        validated: see the field for its rules. A rejected value is a 400
        that names the field, and no form is created. A non-empty targetEmails
        creates the form's email destination in the same transaction, so the
        form and the destination exist together or not at all. An empty or
        absent list creates no destination.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string }
                targetEmails: { $ref: "#/components/schemas/TargetEmails" }
                projectId: { type: string }
      responses:
        "201":
          description: Form created
          content:
            application/json:
              schema:
                type: object
                required: [form]
                properties:
                  form: { $ref: "#/components/schemas/Form" }
        "400": { $ref: "#/components/responses/ValidationError" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/ToolDisabled" }
        "500": { $ref: "#/components/responses/ServerError" }

  /v1/forms/{id}/locate:
    parameters:
      - { name: id, in: path, required: true, schema: { type: string } }
    get:
      operationId: locateForm
      tags: [forms]
      summary: Which workspace a form is in, for a link that names no workspace
      description: |
        For an old link (`/forms/forms/<id>`, an email from before workspace URLs), so
        the app can send the tab to the same route under `/w/<slug>`. It works
        across the caller's workspaces: the token may be for any of them.

        It answers only when the caller could open the form in its own
        workspace: they are a member with a product seat, Forms is on there, and the form is theirs or shared with the workspace. Rows from before workspaces (no workspace) are not located.

        Every other case gets the same 404, byte for byte: no such form,
        someone else's private one, another workspace's, the product turned
        off there, a malformed id, or a request made with an API key or an
        OAuth grant (those are bound to one workspace by consent). Both
        answers are `Cache-Control: no-store`. Rate-limited per user and per
        client IP.
      responses:
        "200":
          description: The form's workspace
          content:
            application/json:
              schema:
                type: object
                required: [workspace_id, slug]
                properties:
                  workspace_id:
                    type: string
                    format: uuid
                  slug:
                    type: string
                    description: The workspace's URL slug, or "" when the stored slug isn't URL-shaped (use the id).
        "404":
          description: Not found, or not the caller's to open (the same response either way)
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
        "429":
          description: Too many lookups; retry after the Retry-After seconds
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
  /v1/forms/{id}:
    parameters:
      - { name: id, in: path, required: true, schema: { type: string } }
    get:
      operationId: getForm
      tags: [forms]
      summary: Form detail (composite)
      description: >-
        The form plus a PREVIEW of its latest 25 submissions (including spam),
        the field names those submissions carry, and a 14-day daily series of
        non-spam submissions. The preview is not the inbox: read it with
        listSubmissions, which pages and says how many there are. Readable: the
        caller's own form or one a teammate shared with the organization.
      responses:
        "200":
          description: Form, recent submissions, field names, and series
          content:
            application/json:
              schema:
                type: object
                required: [form, submissions, fields, series]
                properties:
                  form: { $ref: "#/components/schemas/Form" }
                  submissions:
                    type: array
                    maxItems: 25
                    description: The latest 25, newest first, spam included
                    items: { $ref: "#/components/schemas/Submission" }
                  fields:
                    type: array
                    maxItems: 50
                    description: >-
                      Field names filled in (not blank) in the newest 500
                      accepted submissions, most common first, as they were
                      sent (a name with a space, brackets or non-Latin letters
                      is listed too; a name longer than 200 characters is not).
                      The form's own plumbing (names that start with an
                      underscore, like the _gotcha honeypot) is left out.
                      Names the field summary would refuse are not filtered
                      here: a client that offers them as a breakdown picks
                      only the ones that match its field-name pattern.
                    items: { type: string }
                  spamFields:
                    type: array
                    maxItems: 50
                    description: >-
                      The same, from the newest 100 spam submissions (empty for
                      a form with no spam). Spam can carry fields no accepted
                      submission has, so a table of the spam shows these as
                      its columns.
                    items: { type: string }
                  series:
                    type: array
                    items: { $ref: "#/components/schemas/DaySubmissions" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/ToolDisabled" }
        "404": { $ref: "#/components/responses/NotFound" }
    patch:
      operationId: updateForm
      tags: [forms]
      summary: Update form settings
      description: >-
        Partial update. Owner-only — a form shared with the caller by a
        teammate is readable but returns 403 here. Only the fields present in
        the body are changed. contentFilter must be off/low/medium/high;
        visibility must be private or org; projectId must belong to the
        caller; retentionDays must be 1-3650 or null; spamProvider must be
        none or turnstile (a 400 naming spamProvider otherwise).
        successBehavior, redirectUrl, targetEmails and allowedOrigins are
        validated (see each field for its rules and limits). A rejected value
        is a 400 whose message names the field, and nothing in the request is
        applied. A value of those four fields that is sent back exactly as it
        is already stored (for targetEmails: as the form shows it) is not
        checked again, so a form saved before this validation existed can
        still be updated; only a changed value must be valid. Where such a
        stored value is used it is checked again: see the ingest endpoint
        and targetEmails.
        Turning Turnstile on needs Easerix's Turnstile keys (409
        turnstile_unavailable otherwise) and at least one allowed origin,
        each written as a bare origin like https://example.com (400 otherwise,
        also when origins change while Turnstile is on), and starts in the
        waiting state; turning it off clears the
        enforcement time. Every allowed-origin host of a Turnstile form must
        be covered by a verified Turnstile domain of the form's workspace
        (409 turnstile_domain_unverified with the host otherwise), checked
        when Turnstile is turned on or the origins change. When Easerix
        manages the widget's hostname list, an opt-in that would list more
        than 180 sites is refused (409 turnstile_capacity).
        The autoresponder object mirrors the response nesting.
        Changing retentionDays is recorded in the audit log
        (form.retention_changed).


        targetEmails edits the form's email destinations, not a field of the
        form. A list that equals the targetEmails the form currently shows is
        not a change, so a client that sends every setting on each save is not
        affected. A different list replaces config.to of the form's only email
        destination (enabled or not; a non-empty list also switches a disabled
        one on, so the response shows the saved list and it is mailed; an
        empty list clears it but keeps the destination as it is), creates an
        enabled email destination when the form has
        none and the list is not empty, and does nothing when the form has none
        and the list is empty. A form with more than one email destination
        answers 409 to a changed list and applies nothing: change the
        recipients of each destination through the destinations endpoints.
        The destination and the rest of the request are saved in one
        transaction.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string }
                projectId: { type: string }
                targetEmails: { $ref: "#/components/schemas/TargetEmails" }
                allowedOrigins: { $ref: "#/components/schemas/AllowedOrigins" }
                successBehavior: { $ref: "#/components/schemas/SuccessBehavior" }
                redirectUrl: { $ref: "#/components/schemas/RedirectUrl" }
                blockedSenders:
                  type: array
                  maxItems: 200
                  description: >-
                    Replaces the form's block list. Each entry is an email address
                    or a domain (a leading @ is dropped; entries are lowercased and
                    de-duplicated). A domain also covers its subdomains. A
                    submission whose sender email or any link matches is kept as
                    spam with reason "blocked sender" and sends no notification.
                    An entry that is neither is a 400 with code invalid_block_list.
                  items: { type: string, maxLength: 254 }
                honeypot: { type: boolean }
                spamProvider: { $ref: "#/components/schemas/SpamProvider" }
                contentFilter: { type: string, enum: [off, low, medium, high] }
                aiFilter: { type: boolean }
                aiContext:
                  type: string
                  maxLength: 2000
                  description: >-
                    The owner's description of who they are and what they offer,
                    read by the AI spam filter so a visitor asking for the
                    owner's services is treated as a lead, not a sales pitch.
                    Whitespace is folded to single spaces; at most 500
                    characters after that, or a 400 with code invalid_ai_context.
                    An empty string clears it.
                minSubmitSeconds:
                  type: integer
                  minimum: 0
                  maximum: 60
                  description: >-
                    Minimum time to submit, in seconds; 0 turns it off. A
                    submission whose _elapsed field (the milliseconds the visitor
                    spent on the page, measured by the owner's site in the
                    browser) is below it is kept as spam with reason "submitted
                    too fast" and sends no notification. A submission without a
                    readable, non-negative _elapsed is not checked. Outside 0 to
                    60 is a 400 with code invalid_min_submit_seconds.
                autoresponder:
                  type: object
                  properties:
                    enabled: { type: boolean }
                    subject: { type: string }
                    body: { type: string }
                active: { type: boolean }
                visibility: { type: string, enum: [private, org] }
                retentionDays:
                  type: integer
                  minimum: 1
                  maximum: 3650
                  nullable: true
                  description: >-
                    Delete submissions older than this many days. null keeps
                    them forever; omit the field to leave it unchanged. A
                    background sweep (hourly) does the deleting.
                storeClientMeta:
                  type: boolean
                  description: >-
                    false stores no IP address, User-Agent or referrer with new
                    submissions (existing submissions are not changed).
      responses:
        "200":
          description: Updated form
          content:
            application/json:
              schema:
                type: object
                required: [form]
                properties:
                  form: { $ref: "#/components/schemas/Form" }
        "400": { $ref: "#/components/responses/ValidationError" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }
        "409":
          description: >-
            A changed targetEmails could not be applied: the form has several
            email destinations (change their recipients through the
            destinations endpoints), or its destination was removed while
            saving. Or Turnstile can't be turned on: Easerix has
            no Turnstile keys configured (turnstile_unavailable), an origin's
            host isn't a verified Turnstile domain of the workspace
            (turnstile_domain_unverified, with host), or the shared widget has
            no room for more sites (turnstile_capacity). Nothing in the
            request was applied.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
    delete:
      operationId: deleteForm
      tags: [forms]
      summary: Delete a form
      description: >-
        Owner-only; deletes the form and its submissions cascade. A form shared
        with the caller returns 403.
      responses:
        "200":
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  message: { type: string }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }

  /v1/submissions:
    get:
      operationId: listAllSubmissions
      tags: [submissions]
      summary: List submissions across forms
      description: >-
        The same as listSubmissions across every form the caller may read: their
        own, plus forms a teammate shared with the workspace (scoped exactly as
        the forms list is). One request instead of one per form. Each row also
        carries its form's name and project. q also matches a form's name. A
        formId or projectId that is not the caller's matches nothing: the
        answer is an empty page, never a 404.


        It lists at most the first 1000 submissions that match, in the order
        asked for: a page that starts at or past offset 1000 is empty, and a
        page that would run over it is cut at it. total stops at 1000 and
        totalCapped says there are more. This keeps a page's cost to what is
        read, however much the workspace holds; to reach older submissions,
        narrow the question (formId, projectId, from/to, q, status) or read one
        form's own list, which pages without this limit.
      parameters:
        - $ref: "#/components/parameters/PageLimit"
        - $ref: "#/components/parameters/SubmissionOffset"
        - $ref: "#/components/parameters/SubmissionStatus"
        - $ref: "#/components/parameters/SubmissionQuery"
        - $ref: "#/components/parameters/SubmissionFrom"
        - $ref: "#/components/parameters/SubmissionTo"
        - $ref: "#/components/parameters/SubmissionSort"
        - name: formId
          in: query
          schema: { type: string }
          description: Only this form's submissions
        - name: projectId
          in: query
          schema: { type: string, format: uuid }
          description: Only submissions of forms in this project
      responses:
        "200":
          description: A page of submissions
          content:
            application/json:
              schema:
                type: object
                required: [submissions, limit, offset, total, totalCapped]
                properties:
                  submissions:
                    type: array
                    items: { $ref: "#/components/schemas/InboxSubmission" }
                  limit: { type: integer, description: The page size in effect }
                  offset: { type: integer, description: How many rows were skipped }
                  total:
                    type: integer
                    format: int64
                    maximum: 1000
                    description: >-
                      The submissions the filters match, on every page, up to
                      1000 (see totalCapped)
                  totalCapped:
                    type: boolean
                    description: >-
                      True when more than 1000 submissions match, so total is
                      1000 and the rest are not listed
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/ToolDisabled" }

  /v1/forms/{id}/submissions:
    parameters:
      - { name: id, in: path, required: true, schema: { type: string } }
    get:
      operationId: listSubmissions
      tags: [submissions]
      summary: List submissions
      description: >-
        A page of the form's submissions, newest first by default, filtered on
        the server with limit and offset. Accepted submissions only unless
        status says otherwise. total counts every row the filters match, not
        the page, and comes with every page, so a pager knows how many pages
        there are; an offset past the end is an empty page with that total, not
        an error. Rows are ordered by (created time, id), so rows sharing an
        instant keep their places from one page to the next. Without limit, a
        page is 500 rows, what this endpoint always returned. Submissions are
        children of the form, so a teammate who can read a shared form can read
        its inbox.


        A search (q) has no index: it reads every value of every row. So with q
        the list stops at the first 1000 matches, in the order asked for, as
        listAllSubmissions does: total stops at 1000 and totalCapped says there
        are more, and a page at or past offset 1000 is empty. Without q the whole
        form pages, with an exact total. The export takes every match either way.
      parameters:
        - $ref: "#/components/parameters/PageLimit"
        - $ref: "#/components/parameters/SubmissionOffset"
        - $ref: "#/components/parameters/SubmissionStatus"
        - $ref: "#/components/parameters/SubmissionQuery"
        - $ref: "#/components/parameters/SubmissionFrom"
        - $ref: "#/components/parameters/SubmissionTo"
        - $ref: "#/components/parameters/SubmissionSort"
        - name: includeSpam
          in: query
          deprecated: true
          schema: { type: string, enum: ["true"] }
          description: >-
            Older spelling of status=all, honoured when status is absent. Spam
            is included only when exactly "true".
      responses:
        "200":
          description: A page of submissions
          content:
            application/json:
              schema:
                type: object
                required: [submissions, limit, offset, total]
                properties:
                  submissions:
                    type: array
                    items: { $ref: "#/components/schemas/Submission" }
                  limit: { type: integer, description: The page size in effect }
                  offset: { type: integer, description: How many rows were skipped }
                  total:
                    type: integer
                    format: int64
                    description: >-
                      Every submission the filters match, on every page. With
                      q, at most 1000 (see totalCapped).
                  totalCapped:
                    type: boolean
                    description: >-
                      Sent with q only: true when more than 1000 submissions
                      match, so total is 1000 and the rest are not listed
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/ToolDisabled" }
        "404": { $ref: "#/components/responses/NotFound" }
    delete:
      operationId: deleteSubmissions
      tags: [submissions]
      summary: Delete submissions in bulk
      description: >-
        Hard-deletes submissions and takes them off the form's counters.
        Exactly one selector, from the JSON body or the query string: ids
        (at most 1000; in the query, repeated or comma-separated) deletes those
        submissions whether or not they are spam, and ids of other forms are
        ignored; before (RFC 3339) deletes everything received before that
        instant, leaving spam alone unless includeSpam is true. Owner-only —
        a shared form returns 403. Recorded in the audit log
        (submissions.deleted) when anything was deleted.
      parameters:
        - name: ids
          in: query
          schema:
            type: array
            items: { type: string }
          style: form
          explode: true
        - name: before
          in: query
          schema: { type: string, format: date-time }
        - name: includeSpam
          in: query
          schema: { type: string, enum: ["true", "false"] }
          description: With before, spam is included only when "true"
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                ids:
                  type: array
                  maxItems: 1000
                  items: { type: string }
                before: { type: string, format: date-time }
                includeSpam: { type: boolean, default: false }
      responses:
        "200":
          description: How many submissions were deleted
          content:
            application/json:
              schema:
                type: object
                required: [deleted]
                properties:
                  deleted: { type: integer, format: int64 }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }

  /v1/forms/{id}/submissions/export:
    parameters:
      - { name: id, in: path, required: true, schema: { type: string } }
    get:
      operationId: exportSubmissions
      tags: [submissions]
      summary: Export every matching submission
      description: >-
        Streams every submission the filters match, as CSV or JSON, with no row
        cap. status, q, from, to and sort mean what they mean in listSubmissions
        (accepted submissions unless status says otherwise); limit and offset do
        not apply. X-Total-Count is how many rows the file should hold. The CSV
        has one column per field name found in the matching rows, most common
        first, then created and isSpam, and keeps the spreadsheet guard: any
        cell (and any header) starting with =, +, -, @, a tab or a carriage
        return gets a leading apostrophe so it opens as text, never a formula.
        The JSON is an array of {id, created, isSpam, data} with the values
        exactly as submitted. If the matching rows have more than 2000 distinct
        field names the CSV is refused with 422 and the JSON export still
        works. Readable, like the list it exports, and recorded in the audit
        log (submissions.exported).
      parameters:
        - name: format
          in: query
          schema: { type: string, enum: [csv, json], default: csv }
        - $ref: "#/components/parameters/SubmissionStatus"
        - $ref: "#/components/parameters/SubmissionQuery"
        - $ref: "#/components/parameters/SubmissionFrom"
        - $ref: "#/components/parameters/SubmissionTo"
        - $ref: "#/components/parameters/SubmissionSort"
      responses:
        "200":
          description: The file, as an attachment
          headers:
            X-Total-Count:
              description: How many rows the file should hold
              schema: { type: integer, format: int64 }
            Content-Disposition:
              schema: { type: string }
          content:
            text/csv:
              schema: { type: string }
            application/json:
              schema:
                type: array
                items:
                  type: object
                  required: [id, created, isSpam, data]
                  properties:
                    id: { type: string }
                    created: { type: string, format: date-time }
                    isSpam: { type: boolean }
                    data:
                      type: object
                      additionalProperties: { type: string }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/ToolDisabled" }
        "404": { $ref: "#/components/responses/NotFound" }
        "422":
          description: Too many distinct field names for a CSV; export JSON instead
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429":
          description: Too many exports are running, or the caller reached the rate limit; retry after the Retry-After seconds
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }

  /v1/forms/{id}/submissions/{sid}:
    parameters:
      - { name: id, in: path, required: true, schema: { type: string } }
      - { name: sid, in: path, required: true, schema: { type: string } }
    patch:
      operationId: markSpam
      tags: [submissions]
      summary: Mark spam / not spam
      description: >-
        Flips the spam flag and adjusts the form's spamCount. Returns a
        message, not the submission. Owner-only — triaging a shared form's
        inbox returns 403.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [isSpam]
              properties:
                isSpam: { type: boolean }
      responses:
        "200":
          description: Updated
          content:
            application/json:
              schema:
                type: object
                properties:
                  message: { type: string }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }
    delete:
      operationId: deleteSubmission
      tags: [submissions]
      summary: Delete a submission
      description: >-
        Hard-deletes the submission and decrements the form's counters.
        Owner-only — deleting from a shared form's inbox returns 403. Recorded
        in the audit log (submission.deleted).
      responses:
        "200":
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  message: { type: string }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }

  /v1/forms/{id}/submissions/{sid}/release:
    parameters:
      - { name: id, in: path, required: true, schema: { type: string } }
      - { name: sid, in: path, required: true, schema: { type: string } }
    post:
      operationId: releaseSubmission
      tags: [submissions]
      summary: Release a held submission
      description: >-
        Sends a held submission (held = true: the AI filter could not check it,
        so nothing was sent) as any delivered post is: the owner email and
        notification, the autoresponse and the form's destinations. Clears the
        hold. The message is "released" when this call sent it, and "not held"
        (nothing sent) when the submission was not held, so a repeat is safe.
        Owner-only — releasing from a shared form's inbox returns 403. Recorded
        in the audit log (submission.released).
      responses:
        "200":
          description: Released, or not held
          content:
            application/json:
              schema:
                type: object
                properties:
                  message: { type: string, enum: [released, not held] }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }

  /v1/forms/{id}/summary:
    parameters:
      - { name: id, in: path, required: true, schema: { type: string } }
    get:
      operationId: getFormFieldSummary
      tags: [submissions]
      summary: Submission counts by field value
      description: >-
        Counts of the form's submissions grouped by the value of one or more
        submitted fields (data->>field), largest first, with a missing or blank
        value counted as "(none)". Each breakdown keeps the top 100 values;
        other is how many submissions fall in values past that cap. Spam is
        excluded unless includeSpam=true. Readable: the caller's own form or
        one a teammate shared with the organization.
      parameters:
        - name: field
          in: query
          required: true
          description: >-
            Field name to group by — letters, digits, _ - . only, up to 100
            characters. Repeat (or comma-separate) for up to 5 fields; one
            breakdown is returned per field, in the order given.
          schema:
            type: array
            minItems: 1
            maxItems: 5
            items: { type: string, pattern: '^[A-Za-z0-9_.-]{1,100}$' }
          style: form
          explode: true
        - name: from
          in: query
          description: Inclusive start, YYYY-MM-DD (UTC midnight) or RFC 3339
          schema: { type: string }
        - name: to
          in: query
          description: >-
            Exclusive end as RFC 3339, or YYYY-MM-DD to include that whole
            day (UTC)
          schema: { type: string }
        - name: includeSpam
          in: query
          schema: { type: string, enum: ["true", "false"] }
          description: Spam included only when exactly "true"
      responses:
        "200":
          description: One breakdown per requested field
          content:
            application/json:
              schema:
                type: object
                required: [total, from, to, includeSpam, breakdowns]
                properties:
                  total:
                    type: integer
                    format: int64
                    description: Submissions matching the range and spam filter
                  from: { type: string, format: date-time, nullable: true }
                  to: { type: string, format: date-time, nullable: true }
                  includeSpam: { type: boolean }
                  breakdowns:
                    type: array
                    items: { $ref: "#/components/schemas/FieldBreakdown" }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/ToolDisabled" }
        "404": { $ref: "#/components/responses/NotFound" }

  /v1/forms/{id}/sources:
    parameters:
      - { name: id, in: path, required: true, schema: { type: string } }
    get:
      operationId: getFormSources
      tags: [submissions]
      summary: Where the form's submissions came from
      description: >-
        The form's non-spam submissions counted by source group, computed from
        the attribution fields a site adds (attr_source, attr_referrer_host,
        attr_medium) and checked in order: ai, search, social, direct (no
        source and no referrer), other. Every group is listed, zeros included.
        heardAbout holds the top 20 answers to the heard_about field. Counts
        only. Readable: the caller's own form or one a teammate shared with
        the organization.
      parameters:
        - name: from
          in: query
          description: Inclusive start, YYYY-MM-DD (UTC midnight) or RFC 3339
          schema: { type: string }
        - name: to
          in: query
          description: >-
            Exclusive end as RFC 3339, or YYYY-MM-DD to include that whole
            day (UTC)
          schema: { type: string }
      responses:
        "200":
          description: Submission counts by source group, with heard_about
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SourceSummary" }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/ToolDisabled" }
        "404": { $ref: "#/components/responses/NotFound" }

  /v1/forms/{id}/destinations:
    parameters:
      - { name: id, in: path, required: true, schema: { type: string } }
    get:
      operationId: listDestinations
      tags: [destinations]
      summary: List destinations
      description: >-
        Delivery destinations, created_at ascending. Readable with the form, so
        a teammate a form is shared with can see where it delivers.
      responses:
        "200":
          description: Destinations
          content:
            application/json:
              schema:
                type: object
                required: [destinations]
                properties:
                  destinations:
                    type: array
                    items: { $ref: "#/components/schemas/Destination" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/ToolDisabled" }
        "404": { $ref: "#/components/responses/NotFound" }
    post:
      operationId: createDestination
      tags: [destinations]
      summary: Add a destination
      description: >-
        type must be one of email/webhook/slack/sheets/zapier/crm — only email
        is delivered in v1. enabled defaults true. Owner-only — adding one to a
        shared form returns 403. For type email, config.to is checked like
        targetEmails (see that field) and stored normalized: a list of bare
        addresses, at most 10 of at most 254 characters, trimmed, blanks and
        case-insensitive duplicates dropped, one address per entry. Anything
        else is a 400 whose message names config.to and nothing is stored.
        config may omit to, and other keys are kept. Other destination types
        are not checked. A form's recipients are the union of the enabled email
        destinations (see targetEmails on the form).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [type]
              properties:
                type:
                  type: string
                  enum: [email, webhook, slack, sheets, zapier, crm]
                config:
                  type: object
                  additionalProperties: true
                enabled: { type: boolean }
                connectionId:
                  type: string
                  format: uuid
                  description: >-
                    A destination of an app (type slack, when that app is on) posts through
                    this connection of the workspace, which is required and must be working.
                    The connection lives in the integrations service, which checks it and the
                    config before the destination is saved: for Slack exactly channel_id and,
                    optionally, channel_name.
      responses:
        "201":
          description: Destination created
          content:
            application/json:
              schema:
                type: object
                required: [destination]
                properties:
                  destination: { $ref: "#/components/schemas/Destination" }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }
        "409":
          description: The connection was revoked and needs to be reconnected (code connection_revoked)
          content:
            application/json:
              schema: { $ref: "#/components/schemas/IntegrationError" }
        "503":
          description: The integrations service could not check the destination; try again
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "500": { $ref: "#/components/responses/ServerError" }

  /v1/forms/{id}/destinations/{did}:
    parameters:
      - { name: id, in: path, required: true, schema: { type: string } }
      - { name: did, in: path, required: true, schema: { type: string } }
    patch:
      operationId: updateDestination
      tags: [destinations]
      summary: Update a destination
      description: >-
        Partial update; config is replaced wholesale, not merged. Owner-only —
        editing a shared form's destination returns 403. When the destination
        is of type email, a config sent here is checked and normalized like
        config.to on create (a rejected value is a 400 naming config.to, and
        nothing is changed), and so is the config it already holds when this
        request changes another destination into an email one. Switching
        enabled on or off checks nothing.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                type:
                  type: string
                  enum: [email, webhook, slack, sheets, zapier, crm]
                config:
                  type: object
                  additionalProperties: true
                enabled: { type: boolean }
                connectionId:
                  type: string
                  format: uuid
                  description: >-
                    A destination of an app (type slack, when that app is on) posts through
                    this connection of the workspace, which is required and must be working.
                    The connection lives in the integrations service, which checks it and the
                    config before the destination is saved: for Slack exactly channel_id and,
                    optionally, channel_name.
      responses:
        "200":
          description: Updated destination
          content:
            application/json:
              schema:
                type: object
                required: [destination]
                properties:
                  destination: { $ref: "#/components/schemas/Destination" }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }
        "409":
          description: The connection was revoked and needs to be reconnected (code connection_revoked)
          content:
            application/json:
              schema: { $ref: "#/components/schemas/IntegrationError" }
        "503":
          description: The integrations service could not check the destination; try again
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
    delete:
      operationId: deleteDestination
      tags: [destinations]
      summary: Delete a destination
      description: Owner-only delete; a shared form's destination returns 403.
      responses:
        "200":
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  message: { type: string }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }

  /v1/turnstile/domains:
    get:
      operationId: listTurnstileDomains
      tags: [turnstile]
      summary: List the workspace's Turnstile domains
      description: >-
        Domains the caller's workspace has claimed for Turnstile, verified or
        not, with the proof each needs. Any member of the workspace.
      responses:
        "200":
          description: Domains
          content:
            application/json:
              schema:
                type: object
                required: [domains, limit]
                properties:
                  domains:
                    type: array
                    items: { $ref: "#/components/schemas/TurnstileDomain" }
                  limit: { type: integer, description: Most domains one workspace may claim }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/ToolDisabled" }
    post:
      operationId: createTurnstileDomain
      tags: [turnstile]
      summary: Claim a Turnstile domain
      description: >-
        Claims a host (like example.com) and returns the proof to publish.
        Refused (400) with a code: turnstile_host_ip (an IP address),
        turnstile_host_local (a local name), turnstile_host_shared (a public
        suffix or shared platform name; their subdomains are fine),
        turnstile_host_easerix (Easerix's own names), turnstile_host_invalid
        (not a domain name). Claiming a host already claimed returns it (200). At most
        `limit` domains per workspace (409 turnstile_domain_limit).
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [host]
              properties:
                host: { type: string, example: example.com }
      responses:
        "200":
          description: Already claimed
          content:
            application/json:
              schema:
                type: object
                required: [domain]
                properties:
                  domain: { $ref: "#/components/schemas/TurnstileDomain" }
        "201":
          description: Claimed
          content:
            application/json:
              schema:
                type: object
                required: [domain]
                properties:
                  domain: { $ref: "#/components/schemas/TurnstileDomain" }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/ToolDisabled" }
        "409":
          description: The workspace already has the most domains allowed (turnstile_domain_limit)
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
  /v1/turnstile/domains/{host}/verify:
    parameters:
      - { name: host, in: path, required: true, schema: { type: string } }
    post:
      operationId: verifyTurnstileDomain
      tags: [turnstile]
      summary: Check a Turnstile domain's proof
      description: >-
        Looks for the proof: a DNS TXT record at proof.dnsName holding
        proof.dnsValue (verifies the host and its subdomains), else the file
        at proof.fileUrl holding proof.fileBody (verifies that host only;
        fetched over HTTPS on port 443 from public addresses only, no
        redirects). At most 6 checks per workspace per minute. Another
        workspace's domain is 404.
      responses:
        "200":
          description: Verified (now or before)
          content:
            application/json:
              schema:
                type: object
                required: [domain]
                properties:
                  domain: { $ref: "#/components/schemas/TurnstileDomain" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/ToolDisabled" }
        "404": { $ref: "#/components/responses/NotFound" }
        "429":
          description: Too many proof checks for the workspace this minute (turnstile_verify_rate_limited), or the caller reached the rate limit
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "422":
          description: Neither proof was found (turnstile_proof_not_found)
          content:
            application/json:
              schema:
                type: object
                required: [error]
                properties:
                  error: { type: string }
                  domain: { $ref: "#/components/schemas/TurnstileDomain" }
  /v1/turnstile/domains/{host}:
    parameters:
      - { name: host, in: path, required: true, schema: { type: string } }
    delete:
      operationId: deleteTurnstileDomain
      tags: [turnstile]
      summary: Remove a Turnstile domain
      description: >-
        Refused (409 turnstile_domain_in_use, with formId) while a form of the
        workspace using Turnstile relies on it. Another workspace's domain is
        404.
      responses:
        "204": { description: Removed }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/ToolDisabled" }
        "404": { $ref: "#/components/responses/NotFound" }
        "409":
          description: A Turnstile form still relies on the domain (turnstile_domain_in_use)
          content:
            application/json:
              schema:
                type: object
                required: [error]
                properties:
                  error: { type: string }
                  formId: { type: string }

  /v1/summary:
    get:
      operationId: summary
      tags: [summary]
      summary: Account-wide aggregates
      description: >-
        Totals, top five forms by submission count (full form DTOs), the eight
        most recent non-spam submissions across all forms, and a sparse
        14-day daily series.
      responses:
        "200":
          description: Aggregates
          content:
            application/json:
              schema:
                type: object
                required: [totalForms, activeForms, totalSubmissions, spamBlocked, topForms, recentSubmissions, byDay]
                properties:
                  totalForms: { type: integer }
                  activeForms: { type: integer }
                  totalSubmissions: { type: integer, format: int64 }
                  spamBlocked: { type: integer, format: int64 }
                  topForms:
                    type: array
                    maxItems: 5
                    items: { $ref: "#/components/schemas/Form" }
                  recentSubmissions:
                    type: array
                    maxItems: 8
                    items: { $ref: "#/components/schemas/RecentSubmission" }
                  byDay:
                    type: array
                    items: { $ref: "#/components/schemas/DaySubmissions" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/ToolDisabled" }

  /v1/analytics:
    get:
      operationId: submissionsOverview
      tags: [summary]
      summary: Submissions per day, month or year
      description: >-
        How many submissions arrived per period, split into accepted and spam,
        across the forms the caller can read (their own and any a teammate
        shared with the workspace). Counted in the database, so a form with
        more than 500 submissions is counted in full. Periods are cut in the
        viewer's timezone, not UTC, and a period with nothing in it is returned
        as zero, so the series has no gaps. day lists every day of the anchor's
        month; month the 12 months ending with the anchor's month; year every
        year from the first to the last that has a submission (the anchor is
        ignored), or the anchor's year alone when there are none. from and to
        narrow what is counted as they narrow listSubmissions, so a chart above
        a filtered list counts what the list shows: the periods stay, what is
        outside the range counts as zero, and the year view spans the years
        that have something in the range.
      parameters:
        - $ref: "#/components/parameters/SubmissionFrom"
        - $ref: "#/components/parameters/SubmissionTo"
        - name: view
          in: query
          required: true
          schema: { type: string, enum: [day, month, year] }
        - name: tz
          in: query
          required: true
          description: IANA timezone name of the viewer, such as Asia/Kolkata
          schema: { type: string, example: Asia/Kolkata }
        - name: anchor
          in: query
          description: >-
            A date, YYYY-MM-DD, in the viewer's timezone, between the years
            2000 and 2100. Defaults to today.
          schema: { type: string, format: date }
        - name: formId
          in: query
          description: Count one form only. 404 unless the caller can read it.
          schema: { type: string }
        - name: projectId
          in: query
          description: >-
            Count the forms of one project only. 404 unless the caller can
            read it. Combined with formId, both apply.
          schema: { type: string }
      responses:
        "200":
          description: One bucket per period, oldest first
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SubmissionsOverview" }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/ToolDisabled" }
        "404": { $ref: "#/components/responses/NotFound" }

  /v1/sources:
    get:
      operationId: sources
      tags: [summary]
      summary: Where submissions came from, across forms
      description: >-
        The same counts as getFormSources, across every form the caller owns
        in the active organization (the scope of /v1/summary).
      parameters:
        - name: from
          in: query
          description: Inclusive start, YYYY-MM-DD (UTC midnight) or RFC 3339
          schema: { type: string }
        - name: to
          in: query
          description: >-
            Exclusive end as RFC 3339, or YYYY-MM-DD to include that whole
            day (UTC)
          schema: { type: string }
      responses:
        "200":
          description: Submission counts by source group, with heard_about
          content:
            application/json:
              schema: { $ref: "#/components/schemas/SourceSummary" }
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/ToolDisabled" }

  /v1/forms/{id}/deliveries:
    parameters:
      - { name: id, in: path, required: true, schema: { type: string } }
    get:
      operationId: listFormDeliveries
      tags: [integrations]
      summary: List where a form's submissions were sent
      description: >-
        One entry for each submission and destination, newest first. Readable
        with the form, like its destinations. An entry carries ids, counts and
        a short reason code, never the submission.
      parameters:
        - name: limit
          in: query
          description: How many to return, 100 by default and at most 200
          schema: { type: integer, minimum: 1, maximum: 200 }
      responses:
        "200":
          description: Deliveries
          content:
            application/json:
              schema:
                type: object
                required: [deliveries]
                properties:
                  deliveries:
                    type: array
                    items: { $ref: "#/components/schemas/Delivery" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/ToolDisabled" }
        "404": { $ref: "#/components/responses/NotFound" }
        "500": { $ref: "#/components/responses/ServerError" }

  /v1/forms/{id}/deliveries/{jid}/replay:
    parameters:
      - { name: id, in: path, required: true, schema: { type: string } }
      - { name: jid, in: path, required: true, schema: { type: string } }
    post:
      operationId: replayFormDelivery
      tags: [integrations]
      summary: Send a failed delivery again
      description: >-
        Puts a dead or cancelled delivery back in the queue with its tries
        reset. It keeps its place in the destination's order. Owner-only:
        replaying on a shared form returns 403. A delivery that is not over is
        a 409.
      responses:
        "200":
          description: Queued
          content:
            application/json:
              schema:
                type: object
                required: [message]
                properties:
                  message: { type: string, example: queued }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }
        "409":
          description: Only a failed or cancelled delivery can be sent again (code not_replayable)
          content:
            application/json:
              schema: { $ref: "#/components/schemas/IntegrationError" }
        "500": { $ref: "#/components/responses/ServerError" }

  /v1/{any}:
    options:
      operationId: mgmtPreflight
      tags: [system]
      summary: Management CORS preflight catch-all
      description: >-
        Unauthenticated catch-all so browser preflights to any /v1 path get
        CORS headers instead of a bare 404.
      security: []
      parameters:
        - { name: any, in: path, required: true, schema: { type: string } }
      responses:
        "204":
          description: Preflight OK (empty body)

  /{id}:
    parameters:
      - { name: id, in: path, required: true, schema: { type: string } }
    post:
      operationId: ingest
      tags: [ingest]
      summary: Submit a form (public)
      description: >-
        The product itself. Accepts application/json,
        x-www-form-urlencoded, or multipart/form-data (files not stored; names
        joined into a synthetic _files field). Reserved fields _gotcha/_honey
        (honeypot), _elapsed (milliseconds the visitor spent on the page,
        measured in the browser; checked against the form's minSubmitSeconds)
        and cf-turnstile-response (the Turnstile token, sent in the body) are
        stripped. A post may carry at most 100 fields (not counting
        those reserved ones), and a field name may be at most 200 bytes; a post
        past either is refused with 413, as is a body over 1 MiB (10 MiB for
        multipart/form-data, which may carry files; the files are not stored).
        A field value past 5000 bytes is cut on a character boundary, ends with
        "… [truncated]", and is at most 5000 bytes with that marker; the post
        is kept. Spam-flagged submissions still return success.
        The submitter's reply address (used for the autoresponder and the
        owner's Reply-To) is taken from the email field, or else the first
        field named like an email field, and only when it is a valid address;
        otherwise no autoresponse is sent.
        When the form has allowedOrigins, a post whose Origin is not on the
        list, or that has no Origin, is kept as spam (reason "origin not
        allowed") and is not notified; it gets no CORS grant.
        A stored allowedOrigins entry that is not a valid origin (one saved
        before origins were validated) matches no Origin, but the list still
        counts as set, so it does not open the form to every origin. A
        stored redirectUrl that is not an absolute http(s) URL is not
        followed: the post is answered as if the form had none.
        JSON clients (?ajax=1, Accept, or JSON content type) get
        {ok, id}; HTML posts get a 302 to redirectUrl when configured; else a
        browser (Accept text/html) gets the hosted thank-you page and other
        clients get {ok}. Rate limit 60/min per form+IP.
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: true
          application/x-www-form-urlencoded:
            schema:
              type: object
              additionalProperties: true
          multipart/form-data:
            schema:
              type: object
              additionalProperties: true
      responses:
        "200":
          description: Accepted ({ok, id} for JSON clients; the thank-you page for browser posts without redirect; {ok} for other HTML posts)
          content:
            application/json:
              schema:
                type: object
                required: [ok]
                properties:
                  ok: { type: boolean }
                  id: { type: string, description: Submission id (JSON clients only) }
            text/html:
              schema:
                type: string
                description: Hosted thank-you page with the "Made with Easerix Forms" badge (Accept text/html, no redirect set)
        "302":
          description: HTML post with successBehavior redirect — Location is the form's redirectUrl
          headers:
            Location:
              schema: { type: string }
        "400":
          description: Could not parse submission
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "404":
          description: Form not found or inactive (deliberately indistinguishable)
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "413":
          description: >-
            Too many fields (over 100), a field name over 200 bytes, or a body
            over 1 MiB (10 MiB for multipart/form-data); nothing is stored
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429":
          description: >-
            Rate limit exceeded: too many posts to this form from this address, to this form in all,
            or from this address to any form. The last carries Retry-After.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "500":
          description: Could not save submission
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
    options:
      operationId: ingestPreflight
      tags: [ingest]
      summary: Ingest CORS preflight (public)
      description: 204 with per-form CORS headers; 404/403 with empty bodies for unknown forms or disallowed origins.
      security: []
      responses:
        "204":
          description: Preflight OK (empty body)
        "403":
          description: Origin not allowed (empty body)
        "404":
          description: Form not found or inactive (empty body)
        "429":
          description: Too many requests from this address; retry after the Retry-After seconds (a JSON error, with no CORS headers because the form is not read yet)
    get:
      operationId: ingestInfo
      tags: [ingest]
      summary: Endpoint hint (public)
      description: Unconditional helper response — the form is not looked up.
      security: []
      responses:
        "200":
          description: Usage hint
          content:
            application/json:
              schema:
                type: object
                properties:
                  message: { type: string }
                  method: { type: string }

components:
  parameters:
    PageLimit:
      name: limit
      in: query
      schema: { type: integer, minimum: 1, maximum: 500, default: 500 }
      description: Page size, a whole number from 1. Larger than 500 is clamped to 500. Given but not usable (0, negative, not a number) is a 400. Left out means 500.
    SubmissionOffset:
      name: offset
      in: query
      schema: { type: integer, minimum: 0, default: 0 }
      description: >-
        How many rows to skip: (page - 1) * limit. A whole number, 0 or more; given but not usable is a 400. Left out means 0; one past the end is an empty page, not an error.
    SubmissionStatus:
      name: status
      in: query
      schema: { type: string, enum: [accepted, spam, all], default: accepted }
    SubmissionQuery:
      name: q
      in: query
      schema: { type: string, maxLength: 200 }
      description: >-
        Text to find in a submission's field VALUES, case-insensitive, anywhere
        in the value. Field names are not searched. % and _ are literal.
    SubmissionFrom:
      name: from
      in: query
      schema: { type: string }
      description: Inclusive start, YYYY-MM-DD (UTC midnight) or RFC 3339
    SubmissionTo:
      name: to
      in: query
      schema: { type: string }
      description: >-
        Exclusive end as RFC 3339, or YYYY-MM-DD to include that whole day (UTC)
    SubmissionSort:
      name: sort
      in: query
      schema: { type: string, enum: [newest, oldest], default: newest }
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
      bearerFormat: JWT
  schemas:
    TargetEmails:
      type: array
      maxItems: 10
      items: { type: string, format: email, maxLength: 254 }
      description: >-
        Addresses that get a notification, as bare addresses ("a@example.com",
        not "Ada <a@example.com>"), one per entry. At most 10 entries of at
        most 254 characters. Each is held to the same rule as a submitter's
        reply address: plain ASCII (no SMTPUTF8), a dot-atom part of at most
        64 characters before the @, and a domain of at least two hostname
        labels of at most 63 characters ending in a letters-only (or xn--)
        top level, so no quoted form, IP literal, bare host such as
        localhost, or control or invisible character. Entries are trimmed, blank ones dropped, and
        duplicates dropped case-insensitively keeping the first spelling.
        Anything else is a 400 naming targetEmails. The list is kept in the
        form's email destination (config.to), and the same rules apply to
        config.to of any email destination.
    AllowedOrigins:
      type: array
      maxItems: 20
      items: { type: string, maxLength: 255 }
      description: >-
        Sites permitted to POST to the form (CORS); an empty list allows any
        origin. Each entry is an origin: scheme://host[:port] with an http or
        https scheme. One trailing slash is stripped and the value is stored
        without it, because a browser's Origin header never has one. A path,
        query, fragment, userinfo or wildcard is rejected, and so is a second
        trailing slash. At most 20 entries of at most 255 characters. Entries
        are trimmed, blank ones dropped, and duplicates dropped
        case-insensitively keeping the first spelling. Matching is an exact,
        case-insensitive comparison. Anything else is a 400 naming
        allowedOrigins.
    RedirectUrl:
      type: string
      maxLength: 2048
      description: >-
        Where an HTML post is redirected when successBehavior is redirect:
        an absolute http:// or https:// URL, at most 2048 characters (trimmed),
        or "" to clear it. Any other scheme (javascript:, data:, ftp:) or a
        relative or scheme-relative URL is a 400 naming redirectUrl. null
        leaves the stored value unchanged.
    SuccessBehavior:
      type: string
      enum: [json, redirect]
      description: What a successful submission answers with. Anything else is a 400 naming successBehavior.
    SpamProvider:
      type: string
      enum: [none, turnstile]
      description: >-
        none skips the CAPTCHA check; turnstile verifies the Cloudflare
        Turnstile token. Anything else is a 400 naming spamProvider.
    Project:
      type: object
      required: [id, name, color, formCount, activeFormCount, status, created, updated]
      properties:
        id: { type: string }
        name: { type: string }
        color: { type: string }
        formCount: { type: integer, description: Forms in the project the caller can read }
        activeFormCount: { type: integer, description: "Of those, how many are switched on" }
        status:
          type: string
          enum: [active, paused, empty]
          description: >-
            empty with no forms, active while any form is on, paused when every
            form is off
        visibility:
          type: string
          description: private = owner only · org = readable by everyone in the organization
        ownerId: { type: string }
        created: { type: string, format: date-time }
        updated: { type: string, format: date-time }
    Form:
      type: object
      required:
        [id, projectId, name, endpointUrl, targetEmails, allowedOrigins,
         blockedSenders, successBehavior, honeypot, spamProvider, turnstile, contentFilter, aiFilter, aiContext,
         minSubmitSeconds, autoresponder, retentionDays, storeClientMeta, submissionCount,
         spamCount, active, created, updated]
      properties:
        id: { type: string, description: "6-char nanoid, not a UUID" }
        projectId: { type: string }
        name: { type: string }
        endpointUrl: { type: string }
        targetEmails:
          type: array
          items: { type: string }
          description: >-
            Derived, never stored on the form: the deduped union, in order
            (oldest destination first, then the order inside each), of the
            recipients of the form's enabled email destinations, deduped
            case-insensitively keeping the first spelling. [] when the form has
            none, and then no email is sent. Written through the validated
            TargetEmails rules. A destination saved before that validation
            existed may still hold an entry that is not one bare valid address
            of at most 254 characters: such an entry is left out of this list
            and is never sent mail.
        allowedOrigins:
          type: array
          items: { type: string }
          description: >-
            Written through the validated AllowedOrigins rules; a form saved
            before that validation existed may still hold an older value.
        blockedSenders:
          type: array
          description: Email addresses and domains whose submissions are kept as spam.
          items: { type: string }
        successBehavior:
          type: string
          description: >-
            json | redirect. Set through the validated request field; a form
            saved before that validation existed may still hold another value,
            which does not redirect.
        redirectUrl: { type: string, nullable: true }
        honeypot: { type: boolean }
        spamProvider: { type: string, description: none | turnstile }
        turnstile:
          type: object
          required: [available, siteKey, state, since]
          description: >-
            Turnstile for this form. available is false until Easerix has its
            Turnstile keys. state: off; waiting (opted in, no valid token from
            the form's site yet: a missing token is not held against a
            submission, but a token Cloudflare refuses is spam); or
            enforcing (since the first valid token: a submission without a
            valid token for this form and one of its allowed origins is spam).
          properties:
            available: { type: boolean }
            siteKey: { type: string, nullable: true, description: The widget's site key for the form's page (null when not available) }
            state: { type: string, enum: [off, waiting, enforcing] }
            since: { type: string, format: date-time, nullable: true, description: When enforcement started }
        contentFilter: { type: string, description: off | low | medium | high }
        aiFilter: { type: boolean }
        aiContext:
          type: string
          description: The owner's description of what they offer, read by the AI spam filter ("" = none).
        minSubmitSeconds:
          type: integer
          minimum: 0
          maximum: 60
          description: >-
            Minimum time to submit, in seconds (0 = off). A submission whose
            _elapsed field is below it is kept as spam.
        autoresponder:
          type: object
          required: [enabled, subject, body]
          properties:
            enabled: { type: boolean }
            subject: { type: string }
            body: { type: string }
        retentionDays:
          type: integer
          nullable: true
          description: >-
            Submissions older than this many days are deleted by an hourly
            sweep (recorded as submissions.expired in the audit log). null =
            keep forever.
        storeClientMeta:
          type: boolean
          description: Whether new submissions keep the IP address, User-Agent and referrer
        submissionCount: { type: integer, format: int64, description: "Submissions currently stored, spam included" }
        spamCount: { type: integer, format: int64 }
        active: { type: boolean }
        visibility:
          type: string
          description: private = owner only · org = readable by everyone in the organization
        ownerId: { type: string }
        created: { type: string, format: date-time }
        updated: { type: string, format: date-time }
    Submission:
      type: object
      required: [id, formId, data, isSpam, spamReason, reviewReason, held, ip, referrer, userAgent, created]
      properties:
        id: { type: string, format: uuid }
        formId: { type: string }
        data:
          type: object
          additionalProperties: { type: string }
          description: Ingest coerces every value to a string
        isSpam: { type: boolean }
        spamReason:
          type: string
          description: >-
            "" when clean; else e.g. "honeypot triggered", "submitted too fast",
            "failed CAPTCHA", comma-joined heuristics, or "AI: <reason>"
        reviewReason:
          type: string
          description: >-
            "" unless the AI filter leaned spam with confidence below 0.9: then
            the submission was delivered (isSpam false, owner notified) and
            this holds the model's confidence and reason, e.g. "not sure
            (0.60): AI: <reason>". For staff and debugging; the app shows only
            that the filter wasn't sure, never this text. A held submission
            (see held) also carries a reason here, e.g. "AI check unavailable".
        held:
          type: boolean
          description: >-
            true when the AI filter was on but could not check the submission
            (it errored, timed out, the AI budget was spent, or the shared
            daily AI budget could not be counted because Redis was down) and
            the server keeps such posts for the owner (AI_FAIL_MODE=hold, the
            default).
            Nothing was sent for it: no email, notification, autoresponse or
            destination. isSpam is false. Filing it as spam clears the hold.
        ip: { type: string }
        referrer: { type: string }
        userAgent: { type: string }
        created: { type: string, format: date-time }
    RecentSubmission:
      description: A submission with its form's name, for the dashboard's recent activity
      allOf:
        - $ref: "#/components/schemas/Submission"
        - type: object
          required: [formName]
          properties:
            formName: { type: string }
    InboxSubmission:
      description: A submission with the form it belongs to, for lists across forms
      allOf:
        - $ref: "#/components/schemas/Submission"
        - type: object
          required: [formName, projectId]
          properties:
            formName: { type: string }
            projectId: { type: string }
    Destination:
      type: object
      required: [id, type, config, enabled, created, updated]
      properties:
        id: { type: string }
        type: { type: string, description: email | webhook | slack | sheets | zapier | crm }
        config:
          type: object
          additionalProperties: true
          description: 'For email: {"to": ["a@b.com"]}'
        enabled: { type: boolean }
        connectionId:
          type: string
          format: uuid
          nullable: true
          description: The connection a destination of an app posts through. Present only while an app is on.
        created: { type: string, format: date-time }
        updated: { type: string, format: date-time }
    TurnstileDomain:
      type: object
      required: [host, verified, method, proof, createdAt]
      properties:
        host: { type: string }
        verified: { type: boolean }
        verifiedAt: { type: string, format: date-time, nullable: true }
        method: { type: string, description: 'dns | file | operator ("" until verified)' }
        proof:
          type: object
          required: [dnsName, dnsValue, fileUrl, fileBody]
          properties:
            dnsName: { type: string, description: TXT record name }
            dnsValue: { type: string, description: TXT record value }
            fileUrl: { type: string }
            fileBody: { type: string, description: The file's whole content }
        createdAt: { type: string, format: date-time }
    FieldBreakdown:
      type: object
      required: [field, groups, other]
      properties:
        field: { type: string }
        groups:
          type: array
          maxItems: 100
          items:
            type: object
            required: [value, count]
            properties:
              value: { type: string, description: 'The field value, or "(none)" when missing or blank' }
              count: { type: integer, format: int64 }
        other:
          type: integer
          format: int64
          description: Submissions whose value is past the top-100 cap
    SubmissionsOverview:
      type: object
      required: [view, tz, buckets]
      properties:
        view: { type: string, enum: [day, month, year] }
        tz: { type: string, description: The timezone the periods were cut in }
        buckets:
          type: array
          items: { $ref: "#/components/schemas/SubmissionsBucket" }
    SubmissionsBucket:
      type: object
      required: [date, submissions, spam]
      properties:
        date:
          type: string
          format: date
          description: First day of the period in the viewer's timezone
        submissions:
          type: integer
          format: int64
          description: Accepted submissions in the period (spam is not in here)
        spam:
          type: integer
          format: int64
          description: Submissions flagged as spam in the period
    SourceSummary:
      type: object
      required: [total, from, to, groups, heardAbout]
      properties:
        total:
          type: integer
          format: int64
          description: Non-spam submissions in the range
        from: { type: string, format: date-time, nullable: true }
        to: { type: string, format: date-time, nullable: true }
        groups:
          type: array
          minItems: 5
          maxItems: 5
          description: Every source group, in the order ai, search, social, direct, other
          items:
            type: object
            required: [group, count]
            properties:
              group: { type: string, enum: [ai, search, social, direct, other] }
              count: { type: integer, format: int64 }
        heardAbout:
          type: object
          required: [field, groups, other]
          properties:
            field: { type: string, enum: [heard_about] }
            groups:
              type: array
              maxItems: 20
              items:
                type: object
                required: [value, count]
                properties:
                  value: { type: string, description: 'The answer, or "(none)" when missing or blank' }
                  count: { type: integer, format: int64 }
            other:
              type: integer
              format: int64
              description: Submissions whose answer is past the top-20 cap
    DaySubmissions:
      type: object
      required: [date, submissions]
      properties:
        date: { type: string, description: "UTC day, YYYY-MM-DD; sparse — zero days omitted" }
        submissions: { type: integer }
    Error:
      type: object
      required: [error]
      properties:
        error: { type: string }
    IntegrationError:
      type: object
      required: [error]
      properties:
        error: { type: string, description: Fit to show a person }
        code: { type: string, description: A stable word to branch on }
    Delivery:
      type: object
      required: [id, destinationId, submissionId, status, attempts, maxAttempts, reason, runAt, created, updated, finished]
      properties:
        id: { type: string, format: uuid }
        destinationId: { type: string }
        submissionId: { type: string }
        status: { type: string, enum: [pending, running, succeeded, dead, cancelled] }
        attempts: { type: integer }
        maxAttempts: { type: integer }
        reason:
          type: string
          description: "The code the last try left, such as max_attempts:ratelimited. Empty when there is none."
        runAt: { type: string, format: date-time, description: When it is next due }
        created: { type: string, format: date-time }
        updated: { type: string, format: date-time }
        finished: { type: string, format: date-time, nullable: true }
  responses:
    ValidationError:
      description: >-
        Invalid or incomplete request body, or a value was rejected. For a
        rejected value the message names the field as it was sent (for
        example "allowedOrigins: ..."), and nothing in the request was applied.
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
          example:
            error: 'allowedOrigins: "https://example.com/app" must look like https://example.com (scheme, host and optional port, nothing else)'
    BadRequest:
      description: Invalid or incomplete request body
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    Unauthorized:
      description: >-
        Missing/invalid bearer token, or a token without org context
        ("token missing org context — refresh your session")
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    ToolDisabled:
      description: The forms tool is turned off for the caller's organization
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    Forbidden:
      description: >-
        Either the forms tool is turned off for the caller's organization, or
        the row is readable only because a teammate shared it with the
        organization and mutations stay with its owner ("this form is shared
        with you — only its owner can change it")
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    NotFound:
      description: Resource not found or not owned by the caller
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    ServerError:
      description: Internal error
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    TooManyRequests:
      description: >-
        Rate limit exceeded. The signed-in API allows each user a number of calls a minute,
        and the heaviest routes (export, replay, and the counts across every form) use more
        of that budget per call. Retry-After gives the number of seconds to wait before
        retrying.
      headers:
        Retry-After:
          schema: { type: integer }
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
