{
  "openapi": "3.1.0",
  "info": {
    "title": "GainTrace API",
    "version": "1.0.0",
    "description": "The GainTrace REST API (v1). Read your customer data and push product-usage events, metric events, and signals into GainTrace.\n\nAll endpoints are authenticated with a Bearer API key and scoped to a single workspace.\n\nEach API key can send 60 requests a minute. A `429` response includes a `Retry-After` header with the seconds to wait."
  },
  "servers": [
    {
      "url": "https://app.gaintrace.com/api/v1",
      "description": "Production"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/companies": {
      "get": {
        "operationId": "listCompanies",
        "summary": "List companies",
        "tags": [
          "Companies"
        ],
        "description": "Returns the workspace's Companies, most recently updated first. Money fields are integer minor units of `currency`. Renewal dates are `contractStartDate` and `contractEndDate`, and `autoRenew`.\n\nArchived Companies are left out unless you send `includeArchived=true`. A Company is archived when its source removed it. Each record has `archivedAt`, which is `null` for a live Company.\n\n**Scope:** `read:companies`",
        "parameters": [
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/offset"
          },
          {
            "name": "healthStatus",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "healthy",
                "at_risk",
                "churning"
              ]
            }
          },
          {
            "name": "segment",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "plan",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "search",
            "in": "query",
            "description": "Case-insensitive match on name or domain.",
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/includeArchived"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of Companies.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Company"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "post": {
        "operationId": "upsertCompany",
        "summary": "Create or update a company",
        "tags": [
          "Companies"
        ],
        "description": "Creates a Company, or updates the one that has the same `externalId` (upsert). `externalId` defaults to a slug of `name`.\n\n- A new Company counts against your Company limit (`402` when it is reached). Updating an existing one does not.\n- Creating a Company also fires the `company.created` webhook with `source` set to `api`, and starts any Flow that triggers on a new Company. Updating one fires `company.updated` with `changedFields`.\n- When an existing Company is updated and is linked to a connection with write-back turned on, the change is queued to sync to the source system.\n\n**Scope:** `write:companies`",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompanyUpsert"
              },
              "example": {
                "name": "Acme Inc",
                "externalId": "acme",
                "domain": "acme.com",
                "arr": 4800000,
                "currency": "USD",
                "contractEndDate": "2027-03-31T00:00:00.000Z",
                "autoRenew": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "An existing Company was updated.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Company"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Company created.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Company"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/signals": {
      "get": {
        "operationId": "listSignals",
        "summary": "List signals",
        "description": "Returns non-dismissed signals for the workspace, most recent first. Each item has `accountId` (the legacy record id) and `companyId` (the Company id).\n\n**Scope:** `read:signals`",
        "tags": [
          "Signals"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/offset"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of signals.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SignalListItem"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "post": {
        "operationId": "createSignal",
        "summary": "Create a signal",
        "description": "Records a signal against a Company in the workspace. Name the Company in `accountId` with its Company `id` or the legacy account id.\n\n- The `201` response returns the signal `id`, the legacy `accountId` and the `companyId`.\n- The `signal.created` webhook fires with `source` set to `api`.\n- Signals you create keep their own row. GainTrace's detection never merges them with detected signals, and they are never counted as GainTrace predictions.\n- Metadata can't use the reserved keys `originalType`, `goldenAccountId` or `golden_account_id`.\n\n**Scope:** `write:signals`",
        "tags": [
          "Signals"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SignalCreate"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Signal created.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "id",
                        "accountId",
                        "companyId"
                      ],
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "accountId": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "uuid",
                          "description": "The legacy account id the signal is attached to."
                        },
                        "companyId": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "format": "uuid",
                          "description": "The Company `id`."
                        }
                      }
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "b2c9e1a4-7d3f-4a5b-9c8e-1f2a3b4c5d6e",
                    "accountId": "e5f6a7b8-1c2d-4e3f-8a9b-0c1d2e3f4a5b",
                    "companyId": "a1f0c2d3-5e6f-4a7b-8c9d-0e1f2a3b4c5d"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/events": {
      "post": {
        "operationId": "ingestProductEvents",
        "summary": "Ingest product events",
        "tags": [
          "Ingest"
        ],
        "description": "Ingests a batch of product-usage events. The shape is Segment-compatible: the GainTrace Segment destination sends here with `source` set to `segment` and the Segment `messageId` as `source_event_id`. Events feed health, signals and activation.\n\n**Keys.** Use a secret key (`gt_live_`, scope `write:events`) from your backend. Use a publishable key (`gt_pub_`, scope `write:ingest`) from a browser. Publishable keys need a browser `Origin` header and are pinned to their allowed origins. The endpoint answers CORS preflight.\n\n**Limits.** 1 to 1000 events per request. Replays are safe: an event whose `(source, source_event_id)` was already stored is reported as `duplicate`. Events with `source` of `sdk`, `warehouse` or `segment` must carry a `source_event_id`.\n\n**Per-event results.** The response has one entry in `results` for each event you sent, in the same order, so you can retry only what failed. Events that fail validation are listed in `validation_errors` and do not stop the rest of the batch. If none of the events are valid, the response is `422`.\n\n**Plan limit.** When the monthly event limit is reached the request fails with `402`, unless pay-as-you-go is on. Overage is billed from the events actually stored, so duplicates and retries are not billed.\n\n**Scope:** `write:events` or `write:ingest`",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "events"
                ],
                "properties": {
                  "events": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 1000,
                    "items": {
                      "$ref": "#/components/schemas/ProductEvent"
                    }
                  }
                }
              },
              "example": {
                "events": [
                  {
                    "event_name": "report_exported",
                    "event_category": "feature_usage",
                    "source": "segment",
                    "source_event_id": "msg_01J9ZK3T",
                    "timestamp": "2026-10-14T09:12:43.000Z",
                    "user_id": "ana@acme.com",
                    "properties": {
                      "format": "pdf"
                    }
                  },
                  {
                    "event_name": "",
                    "event_category": "feature_usage",
                    "source": "segment",
                    "source_event_id": "msg_01J9ZK3U",
                    "timestamp": "2026-10-14T09:12:44.000Z"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The batch was processed. `201` is returned even when some events were duplicates or were rejected, so check `results`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "inserted": {
                          "type": "integer",
                          "description": "Events stored."
                        },
                        "duplicates": {
                          "type": "integer",
                          "description": "Events skipped because their `source_event_id` was already stored."
                        },
                        "linked": {
                          "type": "integer",
                          "description": "Events attached to a Company, either through `account_id` or by finding the Person in `user_id`."
                        },
                        "errors": {
                          "type": "integer",
                          "description": "Valid events that GainTrace could not store."
                        },
                        "results": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/ProductEventResult"
                          }
                        }
                      }
                    },
                    "validation_errors": {
                      "type": "array",
                      "description": "Present only when some events failed validation.",
                      "items": {
                        "$ref": "#/components/schemas/EventValidationError"
                      }
                    }
                  }
                },
                "example": {
                  "data": {
                    "inserted": 1,
                    "duplicates": 0,
                    "linked": 1,
                    "errors": 0,
                    "results": [
                      {
                        "status": "inserted"
                      },
                      {
                        "status": "rejected",
                        "reason": "event_name is required and must be a string"
                      }
                    ]
                  },
                  "validation_errors": [
                    {
                      "index": 1,
                      "error": "event_name is required and must be a string"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "description": "The `events` array is missing, empty or over 1000, or no event in it is valid. When no event is valid, the body also carries `validation_errors`.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Error"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "validation_errors": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/EventValidationError"
                          }
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "error": {
                    "code": "unprocessable_entity",
                    "message": "No valid events in request. See validation_errors for the per-event reasons.",
                    "doc_url": "https://docs.gaintrace.com/errors#unprocessable_entity"
                  },
                  "validation_errors": [
                    {
                      "index": 0,
                      "error": "source_event_id is required for source 'segment' (used for deduplication)"
                    }
                  ]
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/metric-events": {
      "post": {
        "operationId": "ingestMetricEvents",
        "summary": "Ingest metric events",
        "description": "Ingests a batch of typed metric events into the metrics engine (feeds daily snapshots that calc metrics evaluate). Idempotent on `(source, externalId)`; duplicates are skipped silently. Returns a per-event outcome.\n\n**Scope:** `write:events` · **1 to 500 events per request.**",
        "tags": [
          "Ingest"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MetricEventBatch"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Batch processed. See `outcomes` for per-event status.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "summary": {
                      "type": "object",
                      "properties": {
                        "received": {
                          "type": "integer"
                        },
                        "ingested": {
                          "type": "integer"
                        },
                        "duplicate": {
                          "type": "integer"
                        },
                        "rejected": {
                          "type": "integer"
                        }
                      }
                    },
                    "outcomes": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/MetricEventOutcome"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/companies/{id}": {
      "get": {
        "operationId": "getCompany",
        "summary": "Get a company",
        "tags": [
          "Companies"
        ],
        "description": "Fetch one Company by UUID, or by `ext:<externalId>`. An archived Company is still returned here, with `archivedAt` set.\n\n**Scope:** `read:companies`",
        "parameters": [
          {
            "$ref": "#/components/parameters/pathId"
          }
        ],
        "responses": {
          "200": {
            "description": "The Company.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Company"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "patch": {
        "operationId": "updateCompany",
        "summary": "Update a company",
        "tags": [
          "Companies"
        ],
        "description": "Updates the mutable fields of an existing Company, addressed by UUID or `ext:<externalId>`. Send at least one field. If the Company is linked to a connection with write-back turned on, the change is queued to sync to the source system. There is no delete endpoint for Companies.\n\n**Scope:** `write:companies`",
        "parameters": [
          {
            "$ref": "#/components/parameters/pathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompanyPatch"
              },
              "example": {
                "contractEndDate": "2027-06-30T00:00:00.000Z",
                "autoRenew": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated Company.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Company"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/signals/{id}": {
      "get": {
        "operationId": "getSignal",
        "summary": "Get a signal",
        "tags": [
          "Signals"
        ],
        "description": "Fetch one signal by id.\n\n**Scope:** `read:signals`",
        "parameters": [
          {
            "$ref": "#/components/parameters/pathId"
          }
        ],
        "responses": {
          "200": {
            "description": "The signal.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Signal"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "patch": {
        "operationId": "updateSignal",
        "summary": "Update a signal",
        "tags": [
          "Signals"
        ],
        "description": "Update a signal's title, description, severity, snooze, or metadata. Metadata can't use the reserved keys `originalType`, `goldenAccountId` or `golden_account_id` (`422`), and any reserved key already stored on the signal is kept.\n\n**Scope:** `write:signals`",
        "parameters": [
          {
            "$ref": "#/components/parameters/pathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SignalPatch"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated signal.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Signal"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "delete": {
        "operationId": "dismissSignal",
        "summary": "Dismiss a signal",
        "tags": [
          "Signals"
        ],
        "description": "Soft-deletes (dismisses) the signal.\n\n**Scope:** `write:signals`",
        "parameters": [
          {
            "$ref": "#/components/parameters/pathId"
          }
        ],
        "responses": {
          "204": {
            "description": "Dismissed."
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/signals/batch": {
      "post": {
        "operationId": "createSignalsBatch",
        "summary": "Create signals in bulk",
        "tags": [
          "Signals"
        ],
        "description": "Create up to 1000 signals. Partial success: each item reports its own outcome, and one bad item never fails the batch. Each item's `accountId` takes a Company `id` or the legacy account id. An id GainTrace can't find fails that item with a message that starts `Couldn't find the Company`. Each created signal fires `signal.created` with `source` set to `api`. Batches of more than 25 signals are delivered in paced batches instead of right away.\n\n**Scope:** `write:signals`",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "data"
                ],
                "properties": {
                  "data": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 1000,
                    "items": {
                      "$ref": "#/components/schemas/SignalCreate"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Per-item outcomes.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/BatchOutcome"
                      }
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "received": {
                          "type": "integer"
                        },
                        "succeeded": {
                          "type": "integer"
                        },
                        "failed": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/contacts": {
      "get": {
        "operationId": "listContacts",
        "summary": "List contacts",
        "tags": [
          "Contacts"
        ],
        "description": "The original path for `GET /people`. It returns the same records in the same shape, and takes the same `includeArchived` parameter. Archived records are left out by default.\n\n**Scope:** `read:contacts`",
        "parameters": [
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/offset"
          },
          {
            "name": "accountId",
            "in": "query",
            "description": "Only People at this Company.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "email",
            "in": "query",
            "description": "Exact match.",
            "schema": {
              "type": "string",
              "format": "email"
            }
          },
          {
            "$ref": "#/components/parameters/personExternalIdQuery"
          },
          {
            "$ref": "#/components/parameters/includeArchived"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of People.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Person"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "post": {
        "operationId": "createContact",
        "summary": "Create or upsert a contact",
        "tags": [
          "Contacts"
        ],
        "description": "The original path for `POST /people`. Same body, same rules, same responses.\n\n**Scope:** `write:contacts`",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PersonCreate"
              },
              "example": {
                "accountId": "a1f0c2d4-7b3e-4e21-8c55-0d9a6b1f2e33",
                "name": "Ana Ruiz",
                "email": "ana@acme.com"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated through `upsert`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Person"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Created.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Person"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "delete": {
        "operationId": "deleteContactByKey",
        "summary": "Delete a person everywhere by key",
        "tags": [
          "Contacts"
        ],
        "description": "Deletes a Person by your own key, for privacy-deletion requests. Pass `externalId` or `email`. GainTrace removes the Person's records at **every** Company, archived ones included, and fires `contact.deleted` for each. It is idempotent: if nobody matches, the response is still `204`.\n\nThis is the same operation as `DELETE /people`. Their survey data is erased too: answers to your surveys are anonymized (name, email and free text removed, scores and choices kept), imported answers are deleted, and their short personal survey links are deleted.\n\n**Scope:** `write:contacts`",
        "parameters": [
          {
            "$ref": "#/components/parameters/personExternalIdQuery"
          },
          {
            "name": "email",
            "in": "query",
            "description": "Used when `externalId` is absent.",
            "schema": {
              "type": "string",
              "format": "email"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted, or nobody matched."
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/contacts/{id}": {
      "get": {
        "operationId": "getContact",
        "summary": "Get a contact",
        "tags": [
          "Contacts"
        ],
        "description": "The original path for `GET /people/{id}`. An archived record is still returned, with `archivedAt` set.\n\n**Scope:** `read:contacts`",
        "parameters": [
          {
            "$ref": "#/components/parameters/pathId"
          }
        ],
        "responses": {
          "200": {
            "description": "The Person.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Person"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "patch": {
        "operationId": "updateContact",
        "summary": "Update a contact",
        "tags": [
          "Contacts"
        ],
        "description": "The original path for `PATCH /people/{id}`. Same body, same rules, including how an `email` change moves the whole Person and the `409` when another Person already uses the address.\n\n**Scope:** `write:contacts`",
        "parameters": [
          {
            "$ref": "#/components/parameters/pathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PersonPatch"
              },
              "example": {
                "phone": "+1 415 555 0134"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated Person.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Person"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "delete": {
        "operationId": "deleteContact",
        "summary": "Delete a contact",
        "tags": [
          "Contacts"
        ],
        "description": "The original path for `DELETE /people/{id}`. Deletes this one record only. Their survey data is erased too, except where they belong to another Company: answers to your surveys are anonymized (name, email and free text removed, scores and choices kept), imported answers are deleted, and their short personal survey links are deleted. Answers that carry only an email address are kept while another record in the workspace still has that email.\n\n**Scope:** `write:contacts`",
        "parameters": [
          {
            "$ref": "#/components/parameters/pathId"
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/webhooks": {
      "get": {
        "operationId": "listWebhooks",
        "summary": "List webhooks",
        "tags": [
          "Webhooks"
        ],
        "description": "List the workspace's webhook subscriptions.\n\n**Scope:** `read:webhooks`",
        "parameters": [
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/offset"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of webhooks.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Webhook"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "post": {
        "operationId": "createWebhook",
        "summary": "Create a webhook",
        "tags": [
          "Webhooks"
        ],
        "description": "Register a webhook subscription. The signing `secret` is returned only in this response.\n\nThe key needs `write:webhooks` and the read scope of every event you subscribe to: `read:companies` for `company.*`, `read:contacts` for `contact.*`, `read:signals` for `signal.created`, and `read:surveys` for `survey.*` and `survey_response.*`. `member.*` events need no read scope. Subscribing to `*` needs all four read scopes. A key without one of them gets `403` with the message `This key can't subscribe to <event>. Add the <scope> scope.`\n\n**Scope:** `write:webhooks`",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookCreate"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Webhook created (includes the one-time secret).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/WebhookCreated"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/webhooks/{id}": {
      "get": {
        "operationId": "getWebhook",
        "summary": "Get a webhook",
        "tags": [
          "Webhooks"
        ],
        "description": "Fetch one webhook.\n\n**Scope:** `read:webhooks`",
        "parameters": [
          {
            "$ref": "#/components/parameters/pathId"
          }
        ],
        "responses": {
          "200": {
            "description": "The webhook.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Webhook"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "patch": {
        "operationId": "updateWebhook",
        "summary": "Update a webhook",
        "tags": [
          "Webhooks"
        ],
        "description": "Update url, events, headers, description, or active state. Changing `events` needs the same read scopes as creating a subscription: `read:companies` for `company.*`, `read:contacts` for `contact.*`, `read:signals` for `signal.created`, and `read:surveys` for `survey.*` and `survey_response.*`. `*` needs all four. A key without one gets `403`. Setting `active` to `true` clears the failure count and the auto-disable.\n\n**Scope:** `write:webhooks`",
        "parameters": [
          {
            "$ref": "#/components/parameters/pathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookPatch"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated webhook.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Webhook"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "delete": {
        "operationId": "deleteWebhook",
        "summary": "Delete a webhook",
        "tags": [
          "Webhooks"
        ],
        "description": "Delete a webhook and its delivery history.\n\n**Scope:** `write:webhooks`",
        "parameters": [
          {
            "$ref": "#/components/parameters/pathId"
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/webhooks/{id}/test": {
      "post": {
        "operationId": "testWebhook",
        "summary": "Send a test event",
        "tags": [
          "Webhooks"
        ],
        "description": "Send a signed `ping` to the endpoint now and return the result.\n\n**Scope:** `write:webhooks`",
        "parameters": [
          {
            "$ref": "#/components/parameters/pathId"
          }
        ],
        "responses": {
          "200": {
            "description": "Delivery result.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "deliveryId": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "status": {
                          "type": "string",
                          "enum": [
                            "pending",
                            "delivered",
                            "failed"
                          ]
                        },
                        "responseStatus": {
                          "type": [
                            "integer",
                            "null"
                          ]
                        },
                        "error": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/people": {
      "get": {
        "operationId": "listPeople",
        "summary": "List people",
        "tags": [
          "People"
        ],
        "description": "Returns People, most recently updated first. A Person who belongs to several Companies appears once for each Company. Filter by Company, email or your own id.\n\nArchived records are left out unless you send `includeArchived=true`. A record is archived when the Person left that Company or its source removed them. Each record has `archivedAt`, which is `null` for a live one.\n\n**Scope:** `read:contacts`",
        "parameters": [
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/offset"
          },
          {
            "name": "accountId",
            "in": "query",
            "description": "Only People at this Company.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "email",
            "in": "query",
            "description": "Exact match.",
            "schema": {
              "type": "string",
              "format": "email"
            }
          },
          {
            "$ref": "#/components/parameters/personExternalIdQuery"
          },
          {
            "$ref": "#/components/parameters/includeArchived"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of People.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Person"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "4c1d3b0a-5f0e-4b6e-9a53-1f2d7c8e9a10",
                      "accountId": "a1f0c2d4-7b3e-4e21-8c55-0d9a6b1f2e33",
                      "name": "Ana Ruiz",
                      "email": "ana@acme.com",
                      "externalId": "user_8812",
                      "phone": null,
                      "role": "VP Operations",
                      "contactRole": "decision_maker",
                      "isChampion": true,
                      "traits": {},
                      "linkedinUrl": null,
                      "avatarUrl": null,
                      "lastSeenAt": "2026-10-12T08:41:00.000Z",
                      "engagementScore": 72,
                      "createdAt": "2026-08-02T10:15:00.000Z",
                      "updatedAt": "2026-10-12T08:41:00.000Z"
                    }
                  ],
                  "meta": {
                    "limit": 50,
                    "offset": 0,
                    "count": 1
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "post": {
        "operationId": "createPerson",
        "summary": "Create or upsert a person",
        "tags": [
          "People"
        ],
        "description": "Adds a Person to a Company.\n\n- Name the Company with `accountId` or `accountExternalId`.\n- A Person who already exists at a **different** Company gets a new record at this one. Matching is by `externalId`, then `email`. That does not count against your People limit.\n- A Person who already exists at **this** Company fails with `409`, unless you send `upsert: true`. Then the record is updated and returned with `200`, and `traits` are merged.\n- A new Person counts against your People limit (`402` when it is reached).\n- With `accountExternalId`, an unknown Company is created for you and counts against your Company limit. It fires the `company.created` webhook with `source` set to `api`. It does not start Company-created Flows.\n- A new Person fires `contact.created`, and an upsert that updates a Person fires `contact.updated`, both with `source` set to `api`.\n\nThis is the same operation as `POST /contacts`.\n\n**Scope:** `write:contacts`",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PersonCreate"
              },
              "example": {
                "accountExternalId": "acme",
                "accountName": "Acme Inc",
                "name": "Ana Ruiz",
                "email": "ana@acme.com",
                "externalId": "user_8812",
                "contactRole": "decision_maker",
                "upsert": true,
                "traits": {
                  "plan_tier": "growth"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The Person already existed at this Company and `upsert` was true. The updated record.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Person"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Person created.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Person"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "delete": {
        "operationId": "deletePersonByKey",
        "summary": "Delete a person everywhere",
        "tags": [
          "People"
        ],
        "description": "Deletes a Person by your own key, for privacy-deletion requests. Pass `externalId` or `email`; `externalId` is tried first. GainTrace removes the Person's records at **every** Company, archived ones included, and fires `contact.deleted` for each, with `source` set to `api`. It is idempotent: if nobody matches, the response is still `204`. Send neither parameter and the call returns `422`.\n\nThis is the same operation as `DELETE /contacts`. To remove a single record, use `DELETE /people/{id}`. Their survey data is erased too: answers to your surveys are anonymized (name, email and free text removed, scores and choices kept), imported answers are deleted, and their short personal survey links are deleted.\n\n**Scope:** `write:contacts`",
        "parameters": [
          {
            "$ref": "#/components/parameters/personExternalIdQuery"
          },
          {
            "name": "email",
            "in": "query",
            "description": "Used when `externalId` is absent.",
            "schema": {
              "type": "string",
              "format": "email"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted, or nobody matched."
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/people/{id}": {
      "get": {
        "operationId": "getPerson",
        "summary": "Get a person",
        "tags": [
          "People"
        ],
        "description": "Fetch one Person at one Company by `id`. An archived record is still returned here, with `archivedAt` set.\n\n**Scope:** `read:contacts`",
        "parameters": [
          {
            "$ref": "#/components/parameters/pathId"
          }
        ],
        "responses": {
          "200": {
            "description": "The Person.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Person"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "patch": {
        "operationId": "updatePerson",
        "summary": "Update a person",
        "tags": [
          "People"
        ],
        "description": "Updates the mutable fields of one Person record. Send at least one field. If the Company is linked to a connection with write-back turned on, the change is queued to sync to the source system.\n\n**Changing `email`.** An email change moves the whole Person, not one record. Every live record of this Person, at every Company, takes the new address, and each fires `contact.updated` with `changedFields` set to `[\"email\"]`. The call returns `409` `conflict` when a different Person in the workspace already uses the address, including a Person whose records are all archived. Addresses are compared without regard to case or surrounding spaces. Changing only the letter case, or sending `email: null`, stays on this one record.\n\n**Scope:** `write:contacts`",
        "parameters": [
          {
            "$ref": "#/components/parameters/pathId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PersonPatch"
              },
              "example": {
                "role": "Chief Operating Officer",
                "isChampion": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated Person.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Person"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "delete": {
        "operationId": "deletePerson",
        "summary": "Delete a person record",
        "tags": [
          "People"
        ],
        "description": "Permanently deletes this one record. If the same human is also at other Companies, those records stay. To remove a human everywhere, use `DELETE /people` with `externalId` or `email`. Fires `contact.deleted`. Their survey data is erased too, except where they belong to another Company: answers to your surveys are anonymized (name, email and free text removed, scores and choices kept), imported answers are deleted, and their short personal survey links are deleted. Answers that carry only an email address are kept while another record in the workspace still has that email.\n\n**Scope:** `write:contacts`",
        "parameters": [
          {
            "$ref": "#/components/parameters/pathId"
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/nps-responses": {
      "get": {
        "operationId": "listNpsResponses",
        "summary": "List NPS responses",
        "tags": [
          "NPS responses"
        ],
        "description": "Returns NPS answers from every source, newest first: answers collected by GainTrace surveys and answers imported through `POST /nps-responses`. Requires a secret key (`gt_live_`); a publishable key gets `403`.\n\n**Scope:** `read:surveys`",
        "parameters": [
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/offset"
          },
          {
            "name": "provider",
            "in": "query",
            "description": "Only answers imported from this provider.",
            "schema": {
              "type": "string",
              "maxLength": 64,
              "pattern": "^[a-zA-Z0-9_-]+$"
            }
          },
          {
            "name": "accountId",
            "in": "query",
            "description": "Only answers from this Company.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "contactId",
            "in": "query",
            "description": "Only answers from this Person.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "from",
            "in": "query",
            "description": "Only answers on or after this time. ISO 8601 with a UTC offset.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "Only answers on or before this time. ISO 8601 with a UTC offset.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of NPS responses.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/NpsResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "0d5e7a31-92c4-4f0b-8a16-3b7d2c9e4f55",
                      "provider": "retently",
                      "externalId": "resp_4471",
                      "accountId": "a1f0c2d4-7b3e-4e21-8c55-0d9a6b1f2e33",
                      "contactId": "4c1d3b0a-5f0e-4b6e-9a53-1f2d7c8e9a10",
                      "email": "ana@acme.com",
                      "score": 9,
                      "category": "promoter",
                      "comment": "Support is quick.",
                      "campaignId": "q3-relationship",
                      "source": "api:retently",
                      "respondedAt": "2026-10-01T14:20:00.000Z"
                    }
                  ],
                  "meta": {
                    "limit": 50,
                    "offset": 0,
                    "count": 1
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "post": {
        "operationId": "importNpsResponse",
        "summary": "Import an NPS response",
        "tags": [
          "NPS responses"
        ],
        "description": "Imports one NPS answer from another survey tool. Send one answer per request. Requires a secret key (`gt_live_`); a publishable key gets `403`.\n\n- **Idempotent.** `provider` and `externalId` together identify the answer. Sending the same pair again updates the stored answer instead of adding a second one. The response is `200` either way.\n- **Who answered.** Send `contactId`, or send both `accountId` and `email`. With `contactId`, the Company and email come from that Person. With `accountId` and `email`, GainTrace tries to match a Person at that Company and leaves `contactId` null when it cannot.\n- **Category.** GainTrace sets `category` from `score`: 9-10 promoter, 7-8 passive, 0-6 detractor.\n- **Stored with your other NPS.** The answer is saved with `source` set to `api:<provider>`, next to answers collected by GainTrace surveys. A `comment` is read for themes.\n- **Webhook.** A new answer fires `survey_response.created`. A repeat of an answer you already imported fires `survey_response.updated`. Imported answers have `surveyId: null` and `channel: import`.\n- **No outreach.** The import does not send survey emails or follow-up messages.\n\n**Scope:** `write:surveys`",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NpsResponseImport"
              },
              "example": {
                "provider": "retently",
                "externalId": "resp_4471",
                "score": 9,
                "respondedAt": "2026-10-01T19:50:00+05:30",
                "accountId": "a1f0c2d4-7b3e-4e21-8c55-0d9a6b1f2e33",
                "email": "ana@acme.com",
                "comment": "Support is quick.",
                "campaignId": "q3-relationship"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The stored answer, whether it was new or an update.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/NpsResponse"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "0d5e7a31-92c4-4f0b-8a16-3b7d2c9e4f55",
                    "provider": "retently",
                    "externalId": "resp_4471",
                    "accountId": "a1f0c2d4-7b3e-4e21-8c55-0d9a6b1f2e33",
                    "contactId": "4c1d3b0a-5f0e-4b6e-9a53-1f2d7c8e9a10",
                    "email": "ana@acme.com",
                    "score": 9,
                    "category": "promoter",
                    "comment": "Support is quick.",
                    "campaignId": "q3-relationship",
                    "source": "api:retently",
                    "respondedAt": "2026-10-01T14:20:00.000Z"
                  }
                }
              }
            }
          },
          "400": {
            "description": "The `contactId` does not match the `accountId` or `email` you sent, or the request was not valid JSON.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/survey-templates": {
      "get": {
        "operationId": "listSurveyTemplates",
        "summary": "List survey templates",
        "description": "List the survey templates the workspace saved, each with its full survey definition. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `read:surveys`",
        "tags": [
          "Surveys"
        ],
        "responses": {
          "200": {
            "description": "The templates.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "A publishable key was used."
          }
        }
      },
      "post": {
        "operationId": "createSurveyTemplate",
        "summary": "Save a survey template",
        "description": "Save a template from an existing survey (`surveyId`) or from a survey definition (`input`). A name another template uses returns `422`. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `write:surveys`",
        "tags": [
          "Surveys"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 255
                  },
                  "folder": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80,
                    "nullable": true
                  },
                  "surveyId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Save this survey as a template. Send this or `input`, not both."
                  },
                  "input": {
                    "$ref": "#/components/schemas/SurveyInput"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The saved template.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "A publishable key was used."
          },
          "422": {
            "description": "The name is already used, or the survey definition is invalid."
          }
        }
      }
    },
    "/surveys": {
      "get": {
        "operationId": "listSurveys",
        "summary": "List surveys",
        "description": "List the workspace's surveys, newest first. There are no filters. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `read:surveys`",
        "tags": [
          "Surveys"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/offset"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of surveys.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "meta"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Survey"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "7b6f2c1e-4d3a-4b5c-9e8f-1a2b3c4d5e6f",
                      "name": "Relationship NPS",
                      "measure": "nps",
                      "status": "draft",
                      "questions": [
                        {
                          "text": "How likely are you to recommend us to a colleague?",
                          "type": "rating",
                          "required": true
                        },
                        {
                          "text": "What is the main reason for your score?",
                          "type": "text",
                          "required": false
                        }
                      ],
                      "settings": {
                        "thankYouTitle": "Thank you",
                        "reminders": {
                          "afterDays": 3,
                          "max": 1
                        }
                      },
                      "cooldownDays": 90,
                      "createdAt": "2026-10-14T09:00:00.000Z",
                      "updatedAt": "2026-10-14T09:00:00.000Z"
                    }
                  ],
                  "meta": {
                    "limit": 50,
                    "offset": 0,
                    "count": 1
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "post": {
        "operationId": "createSurvey",
        "summary": "Create a survey",
        "description": "Create a survey as a draft. It uses the same contract and validation as the survey designer. Launching is a separate step: call `POST /surveys/{id}/status`. The response is `422` when a value fails validation, such as an NPS scale that is not 0-10. A body that is not valid JSON is `400`. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `write:surveys`",
        "tags": [
          "Surveys"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SurveyInput"
              },
              "example": {
                "name": "Relationship NPS",
                "type": "nps",
                "questions": [
                  {
                    "text": "How likely are you to recommend us to a colleague?",
                    "type": "rating",
                    "required": true
                  },
                  {
                    "text": "What is the main reason for your score?",
                    "type": "text",
                    "required": false
                  }
                ],
                "settings": {
                  "reminders": {
                    "afterDays": 3,
                    "max": 1
                  }
                },
                "cooldownDays": 90
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Survey created as a draft.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Survey"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "7b6f2c1e-4d3a-4b5c-9e8f-1a2b3c4d5e6f",
                    "name": "Relationship NPS",
                    "measure": "nps",
                    "status": "draft",
                    "questions": [
                      {
                        "text": "How likely are you to recommend us to a colleague?",
                        "type": "rating",
                        "required": true
                      },
                      {
                        "text": "What is the main reason for your score?",
                        "type": "text",
                        "required": false
                      }
                    ],
                    "settings": {
                      "reminders": {
                        "afterDays": 3,
                        "max": 1
                      }
                    },
                    "cooldownDays": 90,
                    "createdAt": "2026-10-14T09:00:00.000Z",
                    "updatedAt": "2026-10-14T09:00:00.000Z"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/surveys/{id}": {
      "get": {
        "operationId": "getSurvey",
        "summary": "Get a survey",
        "description": "Read one survey definition and its status. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `read:surveys`",
        "tags": [
          "Surveys"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/surveyId"
          }
        ],
        "responses": {
          "200": {
            "description": "The survey.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Survey"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "7b6f2c1e-4d3a-4b5c-9e8f-1a2b3c4d5e6f",
                    "name": "Relationship NPS",
                    "measure": "nps",
                    "status": "draft",
                    "questions": [
                      {
                        "text": "How likely are you to recommend us to a colleague?",
                        "type": "rating",
                        "required": true
                      },
                      {
                        "text": "What is the main reason for your score?",
                        "type": "text",
                        "required": false
                      }
                    ],
                    "settings": {
                      "thankYouTitle": "Thank you",
                      "reminders": {
                        "afterDays": 3,
                        "max": 1
                      }
                    },
                    "cooldownDays": 90,
                    "createdAt": "2026-10-14T09:00:00.000Z",
                    "updatedAt": "2026-10-14T09:00:00.000Z"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "patch": {
        "operationId": "updateSurvey",
        "summary": "Update a survey",
        "description": "Edit a survey. Send any subset of the survey contract. Once a survey is `active` or has any responses, changing `type`, `questions` or `settings.anonymous` is refused with `400`, because it would change what past answers mean. Duplicate the survey in the app to change those. Name, cooldown and the other settings stay editable. The merged result is validated as a whole, so a patch can fail on a rule that involves a key you did not send. Rules that compare several fields (a required first question, the NPS 0-10 and CSAT/CES scale ranges, promotional copy, `showWhen` rules) are checked after the merge, and a failure returns `400` `bad_request` with a generic message and no field detail. A value that fails its own field schema returns `422`. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `write:surveys`",
        "tags": [
          "Surveys"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/surveyId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SurveyPatch"
              },
              "example": {
                "name": "Relationship NPS, Q4",
                "cooldownDays": 60
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated survey.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Survey"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "7b6f2c1e-4d3a-4b5c-9e8f-1a2b3c4d5e6f",
                    "name": "Relationship NPS, Q4",
                    "measure": "nps",
                    "status": "draft",
                    "questions": [
                      {
                        "text": "How likely are you to recommend us to a colleague?",
                        "type": "rating",
                        "required": true
                      },
                      {
                        "text": "What is the main reason for your score?",
                        "type": "text",
                        "required": false
                      }
                    ],
                    "settings": {
                      "thankYouTitle": "Thank you",
                      "reminders": {
                        "afterDays": 3,
                        "max": 1
                      }
                    },
                    "cooldownDays": 60,
                    "createdAt": "2026-10-14T09:00:00.000Z",
                    "updatedAt": "2026-10-14T09:00:00.000Z"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/surveys/{id}/status": {
      "post": {
        "operationId": "setSurveyStatus",
        "summary": "Change survey status",
        "description": "Launch a draft, close a survey, or reopen a closed one. Launching validates the survey contract again. A launched survey can't return to draft, so only `active` and `closed` are accepted. Moving to `active` or `closed` fires the `survey.launched` or `survey.closed` webhook. Sending the status the survey already has changes nothing and fires nothing. If the launch re-validation fails a cross-field rule, the call returns `400` `bad_request` with a generic message and no field detail. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `write:surveys`",
        "tags": [
          "Surveys"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/surveyId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SurveyStatusChange"
              },
              "example": {
                "status": "active"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The survey with its new status.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Survey"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "7b6f2c1e-4d3a-4b5c-9e8f-1a2b3c4d5e6f",
                    "name": "Relationship NPS",
                    "measure": "nps",
                    "status": "active",
                    "questions": [
                      {
                        "text": "How likely are you to recommend us to a colleague?",
                        "type": "rating",
                        "required": true
                      },
                      {
                        "text": "What is the main reason for your score?",
                        "type": "text",
                        "required": false
                      }
                    ],
                    "settings": {
                      "thankYouTitle": "Thank you",
                      "reminders": {
                        "afterDays": 3,
                        "max": 1
                      }
                    },
                    "cooldownDays": 90,
                    "createdAt": "2026-10-14T09:00:00.000Z",
                    "updatedAt": "2026-10-14T09:00:00.000Z"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/surveys/{id}/invitations": {
      "post": {
        "operationId": "requestSurveyInvitations",
        "summary": "Request survey invitations",
        "description": "Request email invitations for up to 100 people (`personIds`), or for everyone a saved segment (`segmentId`) or a set of Company and People rules (`audience`) matches, up to 1,000 people. The survey must be `active`.\n\n**Send or approve.** Workspaces send by default: each invitation is released to send right away, or at the survey's next send window. A workspace can switch to approval, where invitations wait in Triage until a teammate approves them, and approvals expire after 14 days. The result's `mode` says which applied. Invitations sent by an API key follow the workspace setting.\n\n**Who is skipped.** People are skipped, not failed, when an invitation for their email already waits or is about to send, when they are inside the survey's `cooldownDays`, or when the workspace frequency rule applies. The response counts them but does not name them. To preview who would be invited, use the `gt_survey_request_invitations` MCP tool, which defaults to a dry run.\n\n**Errors.** With `personIds`, every person must be active, have an email address and belong to a Company, or the whole request returns `400` and nothing is queued. A `segmentId` that is missing or archived returns `404`. An audience that matches more than 1,000 people returns `400`: narrow the rules or split them into segments. An `audience` with no rules, or a body with more than one of the three keys, returns `422`. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `write:surveys`",
        "tags": [
          "Surveys"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/surveyId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SurveyInvitationRequest"
              },
              "examples": {
                "people": {
                  "summary": "Specific people",
                  "value": {
                    "personIds": [
                      "c3d24e5f-6a7b-4c8d-9e0f-1a2b3c4d5e6f"
                    ]
                  }
                },
                "segment": {
                  "summary": "A saved segment",
                  "value": {
                    "segmentId": "3f6a9c1e-8b2d-4c7a-9e5f-0a1b2c3d4e5f"
                  }
                },
                "audience": {
                  "summary": "Rules",
                  "value": {
                    "audience": {
                      "company": {
                        "logic": "and",
                        "rules": [
                          {
                            "field": "segment",
                            "operator": "eq",
                            "value": "enterprise"
                          }
                        ]
                      },
                      "person": {
                        "logic": "and",
                        "rules": [
                          {
                            "field": "contactRole",
                            "operator": "is_any_of",
                            "value": [
                              "decision_maker",
                              "champion"
                            ]
                          }
                        ]
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Invitations accepted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SurveyInvitationResult"
                    }
                  }
                },
                "example": {
                  "data": {
                    "mode": "send",
                    "queued": 0,
                    "sending": 38,
                    "skipped": 4,
                    "batchId": "e4b1c2d3-6f7a-4b8c-9d0e-1f2a3b4c5d6e",
                    "sendAt": null,
                    "matched": 42
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/surveys/{id}/responses": {
      "post": {
        "operationId": "recordSurveyResponse",
        "summary": "Record a survey response",
        "description": "Record an answer that your own app, bot or form collected from a known person. It runs the same validation, attribution and follow-through as an emailed survey: the response appears in the inbox, fires signals and Flows, and sends the `survey_response.created` webhook with `channel` set to `api`. Send `subject` to tie the answer to a deal, ticket, plan or custom record. The survey must be `active`; otherwise the call returns `404`. Re-sending the same `externalId` for the same survey is safe: the first response is returned with `duplicate: true` and `200`, and the new body is ignored. The first call returns `201`. On an anonymous survey the response is stored without a person or company. Answers that don't fit the survey's questions, and a `subject` GainTrace can't link, return `422`. A body that fails its own field schema also returns `422`. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `write:surveys`",
        "tags": [
          "Surveys"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/surveyId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SurveyResponseCreate"
              },
              "example": {
                "personId": "c3d24e5f-6a7b-4c8d-9e0f-1a2b3c4d5e6f",
                "externalId": "ticket-48213-csat",
                "score": 5,
                "answers": {
                  "q1": "Quick and helpful."
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Response recorded.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SurveyResponseRecorded"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "0d5e8a9b-1c2d-4e3f-8a4b-5c6d7e8f9a0b",
                    "duplicate": false
                  }
                }
              }
            }
          },
          "200": {
            "description": "This `externalId` was already recorded. The first response is returned.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SurveyResponseRecorded"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "0d5e8a9b-1c2d-4e3f-8a4b-5c6d7e8f9a0b",
                    "duplicate": true
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/surveys/{id}/session": {
      "post": {
        "operationId": "createSurveySession",
        "summary": "Create an in-app survey session",
        "description": "Decide whether to show an in-app survey to a signed-in person, and mint the signed embed URL if so. Call it from your backend, never from a browser: a request that carries an `Origin` header is refused with `403`, and cross-origin preflight requests are refused too. (Browser code uses a signed identity token with the in-app SDK instead. See the in-app SDK guide.) It returns `200` for both outcomes. When the person qualifies you get `eligible: true`, an `embedUrl` that is valid for one hour, a `sessionId` and the configured `delayMs`. Otherwise you get `eligible: false` and a `reason`: `disabled` (survey not active or in-app collection off), `cooldown`, `recently_dismissed`, `not_sampled`, `snoozed`, `already_seen`, `minimum_age`, `minimum_sessions`, `display_limit`, or, when the survey has targeting, `page_not_targeted`, `not_targeted` or `awaiting_trigger`. A survey with page rules needs `context.url`; without it the reason is `page_not_targeted`. A person who passes the earlier checks gets one recorded session per UTC day, and those count toward `minSessions`. `parentOrigin` must be listed in `settings.inApp.allowedOrigins`, or the call returns `403`. The person must exist, be active and belong to `accountId`, or the call returns `404`. Send `subject` to tie the survey to a deal, ticket, plan or custom record; a record GainTrace can't link returns `422`. Any invalid or malformed body, or an invalid survey id, returns `422`. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `write:surveys`",
        "tags": [
          "Surveys"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/surveyId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SurveySessionCreate"
              },
              "example": {
                "contactId": "c3d24e5f-6a7b-4c8d-9e0f-1a2b3c4d5e6f",
                "accountId": "a1f0c2d3-5e6f-4a7b-8c9d-0e1f2a3b4c5d",
                "parentOrigin": "https://app.example.com",
                "mode": "survey"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The session decision.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SurveySession"
                    }
                  }
                },
                "examples": {
                  "eligible": {
                    "summary": "Eligible",
                    "value": {
                      "data": {
                        "eligible": true,
                        "embedUrl": "https://app.gaintrace.com/survey/embed/7b6f2c1e-4d3a-4b5c-9e8f-1a2b3c4d5e6f?t=eyJ...&mode=survey&position=bottom",
                        "sessionId": "b2c3d4e5-7a8b-4c9d-8e0f-2a3b4c5d6e7f",
                        "delayMs": 3000
                      }
                    }
                  },
                  "ineligible": {
                    "summary": "Not eligible",
                    "value": {
                      "data": {
                        "eligible": false,
                        "reason": "cooldown"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/surveys/frequency-rule": {
      "get": {
        "operationId": "getSurveyFrequencyRule",
        "summary": "Get the survey frequency rule",
        "description": "Read the workspace-wide rule that limits how often one person is surveyed, across every survey and channel. A workspace that never changed it gets the defaults, 30 and 7 days. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `read:surveys`",
        "tags": [
          "Surveys"
        ],
        "responses": {
          "200": {
            "description": "The frequency rule.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SurveyFrequencyRule"
                    }
                  }
                },
                "example": {
                  "data": {
                    "recontactDays": 30,
                    "dismissedRecontactDays": 7,
                    "companyLimit": null
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "put": {
        "operationId": "setSurveyFrequencyRule",
        "summary": "Set the survey frequency rule",
        "description": "Replace the workspace's frequency rule. Send both day fields. `0` turns a person rule off. `companyLimit` is optional: send `null` to turn the Company limit off, or leave it out to keep it. The rule applies to email invitations and in-app sessions. It does not block responses you record through the API. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `write:surveys`",
        "tags": [
          "Surveys"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SurveyFrequencyRule"
              },
              "example": {
                "recontactDays": 45,
                "dismissedRecontactDays": 14
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The saved rule.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SurveyFrequencyRule"
                    }
                  }
                },
                "example": {
                  "data": {
                    "recontactDays": 45,
                    "dismissedRecontactDays": 14
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/surveys/case-rules": {
      "get": {
        "operationId": "getSurveyCaseRules",
        "summary": "Get the survey response rules",
        "description": "Read how new responses are owned and how long they can wait. A workspace that never changed the rules gets 48 hours and `negative`. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `read:surveys`",
        "tags": [
          "Surveys"
        ],
        "responses": {
          "200": {
            "description": "The response rules.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SurveyCaseRules"
                    }
                  }
                },
                "example": {
                  "data": {
                    "slaHours": 48,
                    "autoAssign": "negative"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "put": {
        "operationId": "setSurveyCaseRules",
        "summary": "Set the survey response rules",
        "description": "Replace the workspace's response rules. Send both fields. It decides who owns new responses and when an open response is overdue. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `write:surveys`",
        "tags": [
          "Surveys"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SurveyCaseRules"
              },
              "example": {
                "slaHours": 24,
                "autoAssign": "all"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The saved rules.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SurveyCaseRules"
                    }
                  }
                },
                "example": {
                  "data": {
                    "slaHours": 24,
                    "autoAssign": "all"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/survey-responses": {
      "get": {
        "operationId": "listSurveyResponses",
        "summary": "List survey responses",
        "description": "List responses from every GainTrace survey (NPS, CSAT, CES and custom), newest first, across the email, in-app and API channels, plus older answers collected before public links, QR codes and kiosks were removed. Responses imported through the NPS import endpoint are not included. Filters combine with AND. An unknown query parameter returns `422`. Pagination is `limit` and `offset`; there is no cursor. `from` and `to` are inclusive and compare against `submittedAt`. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `read:surveys`",
        "tags": [
          "Survey responses"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/offset"
          },
          {
            "name": "surveyId",
            "in": "query",
            "description": "Only responses to this survey.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "companyId",
            "in": "query",
            "description": "Only responses attributed to this company.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "measure",
            "in": "query",
            "description": "Only responses to surveys of this measure.",
            "schema": {
              "$ref": "#/components/schemas/SurveyMeasure"
            }
          },
          {
            "name": "band",
            "in": "query",
            "description": "Only responses in this score band.",
            "schema": {
              "type": "string",
              "enum": [
                "positive",
                "neutral",
                "negative",
                "unscored"
              ]
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Review status. `open` means any status except `resolved`. `overdue` means open past the workspace hours-to-close rule (`GET /surveys/case-rules`).",
            "schema": {
              "type": "string",
              "enum": [
                "new",
                "in_progress",
                "resolved",
                "open",
                "overdue"
              ]
            }
          },
          {
            "name": "from",
            "in": "query",
            "description": "Submitted at or after this time. Use an ISO 8601 timestamp with an offset, for example `2026-10-01T00:00:00Z`.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "Submitted at or before this time. Same format as `from`.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "theme",
            "in": "query",
            "description": "Only responses whose written answers mention this theme.",
            "schema": {
              "type": "string",
              "enum": [
                "onboarding",
                "reliability",
                "performance",
                "usability",
                "missing_functionality",
                "integrations",
                "support_quality",
                "documentation",
                "pricing_value",
                "billing_admin",
                "security_compliance",
                "account_management",
                "reporting_analytics",
                "mobile"
              ]
            }
          },
          {
            "name": "subjectType",
            "in": "query",
            "description": "Only responses about this kind of record.",
            "schema": {
              "type": "string",
              "enum": [
                "deal",
                "ticket",
                "plan",
                "record"
              ]
            }
          },
          {
            "name": "subjectId",
            "in": "query",
            "description": "Only responses about this one record. Send it with `subjectType`; without it the call returns `422`.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of responses.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "meta"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SurveyResponse"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "0d5e8a9b-1c2d-4e3f-8a4b-5c6d7e8f9a0b",
                      "surveyId": "7b6f2c1e-4d3a-4b5c-9e8f-1a2b3c4d5e6f",
                      "surveyName": "Relationship NPS",
                      "measure": "nps",
                      "score": 4,
                      "scaleMax": 10,
                      "band": "negative",
                      "comment": "Reports take too long to load.",
                      "answers": {
                        "q0": 4,
                        "q1": "Reports take too long to load."
                      },
                      "questionAnswers": [
                        {
                          "key": "q0",
                          "number": 1,
                          "text": "How likely are you to recommend us to a colleague?",
                          "type": "rating",
                          "value": 4,
                          "display": "4"
                        },
                        {
                          "key": "q1",
                          "number": 2,
                          "text": "What is the main reason for your score?",
                          "type": "text",
                          "value": "Reports take too long to load.",
                          "display": "Reports take too long to load."
                        }
                      ],
                      "companyId": "a1f0c2d3-5e6f-4a7b-8c9d-0e1f2a3b4c5d",
                      "personId": "c3d24e5f-6a7b-4c8d-9e0f-1a2b3c4d5e6f",
                      "subject": {
                        "type": "ticket",
                        "id": "5d1e7a3b-2c4f-4b6a-8d9e-0f1a2b3c4d5e"
                      },
                      "respondentEmail": "ana@acme.com",
                      "respondentName": "Ana Ruiz",
                      "status": "new",
                      "ownerId": null,
                      "taskId": null,
                      "submittedAt": "2026-10-14T09:12:43.000Z",
                      "reviewedAt": null
                    }
                  ],
                  "meta": {
                    "limit": 50,
                    "offset": 0,
                    "count": 1
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/survey-responses/{id}": {
      "get": {
        "operationId": "getSurveyResponse",
        "summary": "Get a survey response",
        "description": "Read one GainTrace survey response, with its answers, the questions they answer, and the record it is about. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `read:surveys`",
        "tags": [
          "Survey responses"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/surveyResponseId"
          }
        ],
        "responses": {
          "200": {
            "description": "The response.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SurveyResponse"
                    }
                  }
                },
                "example": {
                  "data": {
                    "id": "0d5e8a9b-1c2d-4e3f-8a4b-5c6d7e8f9a0b",
                    "surveyId": "7b6f2c1e-4d3a-4b5c-9e8f-1a2b3c4d5e6f",
                    "surveyName": "Relationship NPS",
                    "measure": "nps",
                    "score": 4,
                    "scaleMax": 10,
                    "band": "negative",
                    "comment": "Reports take too long to load.",
                    "answers": {
                      "q0": 4,
                      "q1": "Reports take too long to load."
                    },
                    "questionAnswers": [
                      {
                        "key": "q0",
                        "number": 1,
                        "text": "How likely are you to recommend us to a colleague?",
                        "type": "rating",
                        "value": 4,
                        "display": "4"
                      },
                      {
                        "key": "q1",
                        "number": 2,
                        "text": "What is the main reason for your score?",
                        "type": "text",
                        "value": "Reports take too long to load.",
                        "display": "Reports take too long to load."
                      }
                    ],
                    "companyId": "a1f0c2d3-5e6f-4a7b-8c9d-0e1f2a3b4c5d",
                    "personId": "c3d24e5f-6a7b-4c8d-9e0f-1a2b3c4d5e6f",
                    "subject": {
                      "type": "ticket",
                      "id": "5d1e7a3b-2c4f-4b6a-8d9e-0f1a2b3c4d5e"
                    },
                    "respondentEmail": "ana@acme.com",
                    "respondentName": "Ana Ruiz",
                    "status": "new",
                    "ownerId": null,
                    "taskId": null,
                    "submittedAt": "2026-10-14T09:12:43.000Z",
                    "reviewedAt": null
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/surveys/rollup-rules": {
      "get": {
        "operationId": "getSurveyRollupRules",
        "summary": "Get the Company score rules",
        "description": "Read how Company scores are built from each person's answers. A workspace that never changed them gets each person's latest answer from the last 365 days, with no role weights. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `read:surveys`",
        "tags": [
          "Surveys"
        ],
        "responses": {
          "200": {
            "description": "The Company score rules.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SurveyRollupRules"
                    }
                  }
                },
                "example": {
                  "data": {
                    "method": "latest",
                    "windowDays": 365,
                    "roleWeights": {}
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "put": {
        "operationId": "setSurveyRollupRules",
        "summary": "Set the Company score rules",
        "description": "Replace how Company scores are built. Send all three fields. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `write:surveys`",
        "tags": [
          "Surveys"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SurveyRollupRules"
              },
              "example": {
                "method": "mean",
                "windowDays": 180,
                "roleWeights": {
                  "decision_maker": 2
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The saved rules.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SurveyRollupRules"
                    }
                  }
                },
                "example": {
                  "data": {
                    "method": "mean",
                    "windowDays": 180,
                    "roleWeights": {
                      "decision_maker": 2
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/surveys/coverage": {
      "get": {
        "operationId": "getSurveyCoverage",
        "summary": "Get survey coverage",
        "description": "Who you hear from inside the rollup window: Companies, ARR and decision makers, plus Companies renewing in the next 90 days with no feedback in 180 days. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `read:surveys`",
        "tags": [
          "Surveys"
        ],
        "responses": {
          "200": {
            "description": "Coverage.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SurveyCoverage"
                    }
                  }
                },
                "example": {
                  "data": {
                    "windowDays": 365,
                    "companies": 42,
                    "companiesHeard": 17,
                    "companiesWithDecisionMaker": 9,
                    "reportingCurrency": "USD",
                    "arrTotal": 48200000,
                    "arrHeard": 29150000,
                    "unconvertedCurrencies": [],
                    "silentRenewals": {
                      "count": 1,
                      "companies": [
                        {
                          "id": "9b2f6c1e-5d4a-4c3b-8a1f-2e7d9c0b6a55",
                          "name": "Northwind Traders",
                          "renewalDate": "2026-11-20T00:00:00.000Z",
                          "arr": 6400000,
                          "currency": "USD"
                        }
                      ]
                    },
                    "companiesInferredOnly": null
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/companies/{id}/survey-scores": {
      "get": {
        "operationId": "getCompanySurveyScores",
        "summary": "Get a Company's survey scores",
        "description": "A Company's NPS, CSAT and effort score under your Company score rules, with how many people each rests on and a sentence describing the method. Returns `404` for a Company outside your workspace. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `read:surveys`",
        "tags": [
          "Surveys"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The Company id.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The Company's scores.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CompanySurveyScores"
                    }
                  }
                },
                "example": {
                  "data": {
                    "companyId": "9b2f6c1e-5d4a-4c3b-8a1f-2e7d9c0b6a55",
                    "measures": [
                      {
                        "measure": "nps",
                        "value": 33,
                        "people": 3,
                        "scaleMax": 10
                      }
                    ],
                    "peopleAnswered": 3,
                    "activePeople": 5,
                    "decisionMakerHeard": true,
                    "lastAnsweredAt": "2026-10-12T09:14:00.000Z",
                    "windowDays": 365,
                    "method": "Built from each person's latest answer in the last 365 days."
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/survey-segments": {
      "get": {
        "operationId": "listSurveySegments",
        "summary": "List survey segments",
        "description": "List the workspace's saved survey segments, by name. Archived segments are left out. The list is not paged: `meta.count` is the number of segments. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `read:surveys`",
        "tags": [
          "Survey segments"
        ],
        "responses": {
          "200": {
            "description": "The segments.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "meta"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SurveySegment"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                },
                "example": {
                  "data": [
                    {
                      "id": "3f6a9c1e-8b2d-4c7a-9e5f-0a1b2c3d4e5f",
                      "name": "Enterprise decision makers",
                      "company": {
                        "logic": "and",
                        "rules": [
                          {
                            "field": "segment",
                            "operator": "eq",
                            "value": "enterprise"
                          }
                        ]
                      },
                      "person": {
                        "logic": "and",
                        "rules": [
                          {
                            "field": "contactRole",
                            "operator": "is_any_of",
                            "value": [
                              "decision_maker",
                              "executive_sponsor"
                            ]
                          }
                        ]
                      },
                      "createdAt": "2026-10-14T09:00:00.000Z",
                      "updatedAt": "2026-10-14T09:00:00.000Z"
                    }
                  ],
                  "meta": {
                    "limit": 1,
                    "offset": 0,
                    "count": 1
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      },
      "post": {
        "operationId": "createSurveySegment",
        "summary": "Create a survey segment",
        "description": "Save a segment of Company and People rules. Use it as a survey's in-app audience (`settings.inApp.targeting.audience.segmentId`) or as the audience of an invitation request (`segmentId`). The name must be unique in the workspace, ignoring case; a name already in use returns `422`. A segment needs at least one rule across the two groups. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `write:surveys`",
        "tags": [
          "Survey segments"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SurveySegmentCreate"
              },
              "example": {
                "name": "Enterprise decision makers",
                "rules": {
                  "company": {
                    "logic": "and",
                    "rules": [
                      {
                        "field": "segment",
                        "operator": "eq",
                        "value": "enterprise"
                      }
                    ]
                  },
                  "person": {
                    "logic": "and",
                    "rules": [
                      {
                        "field": "contactRole",
                        "operator": "is_any_of",
                        "value": [
                          "decision_maker",
                          "executive_sponsor"
                        ]
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Segment saved.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SurveySegment"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "422": {
            "$ref": "#/components/responses/UnprocessableEntity"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/survey-segments/{id}": {
      "delete": {
        "operationId": "archiveSurveySegment",
        "summary": "Archive a survey segment",
        "description": "Archive a saved segment. It leaves the list and its name becomes free to use again. A survey whose in-app audience still points at it stops matching anyone until you choose a new audience, and an invitation request with its `segmentId` returns `404`. A segment that doesn't exist, or is already archived, returns `404`. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `write:surveys`",
        "tags": [
          "Survey segments"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The segment's UUID.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Archived."
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/survey-imports": {
      "get": {
        "operationId": "listSurveyImportSources",
        "summary": "List survey import sources",
        "description": "List the survey tools connected to your workspace (Typeform, SurveyMonkey, Qualtrics and Retently), newest first, with the status of their latest pull. Credentials are never returned. You connect and disconnect sources in the app. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `read:surveys`",
        "tags": [
          "Survey imports"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/offset"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of sources.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "meta"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/SurveyImportSource"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/survey-imports/{id}/runs": {
      "post": {
        "operationId": "runSurveyImport",
        "summary": "Pull a survey import source now",
        "description": "Pull one connected source now instead of waiting for the hourly schedule. The call waits for the pull, up to 60 seconds, and returns what it found. Imported scores count toward Company scores next to your own surveys' responses. Imported NPS also counts toward coverage; imported CSAT and CES do not. The call returns `409` while another pull of the same source is running, and when the source's credential was rejected. It returns `404` for a source outside your workspace. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `write:surveys`",
        "tags": [
          "Survey imports"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The import source's UUID, from `GET /survey-imports`.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The pull finished or stopped early.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SurveyImportRun"
                    }
                  }
                },
                "example": {
                  "data": {
                    "runId": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
                    "status": "succeeded",
                    "fetched": 52,
                    "imported": 31,
                    "updated": 2,
                    "unchanged": 17,
                    "skipped": 2,
                    "skip_reasons": [
                      {
                        "reason": "No email on this response. Map an email field so GainTrace can match the person.",
                        "count": 2
                      }
                    ],
                    "error": null
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/surveys/{id}/results": {
      "get": {
        "operationId": "getSurveyResults",
        "summary": "Get survey results",
        "description": "Results for every question of one survey, shaped by the answer type: counts per choice, means for scores, ranking scores, matrix rows, date ranges and, for the product-market fit question, the share who would be very disappointed. Written answers are counted but never returned. Use `GET /survey-responses` to read individual responses. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `read:surveys`",
        "tags": [
          "Surveys"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/surveyId"
          }
        ],
        "responses": {
          "200": {
            "description": "The results.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/SurveyResults"
                    }
                  }
                },
                "example": {
                  "data": {
                    "surveyId": "7b6f2c1e-4d3a-4b5c-9e8f-1a2b3c4d5e6f",
                    "measure": "nps",
                    "totalResponses": 120,
                    "questions": [
                      {
                        "index": 0,
                        "text": "How likely are you to recommend us to a colleague?",
                        "type": "rating",
                        "answered": 120,
                        "totalResponses": 120,
                        "average": 7.9,
                        "choices": [
                          {
                            "label": "0",
                            "count": 1
                          },
                          {
                            "label": "1",
                            "count": 0
                          },
                          {
                            "label": "2",
                            "count": 2
                          },
                          {
                            "label": "3",
                            "count": 1
                          },
                          {
                            "label": "4",
                            "count": 3
                          },
                          {
                            "label": "5",
                            "count": 4
                          },
                          {
                            "label": "6",
                            "count": 6
                          },
                          {
                            "label": "7",
                            "count": 14
                          },
                          {
                            "label": "8",
                            "count": 21
                          },
                          {
                            "label": "9",
                            "count": 38
                          },
                          {
                            "label": "10",
                            "count": 30
                          }
                        ]
                      },
                      {
                        "index": 1,
                        "text": "What is the main reason for your score?",
                        "type": "text",
                        "answered": 84,
                        "totalResponses": 120,
                        "average": null,
                        "choices": []
                      }
                    ]
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/surveys/nps-drivers": {
      "get": {
        "operationId": "getNpsDrivers",
        "summary": "Get NPS drivers",
        "description": "Company NPS against a product usage metric and ARR. Company scores follow your rollup rules. The response carries a 95% margin of error with every NPS, plus plain and revenue-weighted NPS across the workspace. Archived Companies are left out. A Company with no usage value or no ARR is reported in `missing`, never as zero. Without `metric`, GainTrace uses the first of `events_30d`, `engagement_score`, `dau_wau_ratio` and `seat_utilization` that has data, or else your most-covered metric definition. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `read:surveys`",
        "tags": [
          "Surveys"
        ],
        "parameters": [
          {
            "name": "metric",
            "in": "query",
            "description": "The usage metric: `events_30d`, `active_people_30d`, `active_days_30d`, `engagement_score`, `dau_wau_ratio`, `seat_utilization`, `event:<name>` for one product event, or `def:<id>` for a metric definition. Take values from `metrics` in a previous response. A value in the wrong format returns `400`. A well-formed metric your workspace has no data for returns `404`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The drivers.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/NpsDrivers"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/companies/{id}/inferred-satisfaction": {
      "get": {
        "operationId": "getCompanyInferredSatisfaction",
        "summary": "Get a Company's inferred satisfaction",
        "description": "Inferred satisfaction for one Company: a calibrated 1 to 5 estimate per Person, beside their surveyed score. The response is empty (`company` is `null` and `people` is an empty list) until an admin turns inferred satisfaction on in the app and at least 20 People have both an inferred and a surveyed score to compare. Pass the Company `id`; `ext:<externalId>` isn't accepted, and an id that isn't a UUID returns `400`. A Company outside your workspace returns `404`. Requires a secret server key (`gt_live_`). Publishable keys (`gt_pub_`) return `403`.\n\n**Scope:** `read:surveys`",
        "tags": [
          "Surveys"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The Company's UUID.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The estimates.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/CompanyInferredSatisfaction"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Bearer API key. Secret server keys start with `gt_live_`; client-safe browser keys start with `gt_pub_` (write-only, origin-pinned). Create and scope keys in Settings → API Keys."
      }
    },
    "parameters": {
      "limit": {
        "name": "limit",
        "in": "query",
        "description": "Max rows to return. Default 50, max 100.",
        "schema": {
          "type": "integer",
          "default": 50,
          "maximum": 100,
          "minimum": 1
        }
      },
      "offset": {
        "name": "offset",
        "in": "query",
        "description": "Rows to skip (pagination).",
        "schema": {
          "type": "integer",
          "default": 0,
          "minimum": 0
        }
      },
      "pathId": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "Resource UUID. For companies you may also pass `ext:<externalId>` to address by your external id.",
        "schema": {
          "type": "string"
        }
      },
      "personExternalIdQuery": {
        "name": "externalId",
        "in": "query",
        "description": "Your own stable id for the Person (for example a Segment `userId`). Exact match.",
        "schema": {
          "type": "string"
        }
      },
      "surveyId": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "The survey's UUID.",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "surveyResponseId": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "The survey response's UUID.",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "includeArchived": {
        "name": "includeArchived",
        "in": "query",
        "description": "Set to `true` to include archived records. GainTrace archives a record instead of deleting it when its source removes it, or when a Person leaves a Company. Lists leave archived records out by default. Any value other than `true` or `false` returns `422`.",
        "schema": {
          "type": "boolean",
          "default": false
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "The request could not be parsed (for example, malformed JSON).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "bad_request",
                "message": "Invalid JSON body",
                "doc_url": "https://docs.gaintrace.com/errors#bad_request"
              }
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing, malformed, expired, or revoked API key.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "unauthorized",
                "message": "Missing Authorization header",
                "doc_url": "https://docs.gaintrace.com/errors#unauthorized"
              }
            }
          }
        }
      },
      "PaymentRequired": {
        "description": "A plan limit was reached, or billing is locked. Upgrade or enable pay-as-you-go.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "payment_required",
                "message": "Monthly event limit reached. Upgrade or enable overage billing.",
                "doc_url": "https://docs.gaintrace.com/errors#payment_required"
              }
            }
          }
        }
      },
      "Forbidden": {
        "description": "The key is valid but lacks the required scope, the origin is not allowed, or API v1 is not enabled for the workspace.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "forbidden",
                "message": "Insufficient scope: write:companies required",
                "doc_url": "https://docs.gaintrace.com/errors#forbidden"
              }
            }
          }
        }
      },
      "NotFound": {
        "description": "The resource, or a resource you referenced, was not found in this workspace.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "not_found",
                "message": "Company not found",
                "doc_url": "https://docs.gaintrace.com/errors#not_found"
              }
            }
          }
        }
      },
      "Conflict": {
        "description": "The request conflicts with an existing resource (for example, a duplicate email).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "conflict",
                "message": "A contact with this email already exists in the workspace",
                "doc_url": "https://docs.gaintrace.com/errors#conflict"
              }
            }
          }
        }
      },
      "UnprocessableEntity": {
        "description": "The request was well-formed but a value failed validation.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "unprocessable_entity",
                "message": "Request validation failed. name: name is required",
                "doc_url": "https://docs.gaintrace.com/errors#unprocessable_entity"
              }
            }
          }
        }
      },
      "RateLimited": {
        "description": "The per-key rate limit was exceeded. Each API key can send 60 requests per minute, counted in calendar-minute windows. The `Retry-After` header gives the whole seconds (1 to 60) until the next window opens. Wait that long, then retry.",
        "headers": {
          "Retry-After": {
            "description": "Whole seconds until the next one-minute window starts.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 60
            },
            "example": 23
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "rate_limit_exceeded",
                "message": "Can't accept more than 60 requests a minute from one API key. Retry in 23 seconds.",
                "doc_url": "https://docs.gaintrace.com/errors#rate_limit_exceeded"
              }
            }
          }
        }
      },
      "InternalServerError": {
        "description": "An unexpected error occurred on our side. The failure is logged; retry shortly.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "internal_server_error",
                "message": "Something went wrong. Try again in a moment.",
                "doc_url": "https://docs.gaintrace.com/errors#internal_server_error"
              }
            }
          }
        }
      },
      "ServiceUnavailable": {
        "description": "A backing service (for example, the database) was temporarily unavailable. Retry shortly.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "service_unavailable",
                "message": "We had trouble reaching the database. Try again in a moment.",
                "doc_url": "https://docs.gaintrace.com/errors#service_unavailable"
              }
            }
          }
        }
      },
      "GatewayTimeout": {
        "description": "The request took too long upstream before completing. Retry, and reduce batch size for large payloads.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": {
                "code": "gateway_timeout",
                "message": "The request timed out. Try again in a moment.",
                "doc_url": "https://docs.gaintrace.com/errors#gateway_timeout"
              }
            }
          }
        }
      }
    },
    "schemas": {
      "Meta": {
        "type": "object",
        "properties": {
          "limit": {
            "type": "integer"
          },
          "offset": {
            "type": "integer"
          },
          "count": {
            "type": "integer",
            "description": "Number of rows in this page."
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "description": "The standard error envelope. Every 4xx/5xx response uses this shape.",
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "bad_request",
                  "unauthorized",
                  "payment_required",
                  "forbidden",
                  "not_found",
                  "conflict",
                  "unprocessable_entity",
                  "rate_limit_exceeded",
                  "internal_server_error",
                  "service_unavailable",
                  "gateway_timeout"
                ],
                "description": "Stable, machine-readable error code. Each code maps to exactly one HTTP status."
              },
              "message": {
                "type": "string",
                "description": "Human-readable, safe description of what went wrong. Never contains internal or provider detail."
              },
              "doc_url": {
                "type": "string",
                "format": "uri",
                "example": "https://docs.gaintrace.com/errors#not_found",
                "description": "Deep link to this code in the Errors reference."
              }
            }
          }
        }
      },
      "Company": {
        "type": "object",
        "description": "A canonical company record. Health, counts, and timestamps are read-only.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "externalId": {
            "type": [
              "string",
              "null"
            ],
            "description": "Your stable external id (unique per workspace). Used for upsert."
          },
          "name": {
            "type": "string"
          },
          "domain": {
            "type": [
              "string",
              "null"
            ]
          },
          "industry": {
            "type": [
              "string",
              "null"
            ]
          },
          "employeeCount": {
            "type": [
              "integer",
              "null"
            ]
          },
          "plan": {
            "type": [
              "string",
              "null"
            ]
          },
          "segment": {
            "type": [
              "string",
              "null"
            ]
          },
          "region": {
            "type": [
              "string",
              "null"
            ]
          },
          "location": {
            "type": [
              "string",
              "null"
            ]
          },
          "lifecycleStage": {
            "type": [
              "string",
              "null"
            ]
          },
          "ownerEmail": {
            "type": [
              "string",
              "null"
            ]
          },
          "arr": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Annual recurring revenue in integer minor units of `currency`."
          },
          "mrr": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Monthly recurring revenue in integer minor units of `currency`."
          },
          "currency": {
            "type": [
              "string",
              "null"
            ],
            "description": "ISO 4217 code. Null = workspace reporting currency."
          },
          "contractStartDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "contractEndDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "autoRenew": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "healthScore": {
            "type": [
              "number",
              "null"
            ],
            "description": "0-100 (read-only)."
          },
          "healthStatus": {
            "type": "string",
            "enum": [
              "healthy",
              "at_risk",
              "churning"
            ],
            "description": "Read-only."
          },
          "contactCount": {
            "type": [
              "integer",
              "null"
            ]
          },
          "dealCount": {
            "type": [
              "integer",
              "null"
            ]
          },
          "isPhantom": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "lastActivityAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "archivedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "`null` while the Company is live. Set when GainTrace archived the Company because its source removed it. Archived Companies are left out of `GET /companies` unless you send `includeArchived=true`."
          }
        }
      },
      "Signal": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "accountId": {
            "type": "string",
            "format": "uuid",
            "description": "The legacy record id the signal is attached to. It is the same value the create call returns as `accountId`. For the Company, use `companyId`."
          },
          "companyId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "The Company `id`, as `GET /companies` returns it. `null` when the signal isn't linked to a Company."
          },
          "type": {
            "$ref": "#/components/schemas/SignalReadType"
          },
          "severity": {
            "$ref": "#/components/schemas/SignalSeverity"
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "snoozed",
              "dismissed"
            ],
            "description": "Derived from the dismiss and snooze times. A snoozed signal is `snoozed` until `snoozedUntil` passes, then `open` again."
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time"
          },
          "snoozedUntil": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "dismissedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "metadata": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true
          }
        }
      },
      "SignalCreate": {
        "type": "object",
        "required": [
          "accountId",
          "type",
          "severity",
          "title"
        ],
        "properties": {
          "accountId": {
            "type": "string",
            "format": "uuid",
            "description": "The Company to record the signal against. Send the Company `id` from `GET /companies`, or the legacy account id that earlier signal responses returned. It must belong to your workspace. A value that isn't a UUID returns `422`. An id GainTrace can't find returns `404`."
          },
          "type": {
            "$ref": "#/components/schemas/SignalType"
          },
          "severity": {
            "$ref": "#/components/schemas/SignalSeverity"
          },
          "title": {
            "type": "string",
            "maxLength": 500,
            "minLength": 1
          },
          "description": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 5000
          },
          "metadata": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true,
            "description": "Arbitrary JSON, max 10KB serialized. The keys `originalType`, `goldenAccountId` and `golden_account_id` are reserved and return `422`."
          }
        }
      },
      "SignalType": {
        "type": "string",
        "enum": [
          "usage_drop",
          "usage_spike",
          "feature_adoption",
          "support_ticket",
          "payment_failed",
          "expansion_signal",
          "nps_response",
          "contract_renewal",
          "login_inactive",
          "champion_left"
        ]
      },
      "SignalSeverity": {
        "type": "string",
        "enum": [
          "info",
          "warning",
          "critical"
        ]
      },
      "ProductEvent": {
        "type": "object",
        "required": [
          "event_name",
          "event_category",
          "source",
          "timestamp"
        ],
        "properties": {
          "event_name": {
            "type": "string",
            "maxLength": 255,
            "description": "The event identifier, for example `report_exported`."
          },
          "event_category": {
            "type": "string",
            "enum": [
              "feature_usage",
              "navigation",
              "api",
              "billing",
              "support",
              "auth",
              "integration",
              "admin"
            ]
          },
          "source": {
            "type": "string",
            "enum": [
              "amplitude",
              "mixpanel",
              "posthog",
              "segment",
              "sdk",
              "warehouse",
              "webhook"
            ],
            "description": "Where the event came from."
          },
          "source_event_id": {
            "type": "string",
            "description": "Idempotency key. Required when `source` is `sdk`, `warehouse` or `segment`. An event whose `(source, source_event_id)` pair was already stored is reported as a duplicate and not stored again."
          },
          "timestamp": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 time the event happened."
          },
          "account_id": {
            "type": "string",
            "format": "uuid",
            "description": "The Company `id`. When omitted, GainTrace links the event through `user_id`."
          },
          "user_id": {
            "type": "string",
            "description": "A Person's email or `externalId`. It is matched exactly, ignoring case, against People in your workspace."
          },
          "anonymous_id": {
            "type": "string",
            "description": "The id used before the user was identified."
          },
          "session_id": {
            "type": "string"
          },
          "feature_name": {
            "type": "string"
          },
          "value": {
            "type": "number",
            "description": "Magnitude of a metered event, such as a count of calls. Defaults to 1."
          },
          "unit": {
            "type": "string",
            "maxLength": 32,
            "description": "Unit for `value`, for example `calls`."
          },
          "is_programmatic": {
            "type": "boolean",
            "description": "True when the activity came from an API or integration rather than a person in your UI."
          },
          "properties": {
            "type": "object",
            "additionalProperties": true,
            "description": "Arbitrary JSON, at most 10KB serialized."
          }
        }
      },
      "EventValidationError": {
        "type": "object",
        "properties": {
          "index": {
            "type": "integer",
            "description": "Index of the offending event in the batch."
          },
          "error": {
            "type": "string"
          }
        }
      },
      "MetricEventBatch": {
        "type": "object",
        "required": [
          "events"
        ],
        "properties": {
          "source": {
            "type": "string",
            "enum": [
              "script",
              "api",
              "segment",
              "pendo",
              "mixpanel",
              "import",
              "system"
            ],
            "default": "api"
          },
          "strict": {
            "type": "boolean",
            "default": false,
            "description": "When true, reject events whose `eventName` is not registered in event definitions."
          },
          "events": {
            "type": "array",
            "minItems": 1,
            "maxItems": 500,
            "items": {
              "$ref": "#/components/schemas/MetricEvent"
            }
          }
        }
      },
      "MetricEvent": {
        "type": "object",
        "required": [
          "eventName",
          "occurredAt"
        ],
        "description": "Name the Company with `companyId` or `companyExternalId`. Naming a Person is optional.",
        "properties": {
          "companyId": {
            "type": "string",
            "format": "uuid",
            "description": "The Company `id`. Checked first."
          },
          "companyExternalId": {
            "type": "string",
            "description": "The Company `externalId`. Used when `companyId` is absent."
          },
          "enduserId": {
            "type": "string",
            "format": "uuid",
            "description": "The Person `id`, as returned by `/people`."
          },
          "enduserEmail": {
            "type": "string",
            "format": "email",
            "description": "Used when `enduserId` is absent. GainTrace looks the Person up at the named Company."
          },
          "eventName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time",
            "description": "A UTC timestamp ending in `Z`, for example `2026-10-14T09:30:00Z`. Offsets such as `+05:30` are rejected with `422`."
          },
          "properties": {
            "type": "object",
            "additionalProperties": true,
            "description": "Not validated. With `strict: true`, an `eventName` that is not registered is rejected."
          },
          "externalId": {
            "type": "string",
            "maxLength": 200,
            "description": "Idempotency key. Repeats of the same `(source, externalId)` are skipped and reported as `duplicate`."
          }
        }
      },
      "MetricEventOutcome": {
        "type": "object",
        "properties": {
          "index": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "ingested",
              "duplicate",
              "rejected"
            ]
          },
          "error": {
            "type": "string"
          },
          "eventLogId": {
            "type": "integer"
          }
        }
      },
      "CompanyUpsert": {
        "type": "object",
        "required": [
          "name"
        ],
        "description": "Create or update a company. Upserts on `externalId` (defaults to a slug of `name`).",
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 255,
            "minLength": 1
          },
          "externalId": {
            "type": "string",
            "maxLength": 100,
            "description": "Upsert key. Defaults to a slug of the name."
          },
          "domain": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 255
          },
          "industry": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 100
          },
          "plan": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 50
          },
          "segment": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 50
          },
          "region": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 100
          },
          "location": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 255
          },
          "lifecycleStage": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 30
          },
          "ownerEmail": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 255
          },
          "employeeCount": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "arr": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "description": "Integer minor units."
          },
          "mrr": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "description": "Integer minor units."
          },
          "currency": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[A-Z]{3}$",
            "maxLength": 3,
            "description": "ISO 4217 code or null."
          },
          "contractStartDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "contractEndDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "autoRenew": {
            "type": "boolean"
          }
        }
      },
      "CompanyPatch": {
        "type": "object",
        "description": "Any subset of the writable company fields. `healthScore`/`healthStatus`/counts are read-only.",
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 255,
            "minLength": 1
          },
          "domain": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 255
          },
          "industry": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 100
          },
          "plan": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 50
          },
          "segment": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 50
          },
          "region": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 100
          },
          "location": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 255
          },
          "lifecycleStage": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 30
          },
          "ownerEmail": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 255
          },
          "employeeCount": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "arr": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "description": "Integer minor units."
          },
          "mrr": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0,
            "description": "Integer minor units."
          },
          "currency": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[A-Z]{3}$",
            "maxLength": 3,
            "description": "ISO 4217 code or null."
          },
          "contractStartDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "contractEndDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "autoRenew": {
            "type": "boolean"
          }
        }
      },
      "SignalPatch": {
        "type": "object",
        "description": "Any subset of the mutable signal fields.",
        "properties": {
          "title": {
            "type": "string",
            "maxLength": 500,
            "minLength": 1
          },
          "description": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 5000
          },
          "severity": {
            "$ref": "#/components/schemas/SignalSeverity"
          },
          "snoozedUntil": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Snooze until this time, or null to unsnooze."
          },
          "metadata": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true,
            "description": "Replaces the metadata. The keys `originalType`, `goldenAccountId` and `golden_account_id` are reserved: sending one returns `422`, and any reserved key already stored on the signal is kept."
          }
        }
      },
      "BatchOutcome": {
        "type": "object",
        "properties": {
          "index": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "created",
              "failed"
            ]
          },
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "The new signal id, when `status` is `created`."
          },
          "error": {
            "type": "string",
            "description": "Why this item failed, for example `Couldn't find the Company \"...\" in this workspace. Use an id from GET /api/v1/companies.`"
          }
        }
      },
      "ContactRole": {
        "type": "string",
        "enum": [
          "decision_maker",
          "champion",
          "end_user",
          "billing",
          "influencer",
          "executive_sponsor",
          "technical",
          "other"
        ]
      },
      "WebhookEvent": {
        "type": "string",
        "description": "An event you can subscribe to. `company.*`, `contact.*` and `signal.created` fire for changes from any source, and each delivery names its `source`. See the webhooks guide.",
        "enum": [
          "company.created",
          "company.updated",
          "contact.created",
          "contact.updated",
          "contact.deleted",
          "signal.created",
          "member.invited",
          "member.joined",
          "survey_response.created",
          "survey_response.updated",
          "survey.launched",
          "survey.closed"
        ]
      },
      "Webhook": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Subscribed events, or `[\"*\"]` for all."
          },
          "active": {
            "type": "boolean"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "headers": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "Custom headers sent with each delivery. Values are redacted (`***`) in responses."
          },
          "secretPrefix": {
            "type": "string",
            "description": "First chars of the signing secret. Full secret is returned only at creation."
          },
          "consecutiveFailures": {
            "type": "integer"
          },
          "disabledAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Set when auto-disabled after sustained failures."
          },
          "lastSuccessAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WebhookCreate": {
        "type": "object",
        "required": [
          "url",
          "events"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "maxLength": 500,
            "description": "HTTPS only; may not resolve to a private/reserved address."
          },
          "events": {
            "type": "array",
            "minItems": 1,
            "items": {
              "anyOf": [
                {
                  "$ref": "#/components/schemas/WebhookEvent"
                },
                {
                  "const": "*"
                }
              ]
            },
            "description": "Subscribed events, or `[\"*\"]`."
          },
          "headers": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "Optional custom headers (e.g. an auth token). Reserved/signing headers are rejected. Max 20, 4KB total."
          },
          "description": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 255
          }
        }
      },
      "WebhookPatch": {
        "type": "object",
        "description": "Any subset. Setting `active:true` also clears the auto-disable failure state.",
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "maxLength": 500
          },
          "events": {
            "type": "array",
            "minItems": 1,
            "items": {
              "anyOf": [
                {
                  "$ref": "#/components/schemas/WebhookEvent"
                },
                {
                  "const": "*"
                }
              ]
            }
          },
          "headers": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "description": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 255
          },
          "active": {
            "type": "boolean"
          }
        },
        "minProperties": 1
      },
      "WebhookCreated": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Webhook"
          },
          {
            "type": "object",
            "properties": {
              "secret": {
                "type": "string",
                "description": "The signing secret, returned ONCE. Store it now."
              }
            }
          }
        ]
      },
      "SignalListItem": {
        "type": "object",
        "description": "The subset returned by the list endpoint. `GET /signals/{id}` returns the full Signal.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "accountId": {
            "type": "string",
            "format": "uuid",
            "description": "The legacy record id the signal is attached to. It is the same value the create call returns as `accountId`. For the Company, use `companyId`."
          },
          "companyId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "The Company `id`, as `GET /companies` returns it. `null` when the signal isn't linked to a Company."
          },
          "type": {
            "$ref": "#/components/schemas/SignalReadType"
          },
          "severity": {
            "$ref": "#/components/schemas/SignalSeverity"
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Person": {
        "type": "object",
        "description": "One Person at one Company. A Person who belongs to several Companies is returned as one record per Company, each with its own `id` and `accountId`.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "The id of this Person at this Company."
          },
          "accountId": {
            "type": "string",
            "format": "uuid",
            "description": "The `id` of the Company this record belongs to. See Companies."
          },
          "name": {
            "type": "string"
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "format": "email"
          },
          "externalId": {
            "type": [
              "string",
              "null"
            ],
            "description": "Your own stable id for the Person, such as a Segment `userId`. Product events use it to find the Person."
          },
          "phone": {
            "type": [
              "string",
              "null"
            ]
          },
          "role": {
            "type": [
              "string",
              "null"
            ],
            "description": "Free-text job title."
          },
          "contactRole": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/ContactRole"
              },
              {
                "type": "null"
              }
            ],
            "description": "The Person's role in the buying relationship."
          },
          "isChampion": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "traits": {
            "type": "object",
            "additionalProperties": true,
            "description": "Free-form attributes. An empty object when none are set."
          },
          "linkedinUrl": {
            "type": [
              "string",
              "null"
            ]
          },
          "avatarUrl": {
            "type": [
              "string",
              "null"
            ]
          },
          "lastSeenAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Read-only."
          },
          "engagementScore": {
            "type": [
              "number",
              "null"
            ],
            "description": "Read-only."
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "archivedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "`null` while this record is live. Set when the Person left this Company or its source removed them. Archived records are left out of `GET /people` unless you send `includeArchived=true`."
          }
        }
      },
      "PersonCreate": {
        "type": "object",
        "description": "Create a Person at a Company, or with `upsert: true` create or update. Name the Company with `accountId` or `accountExternalId`. `name` is required unless `upsert` is true and an `email` is supplied, or the Person already exists at another Company.",
        "anyOf": [
          {
            "required": [
              "accountId"
            ]
          },
          {
            "required": [
              "accountExternalId"
            ]
          }
        ],
        "properties": {
          "accountId": {
            "type": "string",
            "format": "uuid",
            "description": "The Company `id`. It must belong to your workspace."
          },
          "accountExternalId": {
            "type": "string",
            "maxLength": 100,
            "description": "The Company `externalId`, used when you do not hold the Company `id`. If no Company has this `externalId`, GainTrace creates one, and that counts against your Company limit. The new Company fires the `company.created` webhook but does not start Company-created Flows. Ignored when `accountId` is a string."
          },
          "accountName": {
            "type": "string",
            "description": "The name for a Company created through `accountExternalId`. Defaults to the `externalId`."
          },
          "upsert": {
            "type": "boolean",
            "default": false,
            "description": "When true, a Person who already exists at this Company is updated and returned with `200`, instead of failing with `409`. `traits` are merged into the stored traits, not replaced."
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "format": "email",
            "maxLength": 255
          },
          "externalId": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 255
          },
          "phone": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 50
          },
          "role": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 100
          },
          "contactRole": {
            "$ref": "#/components/schemas/ContactRole"
          },
          "isChampion": {
            "type": "boolean"
          },
          "traits": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true
          },
          "linkedinUrl": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 2000
          },
          "avatarUrl": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 2000
          }
        }
      },
      "PersonPatch": {
        "type": "object",
        "description": "Any subset of the mutable fields. You cannot move a Person to another Company. `traits` replaces the stored traits.",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "format": "email",
            "maxLength": 255,
            "description": "A new address moves the whole Person: every live record of this Person takes it. `409` when another Person already uses it. `null` clears the address on this record only."
          },
          "externalId": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 255
          },
          "phone": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 50
          },
          "role": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 100
          },
          "contactRole": {
            "$ref": "#/components/schemas/ContactRole"
          },
          "isChampion": {
            "type": "boolean"
          },
          "traits": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": true,
            "description": "Replaces the stored traits. `null` clears them."
          },
          "linkedinUrl": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 2000
          },
          "avatarUrl": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 2000
          }
        }
      },
      "ProductEventResult": {
        "type": "object",
        "description": "The outcome for one submitted event. `results` is in the same order as the `events` you sent.",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "inserted",
              "duplicate",
              "error",
              "rejected"
            ],
            "description": "`inserted`: stored. `duplicate`: already stored under the same `source_event_id`. `error`: valid, but GainTrace could not store it. `rejected`: failed validation, see `reason`."
          },
          "reason": {
            "type": "string",
            "description": "Present when `status` is `rejected`."
          }
        }
      },
      "SignalReadType": {
        "type": "string",
        "description": "The type on a signal you read. Signals GainTrace detects use the full list. Signals you create through the API use the 10 types in `SignalType`.",
        "enum": [
          "usage_drop",
          "usage_spike",
          "feature_adoption",
          "support_ticket",
          "payment_failed",
          "expansion_signal",
          "nps_response",
          "contract_renewal",
          "login_inactive",
          "champion_left",
          "champion_arrived",
          "lead_grade_change",
          "first_value",
          "outcome_gap",
          "commercial_intent",
          "billing_risk",
          "issue_stale_blocker",
          "issue_reopened",
          "issue_shipped"
        ]
      },
      "NpsResponseImport": {
        "type": "object",
        "required": [
          "provider",
          "externalId",
          "score",
          "respondedAt"
        ],
        "additionalProperties": false,
        "description": "One NPS answer from another tool. Send `contactId`, or send both `accountId` and `email`. Fields not listed here are rejected.",
        "properties": {
          "provider": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64,
            "pattern": "^[a-zA-Z0-9_-]+$",
            "description": "The tool the answer came from, for example `retently`."
          },
          "externalId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255,
            "description": "The answer's id in that tool. With `provider`, it makes the import idempotent."
          },
          "score": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10
          },
          "respondedAt": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 with a UTC offset."
          },
          "accountId": {
            "type": "string",
            "format": "uuid",
            "description": "The Company `id`."
          },
          "contactId": {
            "type": "string",
            "format": "uuid",
            "description": "The Person `id`. GainTrace takes the Company and email from this Person."
          },
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 254
          },
          "comment": {
            "type": "string",
            "maxLength": 5000
          },
          "campaignId": {
            "type": "string",
            "maxLength": 255
          }
        }
      },
      "NpsResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "provider": {
            "type": [
              "string",
              "null"
            ]
          },
          "externalId": {
            "type": [
              "string",
              "null"
            ],
            "description": "The id the answer has in the provider's tool."
          },
          "accountId": {
            "type": "string",
            "format": "uuid",
            "description": "The Company `id`."
          },
          "contactId": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "The Person `id`, when GainTrace could attribute the answer to one."
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "score": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10
          },
          "category": {
            "type": "string",
            "enum": [
              "promoter",
              "passive",
              "detractor"
            ],
            "description": "Promoter is 9-10, passive is 7-8, detractor is 0-6."
          },
          "comment": {
            "type": [
              "string",
              "null"
            ]
          },
          "campaignId": {
            "type": [
              "string",
              "null"
            ]
          },
          "source": {
            "type": [
              "string",
              "null"
            ],
            "description": "`api:<provider>` for imported answers."
          },
          "respondedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "SurveyMeasure": {
        "type": "string",
        "enum": [
          "nps",
          "csat",
          "ces",
          "custom"
        ],
        "description": "`nps` is a 0-10 scale. `csat` and `ces` use a 1-5 or 1-7 scale. `custom` has no band and its responses are `unscored`. For `nps`, `csat` and `ces`, the first question must be a required `rating` or `scale` question: it carries the score."
      },
      "SurveyLogicGroup": {
        "type": "object",
        "required": [
          "match",
          "conditions"
        ],
        "additionalProperties": false,
        "description": "Conditions on earlier answers or hidden fields. `match` is `all` or `any`.",
        "properties": {
          "match": {
            "type": "string",
            "enum": [
              "all",
              "any"
            ]
          },
          "conditions": {
            "type": "array",
            "minItems": 1,
            "maxItems": 10,
            "items": {
              "oneOf": [
                {
                  "type": "object",
                  "required": [
                    "question",
                    "operator",
                    "value"
                  ],
                  "additionalProperties": false,
                  "description": "An earlier answer. `question` is the zero-based index. `band` compares the score group (negative, neutral or positive).",
                  "properties": {
                    "question": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 19
                    },
                    "operator": {
                      "type": "string",
                      "enum": [
                        "lte",
                        "gte",
                        "eq",
                        "is",
                        "is_not",
                        "includes",
                        "excludes",
                        "before",
                        "after",
                        "band"
                      ]
                    },
                    "value": {
                      "oneOf": [
                        {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 10
                        },
                        {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 255
                        }
                      ]
                    }
                  }
                },
                {
                  "type": "object",
                  "required": [
                    "hidden",
                    "operator",
                    "value"
                  ],
                  "additionalProperties": false,
                  "description": "A hidden field the survey lists in `settings.hiddenFields`.",
                  "properties": {
                    "hidden": {
                      "type": "string",
                      "pattern": "^[a-z][a-z0-9_]{0,39}$"
                    },
                    "operator": {
                      "type": "string",
                      "enum": [
                        "is",
                        "is_not"
                      ]
                    },
                    "value": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 200
                    }
                  }
                }
              ]
            }
          }
        }
      },
      "SurveyJumpRule": {
        "type": "object",
        "required": [
          "when",
          "to"
        ],
        "additionalProperties": false,
        "description": "Where to go after the question when the conditions match. The first matching rule wins, otherwise the next question.",
        "properties": {
          "when": {
            "$ref": "#/components/schemas/SurveyLogicGroup"
          },
          "to": {
            "oneOf": [
              {
                "type": "object",
                "required": [
                  "question"
                ],
                "additionalProperties": false,
                "properties": {
                  "question": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 19
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "ending"
                ],
                "additionalProperties": false,
                "properties": {
                  "ending": {
                    "type": "string",
                    "pattern": "^[a-z0-9][a-z0-9_-]{0,39}$",
                    "description": "The `id` of an entry in `settings.endings`."
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "end"
                ],
                "additionalProperties": false,
                "properties": {
                  "end": {
                    "type": "boolean",
                    "enum": [
                      true
                    ]
                  }
                }
              }
            ]
          }
        }
      },
      "SurveyEnding": {
        "type": "object",
        "required": [
          "id",
          "name"
        ],
        "additionalProperties": false,
        "description": "A named thank-you screen that only logic jumps reach. It overrides the score-group and default copy field by field.",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9_-]{0,39}$"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 60
          },
          "title": {
            "type": "string",
            "maxLength": 120
          },
          "message": {
            "type": "string",
            "maxLength": 1000
          },
          "link": {
            "type": "object",
            "required": [
              "label",
              "url"
            ],
            "additionalProperties": false,
            "properties": {
              "label": {
                "type": "string",
                "minLength": 1,
                "maxLength": 40
              },
              "url": {
                "type": "string",
                "format": "uri",
                "maxLength": 2048,
                "description": "An HTTPS link."
              }
            }
          }
        }
      },
      "SurveyQuestion": {
        "type": "object",
        "required": [
          "text",
          "type",
          "required"
        ],
        "additionalProperties": false,
        "properties": {
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000,
            "description": "The question text. Use `{{company}}`, `{{first_name}}` or `{{score}}` to fill in details from a signed link. `{{company|your team}}` falls back to the text after the bar. Surveys must stay purely feedback, so promotional phrases such as \"discount code\" or \"limited time\" are rejected."
          },
          "type": {
            "type": "string",
            "enum": [
              "rating",
              "scale",
              "text",
              "multiple_choice",
              "multi_select",
              "dropdown",
              "matrix",
              "ranking",
              "date",
              "statement",
              "consent"
            ],
            "description": "`rating` and `scale` are scored questions. `multiple_choice` picks one answer, `multi_select` picks several (checkboxes) and `dropdown` picks one from a long list. `matrix` asks one scale for several rows, `ranking` orders a list, `date` takes a calendar date, `statement` shows text with no answer, and `consent` is a required checkbox."
          },
          "required": {
            "type": "boolean",
            "description": "A `statement` can't be required. A `consent` question must be required."
          },
          "options": {
            "type": "array",
            "minItems": 2,
            "maxItems": 100,
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "description": "Answer choices, each different. Required for `multiple_choice`, `multi_select`, `dropdown` and `ranking`. Up to 20 for `multiple_choice` and `multi_select`, 100 for `dropdown`, and 10 for `ranking`. For `matrix`, these are the scale columns, lowest first, up to 10."
          },
          "rows": {
            "type": "array",
            "minItems": 2,
            "maxItems": 15,
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255
            },
            "description": "`matrix` only: the statements people rate against the columns in `options`. Each row is different."
          },
          "minSelections": {
            "type": "integer",
            "minimum": 1,
            "maximum": 20,
            "description": "`multi_select` only: the fewest boxes a person must tick. It can't exceed `maxSelections` or the number of options."
          },
          "maxSelections": {
            "type": "integer",
            "minimum": 1,
            "maximum": 20,
            "description": "`multi_select` only: the most boxes a person may tick. It can't exceed the number of options."
          },
          "scaleMin": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10
          },
          "scaleMax": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10,
            "description": "Must be greater than `scaleMin` when both are set."
          },
          "scaleLabels": {
            "type": "object",
            "required": [
              "min",
              "max"
            ],
            "additionalProperties": false,
            "properties": {
              "min": {
                "type": "string",
                "maxLength": 100
              },
              "max": {
                "type": "string",
                "maxLength": 100
              }
            }
          },
          "display": {
            "type": "string",
            "enum": [
              "faces",
              "stars",
              "numbers"
            ],
            "description": "`rating` only. `stars` needs a 1 to 5 scale. `faces` is for the first question of a CSAT survey on a 1 to 5 scale. NPS and CES scores show as numbers."
          },
          "description": {
            "type": "string",
            "maxLength": 2000,
            "description": "`statement` and `consent` only: the text under the question."
          },
          "link": {
            "type": "object",
            "required": [
              "label",
              "url"
            ],
            "additionalProperties": false,
            "description": "`statement` and `consent` only: an optional link, for example to a policy.",
            "properties": {
              "label": {
                "type": "string",
                "minLength": 1,
                "maxLength": 40
              },
              "url": {
                "type": "string",
                "format": "uri",
                "maxLength": 2048,
                "description": "An HTTPS link."
              }
            }
          },
          "preset": {
            "type": "string",
            "enum": [
              "pmf"
            ],
            "description": "`pmf` marks the product-market fit question. It must be a `multiple_choice` question with the four standard answers `Very disappointed`, `Somewhat disappointed`, `Not disappointed` and `I no longer use it`, in that order. Results then include the share who would be very disappointed."
          },
          "showWhen": {
            "type": "object",
            "required": [
              "operator",
              "value"
            ],
            "additionalProperties": false,
            "description": "Show this question only when an earlier answer matches. A question can depend only on an earlier question. The operator depends on the earlier question's type: `lte`, `gte` or `eq` with a number for `rating` and `scale`; `is` or `is_not` with one of the answer choices for `multiple_choice` and `dropdown`; `includes` or `excludes` with one of the choices for `multi_select`; `before` or `after` with a `YYYY-MM-DD` date for `date`. A score value must sit inside the earlier question's scale.",
            "properties": {
              "question": {
                "type": "integer",
                "minimum": 0,
                "maximum": 19,
                "description": "Zero-based index of the earlier question. Defaults to the first question."
              },
              "operator": {
                "type": "string",
                "enum": [
                  "lte",
                  "gte",
                  "eq",
                  "is",
                  "is_not",
                  "includes",
                  "excludes",
                  "before",
                  "after"
                ]
              },
              "value": {
                "oneOf": [
                  {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 10
                  },
                  {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 255
                  }
                ]
              }
            }
          },
          "logic": {
            "allOf": [
              {
                "$ref": "#/components/schemas/SurveyLogicGroup"
              }
            ],
            "description": "Show this question only when these conditions on earlier answers or hidden fields match. Never send both `logic` and `showWhen`."
          },
          "jumps": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "$ref": "#/components/schemas/SurveyJumpRule"
            },
            "description": "Where to go after this question. The first rule whose conditions match wins."
          },
          "libraryId": {
            "type": "string",
            "format": "uuid",
            "description": "The workspace library question this one was copied from. Never shown to respondents."
          }
        }
      },
      "SurveySettings": {
        "type": "object",
        "additionalProperties": false,
        "description": "Optional survey settings. Unknown keys are rejected.",
        "properties": {
          "defaultLanguage": {
            "type": "string",
            "enum": [
              "en",
              "ar",
              "bg",
              "bn",
              "ca",
              "cs",
              "da",
              "de",
              "el",
              "es",
              "et",
              "fa",
              "fi",
              "fil",
              "fr",
              "he",
              "hi",
              "hr",
              "hu",
              "id",
              "it",
              "ja",
              "ko",
              "lt",
              "lv",
              "ms",
              "nl",
              "no",
              "pl",
              "pt-BR",
              "pt-PT",
              "ro",
              "ru",
              "sk",
              "sl",
              "sr",
              "sv",
              "th",
              "tr",
              "uk",
              "ur",
              "vi",
              "zh-CN",
              "zh-TW"
            ],
            "description": "The language respondents see when nothing else matches. Defaults to `en`."
          },
          "translations": {
            "type": "object",
            "maxProperties": 15,
            "propertyNames": {
              "enum": [
                "en",
                "ar",
                "bg",
                "bn",
                "ca",
                "cs",
                "da",
                "de",
                "el",
                "es",
                "et",
                "fa",
                "fi",
                "fil",
                "fr",
                "he",
                "hi",
                "hr",
                "hu",
                "id",
                "it",
                "ja",
                "ko",
                "lt",
                "lv",
                "ms",
                "nl",
                "no",
                "pl",
                "pt-BR",
                "pt-PT",
                "ro",
                "ru",
                "sk",
                "sl",
                "sr",
                "sv",
                "th",
                "tr",
                "uk",
                "ur",
                "vi",
                "zh-CN",
                "zh-TW"
              ]
            },
            "additionalProperties": {
              "$ref": "#/components/schemas/SurveyLanguageCopy"
            },
            "description": "Respondent copy per language code, up to 15 languages. A respondent sees the language they choose or their browser asks for when the survey offers it, and the default language otherwise. Translations never change a score or answer: GainTrace maps what a respondent picked back to the default-language choice before it saves."
          },
          "brandColor": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$",
            "example": "#FFAC00"
          },
          "logoUrl": {
            "type": "string",
            "format": "uri",
            "maxLength": 2048,
            "description": "An HTTPS image URL."
          },
          "thankYouTitle": {
            "type": "string",
            "maxLength": 120
          },
          "thankYouMessage": {
            "type": "string",
            "maxLength": 1000
          },
          "thankYouByBand": {
            "type": "object",
            "additionalProperties": false,
            "description": "Replaces the title, message and button for respondents whose score lands in a band.",
            "properties": {
              "negative": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 120
                  },
                  "message": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "link": {
                    "type": "object",
                    "required": [
                      "label",
                      "url"
                    ],
                    "additionalProperties": false,
                    "description": "A button for this score group only, such as a review site for promoters. Falls back to `thankYouLink`.",
                    "properties": {
                      "label": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 40
                      },
                      "url": {
                        "type": "string",
                        "format": "uri",
                        "maxLength": 2048,
                        "description": "An HTTPS link."
                      }
                    }
                  }
                }
              },
              "neutral": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 120
                  },
                  "message": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "link": {
                    "type": "object",
                    "required": [
                      "label",
                      "url"
                    ],
                    "additionalProperties": false,
                    "description": "A button for this score group only, such as a review site for promoters. Falls back to `thankYouLink`.",
                    "properties": {
                      "label": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 40
                      },
                      "url": {
                        "type": "string",
                        "format": "uri",
                        "maxLength": 2048,
                        "description": "An HTTPS link."
                      }
                    }
                  }
                }
              },
              "positive": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 120
                  },
                  "message": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "link": {
                    "type": "object",
                    "required": [
                      "label",
                      "url"
                    ],
                    "additionalProperties": false,
                    "description": "A button for this score group only, such as a review site for promoters. Falls back to `thankYouLink`.",
                    "properties": {
                      "label": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 40
                      },
                      "url": {
                        "type": "string",
                        "format": "uri",
                        "maxLength": 2048,
                        "description": "An HTTPS link."
                      }
                    }
                  }
                }
              }
            }
          },
          "thankYouLink": {
            "type": "object",
            "required": [
              "label",
              "url"
            ],
            "additionalProperties": false,
            "description": "An optional next step on the thank-you screen.",
            "properties": {
              "label": {
                "type": "string",
                "minLength": 1,
                "maxLength": 40
              },
              "url": {
                "type": "string",
                "format": "uri",
                "maxLength": 2048,
                "description": "An HTTPS link."
              }
            }
          },
          "anonymous": {
            "type": "boolean",
            "description": "Anonymous surveys store no person, company or respondent identity on a response. This setting locks once the survey is live or has responses."
          },
          "hiddenFields": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "type": "string",
              "pattern": "^[a-z][a-z0-9_]{0,39}$"
            },
            "description": "Names of link parameters saved with each response, for example `plan`. Values for any other name are dropped."
          },
          "endings": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "$ref": "#/components/schemas/SurveyEnding"
            },
            "description": "Named thank-you screens that only logic jumps reach."
          },
          "customCss": {
            "type": "string",
            "maxLength": 10000,
            "description": "Styling for the respondent page and the in-app survey. It can't contain `<`, `@import` or `url()`."
          },
          "sendWindow": {
            "type": "object",
            "required": [
              "startHour",
              "endHour",
              "weekdaysOnly"
            ],
            "additionalProperties": false,
            "description": "Approved email invitations wait for these local hours in the workspace time zone.",
            "properties": {
              "startHour": {
                "type": "integer",
                "minimum": 0,
                "maximum": 23
              },
              "endHour": {
                "type": "integer",
                "minimum": 1,
                "maximum": 24,
                "description": "Must be greater than `startHour`."
              },
              "weekdaysOnly": {
                "type": "boolean"
              }
            }
          },
          "reminders": {
            "type": "object",
            "required": [
              "afterDays",
              "max"
            ],
            "additionalProperties": false,
            "description": "Re-send to people who have not answered. People who answered are never reminded.",
            "properties": {
              "afterDays": {
                "type": "integer",
                "minimum": 1,
                "maximum": 14
              },
              "max": {
                "type": "integer",
                "minimum": 1,
                "maximum": 3
              }
            }
          },
          "alerts": {
            "type": "object",
            "required": [
              "bands"
            ],
            "additionalProperties": false,
            "description": "Post each new response in the chosen bands to Slack, Microsoft Teams, or both. Set `slackChannel`, `teamsWebhookUrl` or both.",
            "properties": {
              "bands": {
                "type": "array",
                "minItems": 1,
                "maxItems": 3,
                "items": {
                  "type": "string",
                  "enum": [
                    "negative",
                    "neutral",
                    "positive"
                  ]
                }
              },
              "slackChannel": {
                "type": "string",
                "pattern": "^[CG][A-Z0-9]{6,}$",
                "description": "A Slack channel id."
              },
              "teamsWebhookUrl": {
                "type": "string",
                "format": "uri",
                "maxLength": 2048,
                "description": "The HTTPS webhook URL from a Teams Workflow."
              }
            }
          },
          "inApp": {
            "type": "object",
            "required": [
              "enabled",
              "allowedOrigins",
              "minAgeDays",
              "minSessions",
              "maxDisplays",
              "delayMs"
            ],
            "additionalProperties": false,
            "description": "In-app collection rules. See the in-app SDK guide.",
            "properties": {
              "enabled": {
                "type": "boolean",
                "description": "Enabling requires at least one allowed origin."
              },
              "allowedOrigins": {
                "type": "array",
                "maxItems": 20,
                "items": {
                  "type": "string",
                  "format": "uri",
                  "maxLength": 255
                },
                "description": "Exact origins such as `https://app.example.com`. No paths, no wildcards. HTTPS only, except `http://localhost` and `http://127.0.0.1`."
              },
              "minAgeDays": {
                "type": "integer",
                "minimum": 0,
                "maximum": 730,
                "description": "Days since the person was first recorded in GainTrace."
              },
              "minSessions": {
                "type": "integer",
                "minimum": 1,
                "maximum": 365,
                "description": "Distinct UTC days on which a session was recorded for the person."
              },
              "maxDisplays": {
                "type": "integer",
                "minimum": 1,
                "maximum": 10,
                "description": "Maximum displays inside the survey's cooldown window."
              },
              "delayMs": {
                "type": "integer",
                "minimum": 0,
                "maximum": 120000
              },
              "samplingPercent": {
                "type": "integer",
                "minimum": 1,
                "maximum": 100,
                "description": "Show to this share of eligible people. The same people stay in or out of the sample on every visit. Omit for everyone."
              },
              "position": {
                "type": "string",
                "enum": [
                  "bottom",
                  "bottom-right",
                  "bottom-left",
                  "center"
                ],
                "description": "Defaults to `bottom`. `center` is a blocking modal."
              },
              "targeting": {
                "$ref": "#/components/schemas/SurveyInAppTargeting"
              }
            }
          },
          "advocacy": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "enabled",
              "ask"
            ],
            "description": "When a respondent in the top score group (NPS 9-10, or the top two points of a CSAT or effort scale) at a known Company answers, the Company's CSM gets a task to ask them for a review, a case study or a reference call. At most one open ask per person; anonymous surveys never create one.",
            "properties": {
              "enabled": {
                "type": "boolean"
              },
              "ask": {
                "type": "string",
                "enum": [
                  "review",
                  "case_study",
                  "reference"
                ]
              }
            }
          },
          "aiProbe": {
            "type": "object",
            "required": [
              "enabled"
            ],
            "additionalProperties": false,
            "description": "One optional AI-written follow-up question, asked after the response is saved and labelled as AI-generated. Off unless enabled. When a respondent answers it, the question and answer appear in the response `answers` under `_probe`.",
            "properties": {
              "enabled": {
                "type": "boolean"
              }
            }
          }
        }
      },
      "SurveyInput": {
        "type": "object",
        "required": [
          "name",
          "type",
          "questions"
        ],
        "additionalProperties": false,
        "description": "The survey contract. Send exactly these keys. NPS uses a 0 to 10 scale. CSAT and CES use 1 to 5 or 1 to 7. The first question of an NPS, CSAT or CES survey is the required score question. A survey has 1 to 20 questions.",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "type": {
            "$ref": "#/components/schemas/SurveyMeasure"
          },
          "questions": {
            "type": "array",
            "minItems": 1,
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/SurveyQuestion"
            }
          },
          "settings": {
            "$ref": "#/components/schemas/SurveySettings"
          },
          "cooldownDays": {
            "type": "integer",
            "minimum": 0,
            "maximum": 730,
            "description": "Minimum days since this person last got a survey of the same measure (an email sent, an invited answer or an in-app view) before this survey can invite them or show to them in-app. It doesn't block responses you record through the API."
          }
        }
      },
      "SurveyPatch": {
        "type": "object",
        "additionalProperties": false,
        "description": "Any subset of the survey contract. `settings` keys you send replace the matching top-level settings keys, and the rest are kept. A nested object such as `reminders` is replaced as a whole.",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "type": {
            "$ref": "#/components/schemas/SurveyMeasure"
          },
          "questions": {
            "type": "array",
            "minItems": 1,
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/SurveyQuestion"
            }
          },
          "settings": {
            "$ref": "#/components/schemas/SurveySettings"
          },
          "cooldownDays": {
            "type": "integer",
            "minimum": 0,
            "maximum": 730,
            "description": "Minimum days since this person last got a survey of the same measure (an email sent, an invited answer or an in-app view) before this survey can invite them or show to them in-app. It doesn't block responses you record through the API."
          }
        }
      },
      "Survey": {
        "type": "object",
        "required": [
          "id",
          "name",
          "measure",
          "status",
          "questions",
          "settings",
          "cooldownDays",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "measure": {
            "$ref": "#/components/schemas/SurveyMeasure"
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "active",
              "closed"
            ]
          },
          "questions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SurveyQuestion"
            }
          },
          "settings": {
            "$ref": "#/components/schemas/SurveySettings"
          },
          "cooldownDays": {
            "type": "integer"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "SurveyStatusChange": {
        "type": "object",
        "required": [
          "status"
        ],
        "additionalProperties": false,
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "active",
              "closed"
            ]
          }
        }
      },
      "SurveyInvitationRequest": {
        "description": "Who to invite. Send exactly one of `personIds`, `segmentId` or `audience`.",
        "oneOf": [
          {
            "type": "object",
            "required": [
              "personIds"
            ],
            "additionalProperties": false,
            "properties": {
              "personIds": {
                "type": "array",
                "minItems": 1,
                "maxItems": 100,
                "items": {
                  "type": "string",
                  "format": "uuid"
                },
                "description": "Ids of people. Duplicates are ignored."
              }
            }
          },
          {
            "type": "object",
            "required": [
              "segmentId"
            ],
            "additionalProperties": false,
            "properties": {
              "segmentId": {
                "type": "string",
                "format": "uuid",
                "description": "A saved segment from `POST /survey-segments`."
              }
            }
          },
          {
            "type": "object",
            "required": [
              "audience"
            ],
            "additionalProperties": false,
            "properties": {
              "audience": {
                "$ref": "#/components/schemas/SurveyAudienceRules"
              }
            }
          }
        ]
      },
      "SurveyInvitationResult": {
        "type": "object",
        "required": [
          "mode",
          "queued",
          "sending",
          "skipped",
          "batchId",
          "sendAt"
        ],
        "properties": {
          "mode": {
            "type": "string",
            "enum": [
              "send",
              "approve"
            ],
            "description": "The workspace's invitation setting. `send` releases invitations to send. `approve` holds them in Triage until a teammate approves."
          },
          "queued": {
            "type": "integer",
            "description": "Invitations now waiting for approval in Triage. Always `0` when `mode` is `send`."
          },
          "sending": {
            "type": "integer",
            "description": "Invitations released to send: right away, or at the survey's next send window. Always `0` when `mode` is `approve`."
          },
          "skipped": {
            "type": "integer",
            "description": "People left out: an invitation already waits or is about to send for their email, they are inside this survey's `cooldownDays`, or they were surveyed within the workspace frequency rule."
          },
          "batchId": {
            "type": "string",
            "format": "uuid"
          },
          "sendAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "When released invitations send, if the survey has a send window. `null` when the survey has no send window, or when `mode` is `approve`."
          },
          "matched": {
            "type": "integer",
            "description": "Only for `segmentId` and `audience` requests: how many people the audience matched before skips."
          }
        }
      },
      "SurveyResponseCreate": {
        "type": "object",
        "required": [
          "personId",
          "externalId"
        ],
        "additionalProperties": false,
        "properties": {
          "personId": {
            "type": "string",
            "format": "uuid",
            "description": "An active person in your workspace."
          },
          "externalId": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255,
            "description": "Your own stable id for this answer. Re-sending it for the same survey returns the first response instead of creating another."
          },
          "score": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10,
            "description": "The first question's score. It must sit inside that question's scale, and must match `answers.q0` when you send both."
          },
          "answers": {
            "type": "object",
            "additionalProperties": true,
            "description": "Answers keyed by zero-based question index: `q0`, `q1` and so on. A score is an integer inside the question's scale. A multiple choice or dropdown answer is one of the listed options. A checkbox answer is a list of options. A ranking is every option, in your order. A matrix is an object of row to column. A date is `YYYY-MM-DD`. A consent answer is `true`. Text answers are at most 5,000 characters. Required questions that are visible must be answered. `comment` carries a free-text comment."
          },
          "hidden": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "maxLength": 200
            },
            "description": "Values for the survey's `hiddenFields`. At most 10 keys, each name at most 40 characters. Names the survey does not list are dropped."
          },
          "subject": {
            "$ref": "#/components/schemas/SurveySubjectInput"
          }
        }
      },
      "SurveyResponseRecorded": {
        "type": "object",
        "required": [
          "id",
          "duplicate"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "nullable": true,
            "description": "The response id."
          },
          "duplicate": {
            "type": "boolean",
            "description": "`true` when this `externalId` was already recorded and the first response is returned."
          }
        }
      },
      "SurveyResponse": {
        "type": "object",
        "required": [
          "id",
          "surveyId",
          "surveyName",
          "measure",
          "score",
          "scaleMax",
          "band",
          "comment",
          "answers",
          "questionAnswers",
          "subject",
          "status",
          "submittedAt"
        ],
        "description": "The same shape as the `survey_response` webhook payload for a GainTrace survey, without `source` and `channel`.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "surveyId": {
            "type": "string",
            "format": "uuid"
          },
          "surveyName": {
            "type": "string"
          },
          "measure": {
            "$ref": "#/components/schemas/SurveyMeasure"
          },
          "score": {
            "type": "integer",
            "nullable": true
          },
          "scaleMax": {
            "type": "integer",
            "nullable": true,
            "description": "The maximum of the survey's first-question scale."
          },
          "band": {
            "type": "string",
            "enum": [
              "positive",
              "neutral",
              "negative",
              "unscored"
            ],
            "description": "NPS: 9-10 positive, 7-8 neutral, 0-6 negative. CSAT and CES: the top two points of the scale are positive, the bottom half is negative, the rest neutral. Custom surveys and answers without a score are `unscored`."
          },
          "comment": {
            "type": "string",
            "nullable": true
          },
          "answers": {
            "type": "object",
            "additionalProperties": true,
            "description": "Answers keyed `q0`, `q1` and so on, plus `comment` and `hidden` when present. When the AI follow-up was asked, `_probe` holds its `question` and the respondent's `answer`. Use `questionAnswers` to read answers with their question text."
          },
          "questionAnswers": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SurveyQuestionAnswer"
            },
            "description": "Each answer with its question text, in question order."
          },
          "companyId": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "personId": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "subject": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/SurveySubject"
              },
              {
                "type": "null"
              }
            ],
            "description": "The deal, ticket, plan or custom record the response is about. `null` when it isn't linked to one, and always `null` on anonymous surveys."
          },
          "respondentEmail": {
            "type": "string",
            "nullable": true
          },
          "respondentName": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "string",
            "enum": [
              "new",
              "in_progress",
              "resolved"
            ]
          },
          "ownerId": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "taskId": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "submittedAt": {
            "type": "string",
            "format": "date-time"
          },
          "reviewedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "language": {
            "type": "string",
            "description": "The language code the respondent answered in, such as `en` or `pt-BR`."
          }
        }
      },
      "SurveySessionCreate": {
        "type": "object",
        "required": [
          "contactId",
          "accountId",
          "parentOrigin"
        ],
        "additionalProperties": false,
        "description": "Field names follow the code: `contactId` is a person id and `accountId` is a company id.",
        "properties": {
          "contactId": {
            "type": "string",
            "format": "uuid",
            "description": "The signed-in person's id in GainTrace."
          },
          "accountId": {
            "type": "string",
            "format": "uuid",
            "description": "The id of that person's company. It must match the person."
          },
          "parentOrigin": {
            "type": "string",
            "format": "uri",
            "maxLength": 255,
            "description": "The exact origin of the page that will show the survey, such as `https://app.example.com`. It must be listed in the survey's `settings.inApp.allowedOrigins`."
          },
          "mode": {
            "type": "string",
            "enum": [
              "survey",
              "test"
            ],
            "default": "survey",
            "description": "`test` skips eligibility rules and records nothing, so you can preview the survey."
          },
          "context": {
            "type": "object",
            "required": [
              "url"
            ],
            "additionalProperties": false,
            "description": "What the person is doing right now. Send it when the survey has page rules or a trigger under `settings.inApp.targeting`.",
            "properties": {
              "url": {
                "type": "string",
                "format": "uri",
                "maxLength": 2048,
                "description": "The page the person is on. It must be on `parentOrigin`, or the call returns `422`."
              },
              "event": {
                "type": "string",
                "pattern": "^[A-Za-z0-9][A-Za-z0-9_.:-]{0,63}$",
                "description": "The event name your code sent with `GaintraceSurveys.track()`, for an `event` trigger."
              },
              "dwellSeconds": {
                "type": "integer",
                "minimum": 0,
                "maximum": 86400,
                "description": "Seconds on the page, for a `time_on_page` trigger."
              }
            }
          },
          "subject": {
            "$ref": "#/components/schemas/SurveySubjectInput",
            "description": "The deal, ticket, plan or custom record this survey asks about. Responses to the embed carry it as their `subject`. The record must belong to the same Company as the person. The record a response is about: a deal, ticket, plan or custom record. Name it by its GainTrace `id`, or, for a deal or ticket, by the id it has in your CRM or help desk (`externalId`, with `source` when more than one connection holds that id). For a custom record, send the data model's `model` slug and the record's `externalId`. The record must exist, must not be archived, and must belong to the same Company as the person."
          },
          "lang": {
            "type": "string",
            "maxLength": 35,
            "description": "A language tag such as `es` or `pt-BR`. The survey shows in this language when it has a translation for it. It wins over the person's `locale` or `language` trait and the browser."
          }
        }
      },
      "SurveySession": {
        "oneOf": [
          {
            "type": "object",
            "required": [
              "eligible",
              "embedUrl",
              "delayMs"
            ],
            "properties": {
              "eligible": {
                "type": "boolean",
                "enum": [
                  true
                ]
              },
              "embedUrl": {
                "type": "string",
                "format": "uri",
                "description": "A signed URL that is valid for one hour. Pass it to `GaintraceSurveys.show`. It uses your verified custom domain while the white-label add-on is active."
              },
              "sessionId": {
                "type": "string",
                "format": "uuid",
                "description": "Omitted in test mode."
              },
              "delayMs": {
                "type": "integer"
              }
            }
          },
          {
            "type": "object",
            "required": [
              "eligible",
              "reason"
            ],
            "properties": {
              "eligible": {
                "type": "boolean",
                "enum": [
                  false
                ]
              },
              "reason": {
                "type": "string",
                "enum": [
                  "disabled",
                  "cooldown",
                  "recently_dismissed",
                  "not_sampled",
                  "snoozed",
                  "already_seen",
                  "minimum_age",
                  "minimum_sessions",
                  "display_limit",
                  "page_not_targeted",
                  "not_targeted",
                  "awaiting_trigger"
                ],
                "description": "Why the person doesn't see the survey now. `page_not_targeted`, `not_targeted` and `awaiting_trigger` come from the survey's targeting: the page didn't match, the person isn't in the audience, or the trigger hasn't fired yet. Ask again when the person reaches the page or fires the event."
              },
              "awaiting": {
                "type": "object",
                "description": "With `awaiting_trigger`: what the survey is waiting for.",
                "properties": {
                  "events": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "timeOnPageSeconds": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        ]
      },
      "SurveyFrequencyRule": {
        "type": "object",
        "required": [
          "recontactDays",
          "dismissedRecontactDays"
        ],
        "additionalProperties": false,
        "properties": {
          "recontactDays": {
            "type": "integer",
            "minimum": 0,
            "maximum": 365,
            "description": "Days after any survey contact (email sent, in-app shown, answered, or imported answer) before the same person is surveyed again. 0 turns the rule off. Default 30."
          },
          "dismissedRecontactDays": {
            "type": "integer",
            "minimum": 0,
            "maximum": 365,
            "description": "Days after someone dismisses an in-app survey before any in-app survey shows to them again. 0 turns the rule off. Default 7."
          },
          "companyLimit": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": false,
            "required": [
              "people",
              "days"
            ],
            "description": "Optional Company limit: ask at most `people` different people at one Company within `days`, across every survey and channel. People are matched by email address, so a person counts once however often they are asked, and reminders don't count. `null` means no limit, which is the default. Leave it out of a PUT to keep the saved limit.",
            "properties": {
              "people": {
                "type": "integer",
                "minimum": 1,
                "maximum": 1000
              },
              "days": {
                "type": "integer",
                "minimum": 1,
                "maximum": 365
              }
            }
          }
        }
      },
      "SurveyCaseRules": {
        "type": "object",
        "required": [
          "slaHours",
          "autoAssign"
        ],
        "additionalProperties": false,
        "properties": {
          "slaHours": {
            "type": "integer",
            "minimum": 1,
            "maximum": 720,
            "description": "Hours an open response can wait before it is overdue. Default 48."
          },
          "autoAssign": {
            "type": "string",
            "enum": [
              "none",
              "negative",
              "all"
            ],
            "description": "Assign new responses to the company's CSM: never, only negative ones, or all. Default `negative`."
          }
        }
      },
      "SurveyRollupRules": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "method",
          "windowDays",
          "roleWeights"
        ],
        "description": "How a Company's score is built from its people's answers. Each person counts once per measure.",
        "properties": {
          "method": {
            "type": "string",
            "enum": [
              "latest",
              "mean",
              "median"
            ],
            "description": "How one person's answers inside the window become their score: their latest answer, or the mean or median of their answers. Answers on another scale are mapped onto the scale of the person's latest answer first."
          },
          "windowDays": {
            "type": "integer",
            "minimum": 30,
            "maximum": 730,
            "description": "Answers older than this many days stop counting toward Company scores and coverage."
          },
          "roleWeights": {
            "type": "object",
            "additionalProperties": false,
            "description": "How many times a person in this role counts. Everyone else counts once. Weights of 1 are dropped when saved.",
            "properties": {
              "decision_maker": {
                "type": "number",
                "minimum": 1,
                "maximum": 5
              },
              "executive_sponsor": {
                "type": "number",
                "minimum": 1,
                "maximum": 5
              },
              "champion": {
                "type": "number",
                "minimum": 1,
                "maximum": 5
              }
            }
          }
        }
      },
      "SurveyMeasureScore": {
        "type": "object",
        "required": [
          "measure",
          "value",
          "people",
          "scaleMax"
        ],
        "properties": {
          "measure": {
            "type": "string",
            "enum": [
              "nps",
              "csat",
              "ces"
            ]
          },
          "value": {
            "type": "number",
            "description": "NPS from -100 to 100 (percent of people at 9-10 minus percent at 0-6, role-weighted); CSAT as the percent of people in the top two points of their scale; CES as the role-weighted mean, or the weighted median when the method is `median`, rounded to one decimal."
          },
          "people": {
            "type": "integer",
            "description": "People whose answers count toward this measure."
          },
          "scaleMax": {
            "type": "integer"
          }
        }
      },
      "CompanySurveyScores": {
        "type": "object",
        "required": [
          "companyId",
          "measures",
          "peopleAnswered",
          "activePeople",
          "decisionMakerHeard",
          "lastAnsweredAt",
          "windowDays",
          "method"
        ],
        "properties": {
          "companyId": {
            "type": "string",
            "format": "uuid"
          },
          "measures": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SurveyMeasureScore"
            },
            "description": "One entry per measure with at least one scored answer in the window. Imported NPS scores count with your own surveys."
          },
          "peopleAnswered": {
            "type": "integer"
          },
          "activePeople": {
            "type": "integer",
            "description": "The Company's People that aren't archived."
          },
          "decisionMakerHeard": {
            "type": "boolean",
            "description": "Whether a decision maker or executive sponsor answered inside the window."
          },
          "lastAnsweredAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "windowDays": {
            "type": "integer"
          },
          "method": {
            "type": "string",
            "description": "One sentence describing how the scores were built, to show beside them."
          }
        }
      },
      "SurveyCoverage": {
        "type": "object",
        "required": [
          "windowDays",
          "companies",
          "companiesHeard",
          "companiesWithDecisionMaker",
          "reportingCurrency",
          "arrTotal",
          "arrHeard",
          "unconvertedCurrencies",
          "silentRenewals"
        ],
        "properties": {
          "windowDays": {
            "type": "integer",
            "description": "The rollup window answers are counted in."
          },
          "companies": {
            "type": "integer",
            "description": "Companies that aren't archived."
          },
          "companiesHeard": {
            "type": "integer",
            "description": "Companies with a scored answer in the window, scored answers from your surveys or imported NPS."
          },
          "companiesWithDecisionMaker": {
            "type": "integer",
            "description": "Of those, how many had a decision maker or executive sponsor answer."
          },
          "reportingCurrency": {
            "type": "string",
            "description": "The workspace reporting currency the ARR figures are in."
          },
          "arrTotal": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ARR of all Companies in minor units of the reporting currency. Null when no Company has ARR."
          },
          "arrHeard": {
            "type": [
              "integer",
              "null"
            ],
            "description": "ARR of the Companies heard from, in minor units of the reporting currency."
          },
          "unconvertedCurrencies": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Currencies left out of the ARR figures because no exchange rate exists for them yet."
          },
          "silentRenewals": {
            "type": "object",
            "required": [
              "count",
              "companies"
            ],
            "description": "Companies renewing in the next 90 days that nobody has heard from in 180 days.",
            "properties": {
              "count": {
                "type": "integer"
              },
              "companies": {
                "type": "array",
                "description": "Up to 10, largest ARR first.",
                "items": {
                  "type": "object",
                  "required": [
                    "id",
                    "name",
                    "renewalDate",
                    "arr",
                    "currency"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "name": {
                      "type": "string"
                    },
                    "renewalDate": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "arr": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    },
                    "currency": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "companiesInferredOnly": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Companies that have an inferred satisfaction score but no scored survey answer in the window. `null` until an admin turns on inferred satisfaction and it has enough People to calibrate. These Companies are never counted in `companiesHeard`."
          }
        }
      },
      "SurveyFilterRule": {
        "type": "object",
        "required": [
          "field",
          "operator",
          "value"
        ],
        "additionalProperties": false,
        "properties": {
          "field": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "description": "In a Company rule group, a field key from your Company data model, such as `segment` or `plan`. In a People rule group, one of `email`, `name`, `role`, `contactRole`, `isChampion`, `lastSeenAt`, `engagementScore`, `createdAt`, or `traits.<key>` for a Person trait. `person.` and `people.` prefixes are accepted. Any other People field returns `422`."
          },
          "operator": {
            "type": "string",
            "enum": [
              "eq",
              "neq",
              "gt",
              "gte",
              "lt",
              "lte",
              "contains",
              "not_contains",
              "starts_with",
              "ends_with",
              "is_empty",
              "is_not_empty",
              "in",
              "not_in",
              "between",
              "before",
              "after",
              "in_the_last",
              "in_the_next",
              "older_than",
              "further_than",
              "is",
              "is_not",
              "is_any_of",
              "is_none_of"
            ],
            "description": "The same operators Flow conditions use."
          },
          "value": {
            "oneOf": [
              {
                "type": "string",
                "maxLength": 500
              },
              {
                "type": "number"
              },
              {
                "type": "boolean"
              },
              {
                "type": "array",
                "maxItems": 50,
                "items": {
                  "type": "string",
                  "maxLength": 200
                }
              }
            ]
          },
          "value2": {
            "oneOf": [
              {
                "type": "string",
                "maxLength": 500
              },
              {
                "type": "number"
              }
            ],
            "description": "The upper bound for `between`."
          },
          "unit": {
            "type": "string",
            "enum": [
              "minutes",
              "hours",
              "days",
              "workdays",
              "weeks",
              "months"
            ],
            "description": "The unit for date operators such as `in_the_last`."
          }
        }
      },
      "SurveyFilterGroup": {
        "type": "object",
        "required": [
          "logic",
          "rules"
        ],
        "additionalProperties": false,
        "properties": {
          "logic": {
            "type": "string",
            "enum": [
              "and",
              "or"
            ]
          },
          "rules": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/SurveyFilterRule"
            }
          }
        }
      },
      "SurveyAudienceRules": {
        "type": "object",
        "required": [
          "company",
          "person"
        ],
        "additionalProperties": false,
        "description": "Who to reach: People who match `person`, at Companies that match `company`. An empty `rules` list in a group matches everyone for that group. A request needs at least one rule across both groups, so nobody is ever invited by accident. Only People with an email address at Companies that aren't archived can match.",
        "properties": {
          "company": {
            "$ref": "#/components/schemas/SurveyFilterGroup"
          },
          "person": {
            "$ref": "#/components/schemas/SurveyFilterGroup"
          }
        }
      },
      "SurveySegmentCreate": {
        "type": "object",
        "required": [
          "name",
          "rules"
        ],
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "description": "Unique in the workspace, ignoring case."
          },
          "rules": {
            "$ref": "#/components/schemas/SurveyAudienceRules"
          }
        }
      },
      "SurveySegment": {
        "type": "object",
        "required": [
          "id",
          "name",
          "company",
          "person",
          "createdAt",
          "updatedAt"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "company": {
            "$ref": "#/components/schemas/SurveyFilterGroup"
          },
          "person": {
            "$ref": "#/components/schemas/SurveyFilterGroup"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "SurveySubjectInput": {
        "description": "The record a response is about: a deal, ticket, plan or custom record. Name it by its GainTrace `id`, or, for a deal or ticket, by the id it has in your CRM or help desk (`externalId`, with `source` when more than one connection holds that id). For a custom record, send the data model's `model` slug and the record's `externalId`. The record must exist, must not be archived, and must belong to the same Company as the person.",
        "oneOf": [
          {
            "type": "object",
            "required": [
              "type",
              "id"
            ],
            "additionalProperties": false,
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "deal",
                  "ticket",
                  "plan",
                  "record"
                ]
              },
              "id": {
                "type": "string",
                "format": "uuid",
                "description": "The GainTrace record id."
              }
            }
          },
          {
            "type": "object",
            "required": [
              "type",
              "externalId"
            ],
            "additionalProperties": false,
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "deal",
                  "ticket"
                ]
              },
              "externalId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 255
              },
              "source": {
                "type": "string",
                "minLength": 1,
                "maxLength": 64,
                "description": "The connection the id comes from, such as `hubspot`. Lowercased."
              }
            }
          },
          {
            "type": "object",
            "required": [
              "type",
              "model",
              "externalId"
            ],
            "additionalProperties": false,
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "record"
                ]
              },
              "model": {
                "type": "string",
                "minLength": 1,
                "maxLength": 64,
                "description": "The data model's slug."
              },
              "externalId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 255
              }
            }
          }
        ]
      },
      "SurveySubject": {
        "type": "object",
        "required": [
          "type",
          "id"
        ],
        "description": "The record the response is about.",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "deal",
              "ticket",
              "plan",
              "record"
            ]
          },
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "The GainTrace record id."
          }
        }
      },
      "SurveyPageRule": {
        "type": "object",
        "required": [
          "match",
          "value"
        ],
        "additionalProperties": false,
        "properties": {
          "match": {
            "type": "string",
            "enum": [
              "equals",
              "contains",
              "starts_with"
            ]
          },
          "value": {
            "type": "string",
            "minLength": 1,
            "maxLength": 512,
            "description": "A path and query such as `/billing`. No spaces, and nothing after `#`."
          }
        }
      },
      "SurveyInAppTargeting": {
        "type": "object",
        "additionalProperties": false,
        "description": "Who, where and when the in-app survey shows. GainTrace checks the page rules first, then the audience, then the trigger. People who don't qualify get a reason from `POST /surveys/{id}/session`.",
        "properties": {
          "audience": {
            "description": "Limit the survey to a saved segment, or to rules you send here.",
            "oneOf": [
              {
                "type": "object",
                "required": [
                  "segmentId"
                ],
                "additionalProperties": false,
                "properties": {
                  "segmentId": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "rules"
                ],
                "additionalProperties": false,
                "properties": {
                  "rules": {
                    "$ref": "#/components/schemas/SurveyAudienceRules"
                  }
                }
              }
            ]
          },
          "pages": {
            "type": "object",
            "required": [
              "include",
              "exclude"
            ],
            "additionalProperties": false,
            "description": "Page rules matched against the `context.url` your backend sends when it mints a session. With include rules, the page must match one. A page that matches an exclude rule never shows the survey.",
            "properties": {
              "include": {
                "type": "array",
                "maxItems": 20,
                "items": {
                  "$ref": "#/components/schemas/SurveyPageRule"
                }
              },
              "exclude": {
                "type": "array",
                "maxItems": 20,
                "items": {
                  "$ref": "#/components/schemas/SurveyPageRule"
                }
              }
            }
          },
          "trigger": {
            "description": "What makes the survey appear. Without a trigger it shows as soon as the person qualifies.",
            "oneOf": [
              {
                "type": "object",
                "required": [
                  "kind"
                ],
                "additionalProperties": false,
                "properties": {
                  "kind": {
                    "type": "string",
                    "enum": [
                      "page_load"
                    ]
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "kind",
                  "events"
                ],
                "additionalProperties": false,
                "properties": {
                  "kind": {
                    "type": "string",
                    "enum": [
                      "event"
                    ]
                  },
                  "events": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 10,
                    "items": {
                      "type": "string",
                      "pattern": "^[A-Za-z0-9][A-Za-z0-9_.:-]{0,63}$"
                    },
                    "description": "Event names your code sends with `GaintraceSurveys.track()`."
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "kind",
                  "seconds"
                ],
                "additionalProperties": false,
                "properties": {
                  "kind": {
                    "type": "string",
                    "enum": [
                      "time_on_page"
                    ]
                  },
                  "seconds": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 600
                  }
                }
              }
            ]
          }
        }
      },
      "SurveyLanguageCopy": {
        "type": "object",
        "additionalProperties": false,
        "description": "The copy for one language. Anything you leave out falls back to the default language. A question translation applies only while the default copy it was written against is unchanged: GainTrace stamps a `source` fingerprint on save, and a translation whose fingerprint no longer matches is ignored until you update it.",
        "properties": {
          "title": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200,
            "description": "The survey name shown as the heading."
          },
          "questions": {
            "type": "array",
            "maxItems": 20,
            "description": "One entry per question, in order. Use `null` for a question you don't translate.",
            "items": {
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "source": {
                      "type": "string",
                      "pattern": "^[0-9a-f]{8}$",
                      "description": "Fingerprint of the default copy. GainTrace sets it on save when you leave it out."
                    },
                    "text": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 1000
                    },
                    "description": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 2000
                    },
                    "linkLabel": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 255
                    },
                    "options": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255
                      },
                      "description": "Same length and order as the default `options`."
                    },
                    "rows": {
                      "type": "array",
                      "maxItems": 15,
                      "items": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 255
                      },
                      "description": "Same length and order as the default `rows`."
                    },
                    "scaleLabels": {
                      "type": "object",
                      "additionalProperties": false,
                      "properties": {
                        "min": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 100
                        },
                        "max": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 100
                        }
                      }
                    }
                  }
                }
              ]
            }
          },
          "thankYou": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "title": {
                "type": "string",
                "minLength": 1,
                "maxLength": 120
              },
              "message": {
                "type": "string",
                "minLength": 1,
                "maxLength": 1000
              },
              "linkLabel": {
                "type": "string",
                "minLength": 1,
                "maxLength": 40
              },
              "byBand": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "negative": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "title": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 120
                      },
                      "message": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 1000
                      },
                      "linkLabel": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 40
                      }
                    }
                  },
                  "neutral": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "title": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 120
                      },
                      "message": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 1000
                      },
                      "linkLabel": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 40
                      }
                    }
                  },
                  "positive": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "title": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 120
                      },
                      "message": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 1000
                      },
                      "linkLabel": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 40
                      }
                    }
                  }
                }
              }
            }
          },
          "ui": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "minLength": 1,
              "maxLength": 1000
            },
            "description": "Overrides for the respondent page's interface strings, keyed by string id. An unknown key returns `422`."
          },
          "endings": {
            "type": "object",
            "description": "Translations of `settings.endings`, keyed by ending `id`.",
            "additionalProperties": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "title": {"type": "string", "minLength": 1, "maxLength": 120},
                "message": {"type": "string", "minLength": 1, "maxLength": 1000},
                "linkLabel": {"type": "string", "minLength": 1, "maxLength": 40}
              }
            }
          },
          "reviewedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "SurveyQuestionAnswer": {
        "type": "object",
        "required": [
          "key",
          "number",
          "text",
          "type",
          "value",
          "display"
        ],
        "description": "One answer paired with its question wording. Statements and unanswered questions are left out.",
        "properties": {
          "key": {
            "type": "string",
            "description": "`q0`, `q1` and so on, the same key as in `answers`."
          },
          "number": {
            "type": "integer",
            "description": "The question number, starting at 1."
          },
          "text": {
            "type": "string",
            "description": "The question text."
          },
          "type": {
            "type": "string",
            "enum": [
              "rating",
              "scale",
              "text",
              "multiple_choice",
              "multi_select",
              "dropdown",
              "matrix",
              "ranking",
              "date",
              "statement",
              "consent"
            ]
          },
          "value": {
            "description": "The stored answer: a number for a score, a string for text, a choice, or a `YYYY-MM-DD` date, a list of strings for checkboxes and rankings (in rank order), an object of row to column for a matrix, and `true` for consent."
          },
          "display": {
            "type": "string",
            "description": "The answer as readable text, for example `Reporting, Alerts`."
          }
        }
      },
      "SurveyImportSource": {
        "type": "object",
        "required": [
          "id",
          "provider",
          "name",
          "externalSurveyId",
          "measure",
          "scaleMin",
          "scaleMax",
          "status",
          "credentialHint",
          "connectedAt",
          "lastRunAt",
          "lastSuccessAt",
          "lastError",
          "nextRunAt",
          "lastRun"
        ],
        "description": "A survey tool connected to your workspace. The credential is never returned.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "provider": {
            "type": "string",
            "enum": [
              "typeform",
              "surveymonkey",
              "qualtrics",
              "retently"
            ]
          },
          "name": {
            "type": "string"
          },
          "externalSurveyId": {
            "type": "string",
            "description": "The form, survey or campaign id in the provider's tool."
          },
          "measure": {
            "type": "string",
            "enum": [
              "nps",
              "csat",
              "ces"
            ]
          },
          "scaleMin": {
            "type": "integer"
          },
          "scaleMax": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "paused",
              "error"
            ],
            "description": "`error` means the provider rejected the credential. Disconnect the source in the app and connect it again."
          },
          "credentialHint": {
            "type": "string",
            "description": "The last four characters of the stored credential."
          },
          "connectedAt": {
            "type": "string",
            "format": "date-time"
          },
          "lastRunAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "lastSuccessAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "lastError": {
            "type": [
              "string",
              "null"
            ]
          },
          "nextRunAt": {
            "type": "string",
            "format": "date-time"
          },
          "lastRun": {
            "type": [
              "object",
              "null"
            ],
            "description": "Counts from the most recent run.",
            "properties": {
              "imported": {
                "type": "integer"
              },
              "updated": {
                "type": "integer"
              },
              "skipped": {
                "type": "integer"
              }
            }
          }
        }
      },
      "SurveyImportRun": {
        "type": "object",
        "required": [
          "runId",
          "status",
          "fetched",
          "imported",
          "updated",
          "unchanged",
          "skipped",
          "skip_reasons",
          "error"
        ],
        "properties": {
          "runId": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "succeeded",
              "partial",
              "failed"
            ],
            "description": "`partial` means the pull stopped before it finished. GainTrace continues on a later pull."
          },
          "fetched": {
            "type": "integer",
            "description": "Responses read from the provider."
          },
          "imported": {
            "type": "integer",
            "description": "New responses saved."
          },
          "updated": {
            "type": "integer",
            "description": "Responses that changed since an earlier import."
          },
          "unchanged": {
            "type": "integer"
          },
          "skipped": {
            "type": "integer",
            "description": "Responses left out. `skip_reasons` says why."
          },
          "skip_reasons": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "reason",
                "count"
              ],
              "properties": {
                "reason": {
                  "type": "string"
                },
                "count": {
                  "type": "integer"
                }
              }
            }
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "SurveyQuestionResult": {
        "type": "object",
        "required": [
          "index",
          "text",
          "type",
          "answered",
          "totalResponses",
          "average",
          "choices"
        ],
        "description": "Results for one question. Which optional fields appear depends on the question's type.",
        "properties": {
          "index": {
            "type": "integer",
            "description": "Zero-based question index."
          },
          "text": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "rating",
              "scale",
              "text",
              "multiple_choice",
              "multi_select",
              "dropdown",
              "matrix",
              "ranking",
              "date",
              "statement",
              "consent"
            ]
          },
          "answered": {
            "type": "integer",
            "description": "How many responses answered this question."
          },
          "totalResponses": {
            "type": "integer",
            "description": "How many responses the survey has."
          },
          "average": {
            "type": [
              "number",
              "null"
            ],
            "description": "Mean score for `rating` and `scale` questions, to two decimals. `null` otherwise, or with no answers."
          },
          "choices": {
            "type": "array",
            "description": "Counts in a fixed order: the scale from lowest to highest, the option order, months for a date, or a single `Agreed` row for consent. Text answers are counted in `answered` but never listed.",
            "items": {
              "type": "object",
              "required": [
                "label",
                "count"
              ],
              "properties": {
                "label": {
                  "type": "string"
                },
                "count": {
                  "type": "integer"
                }
              }
            }
          },
          "ranking": {
            "type": "array",
            "description": "`ranking` questions: items from most to least preferred. First place counts for the number of items and last place for 1.",
            "items": {
              "type": "object",
              "properties": {
                "label": {
                  "type": "string"
                },
                "score": {
                  "type": "number"
                },
                "averagePosition": {
                  "type": [
                    "number",
                    "null"
                  ]
                },
                "firstPlace": {
                  "type": "integer"
                },
                "count": {
                  "type": "integer"
                }
              }
            }
          },
          "matrix": {
            "type": "array",
            "description": "`matrix` questions: one entry per row, with the answers across the shared columns and the average column position, from 1.",
            "items": {
              "type": "object",
              "properties": {
                "row": {
                  "type": "string"
                },
                "answered": {
                  "type": "integer"
                },
                "average": {
                  "type": [
                    "number",
                    "null"
                  ]
                },
                "choices": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "label": {
                        "type": "string"
                      },
                      "count": {
                        "type": "integer"
                      }
                    }
                  }
                }
              }
            }
          },
          "dates": {
            "type": "object",
            "description": "`date` questions: the earliest and latest date answered.",
            "properties": {
              "earliest": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "latest": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "pmf": {
            "type": "object",
            "description": "Questions with `preset: \"pmf\"`: the four answer counts, the base (the first three answers added up) and the share who would be very disappointed.",
            "properties": {
              "veryDisappointed": {
                "type": "integer"
              },
              "somewhatDisappointed": {
                "type": "integer"
              },
              "notDisappointed": {
                "type": "integer"
              },
              "noLongerUse": {
                "type": "integer"
              },
              "base": {
                "type": "integer"
              },
              "percent": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Percent of the base who would be very disappointed. `null` with an empty base."
              }
            }
          }
        }
      },
      "SurveyResults": {
        "type": "object",
        "required": [
          "surveyId",
          "measure",
          "totalResponses",
          "questions"
        ],
        "properties": {
          "surveyId": {
            "type": "string",
            "format": "uuid"
          },
          "measure": {
            "$ref": "#/components/schemas/SurveyMeasure"
          },
          "totalResponses": {
            "type": "integer"
          },
          "questions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SurveyQuestionResult"
            },
            "description": "One entry per question, in survey order."
          }
        }
      },
      "NpsInterval": {
        "type": "object",
        "required": [
          "nps",
          "margin",
          "low",
          "high",
          "n",
          "method"
        ],
        "properties": {
          "nps": {
            "type": "integer",
            "description": "NPS from -100 to 100."
          },
          "margin": {
            "type": "integer",
            "description": "The 95% margin of error, in NPS points."
          },
          "low": {
            "type": "integer"
          },
          "high": {
            "type": "integer"
          },
          "n": {
            "type": "number",
            "description": "The effective sample size."
          },
          "method": {
            "type": "string",
            "enum": [
              "wald",
              "adjusted_wald"
            ],
            "description": "`adjusted_wald` is used when every answer falls in one group, so a small sample never reads as a margin of zero."
          }
        }
      },
      "UsageMetricOption": {
        "type": "object",
        "required": [
          "key",
          "label",
          "unit",
          "group",
          "window",
          "companies"
        ],
        "properties": {
          "key": {
            "type": "string",
            "description": "The value to send as `metric`."
          },
          "label": {
            "type": "string"
          },
          "unit": {
            "type": [
              "string",
              "null"
            ]
          },
          "group": {
            "type": "string",
            "enum": [
              "events",
              "health",
              "metrics"
            ]
          },
          "window": {
            "type": "string",
            "enum": [
              "before_answer",
              "current",
              "latest_value"
            ],
            "description": "How the value is read. `before_answer` covers the 30 days up to the Company's latest answer. `current` is the Company's value now. `latest_value` is the newest recorded value."
          },
          "companies": {
            "type": "integer",
            "description": "How many Companies have data for this metric."
          }
        }
      },
      "NpsDrivers": {
        "type": "object",
        "required": [
          "windowDays",
          "method",
          "reportingCurrency",
          "metric",
          "metrics",
          "points",
          "overall",
          "quadrants",
          "missing",
          "truncated"
        ],
        "properties": {
          "windowDays": {
            "type": "integer",
            "description": "The rollup window from `GET /surveys/rollup-rules`."
          },
          "method": {
            "type": "string",
            "description": "One sentence describing how Company scores were built."
          },
          "reportingCurrency": {
            "type": "string"
          },
          "metric": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/UsageMetricOption"
              },
              {
                "type": "null"
              }
            ],
            "description": "The usage metric the points use. `null` when the workspace has no usage data."
          },
          "metrics": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/UsageMetricOption"
            },
            "description": "Every metric you can send as `metric`. Metrics with no data are not offered."
          },
          "points": {
            "type": "array",
            "description": "One point per Company with NPS answers in the window, largest ARR first. Capped at 2,000.",
            "items": {
              "type": "object",
              "required": [
                "companyId",
                "name",
                "nps",
                "margin",
                "people",
                "usage",
                "arr"
              ],
              "properties": {
                "companyId": {
                  "type": "string",
                  "format": "uuid"
                },
                "name": {
                  "type": "string"
                },
                "nps": {
                  "type": "integer"
                },
                "margin": {
                  "type": "integer",
                  "description": "The 95% margin of error."
                },
                "people": {
                  "type": "integer",
                  "description": "People whose answers count toward this Company's NPS."
                },
                "usage": {
                  "type": [
                    "number",
                    "null"
                  ],
                  "description": "The Company's value for the metric. `null` when it has none, never zero."
                },
                "arr": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "description": "ARR in minor units of `reportingCurrency`. `null` when the Company has no ARR or no exchange rate exists."
                }
              }
            }
          },
          "overall": {
            "type": "object",
            "properties": {
              "plain": {
                "oneOf": [
                  {
                    "allOf": [
                      {
                        "$ref": "#/components/schemas/NpsInterval"
                      },
                      {
                        "type": "object",
                        "properties": {
                          "people": {
                            "type": "integer"
                          }
                        }
                      }
                    ]
                  },
                  {
                    "type": "null"
                  }
                ],
                "description": "NPS across everyone, each Person counted once."
              },
              "revenueWeighted": {
                "oneOf": [
                  {
                    "allOf": [
                      {
                        "$ref": "#/components/schemas/NpsInterval"
                      },
                      {
                        "type": "object",
                        "properties": {
                          "companies": {
                            "type": "integer"
                          },
                          "arr": {
                            "type": "integer",
                            "description": "ARR of the Companies in the calculation, in minor units of `reportingCurrency`."
                          }
                        }
                      }
                    ]
                  },
                  {
                    "type": "null"
                  }
                ],
                "description": "NPS where each Company counts in proportion to its ARR. Companies without ARR are left out."
              }
            }
          },
          "quadrants": {
            "type": "array",
            "description": "Companies split at the median usage and at NPS 0.",
            "items": {
              "type": "object",
              "properties": {
                "key": {
                  "type": "string",
                  "enum": [
                    "high_usage_positive",
                    "high_usage_negative",
                    "low_usage_positive",
                    "low_usage_negative"
                  ]
                },
                "companies": {
                  "type": "integer"
                },
                "arrMinor": {
                  "type": "integer"
                },
                "medianUsage": {
                  "type": [
                    "number",
                    "null"
                  ]
                }
              }
            }
          },
          "missing": {
            "type": "object",
            "description": "What the numbers leave out.",
            "properties": {
              "usage": {
                "type": "integer",
                "description": "Points with no usage value."
              },
              "arr": {
                "type": "integer",
                "description": "Points with no ARR."
              },
              "unconvertedCurrencies": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "truncated": {
            "type": "boolean",
            "description": "`true` when there were more than 2,000 points."
          }
        }
      },
      "CompanyInferredSatisfaction": {
        "type": "object",
        "required": [
          "enabled",
          "windowDays",
          "calibration",
          "company",
          "people"
        ],
        "description": "A Trace AI estimate of how satisfied a Company's People sound, built from their own emails, calls and tickets. It is always separate from NPS, CSAT and CES.",
        "properties": {
          "enabled": {
            "type": "boolean",
            "description": "Whether an admin turned inferred satisfaction on."
          },
          "windowDays": {
            "type": "integer",
            "description": "How far back a Person's conversations count."
          },
          "calibration": {
            "type": "object",
            "required": [
              "n",
              "agreementPercent",
              "meanAbsoluteError",
              "map",
              "computedAt",
              "published",
              "minimumN"
            ],
            "description": "How the estimate compares with People's surveyed scores.",
            "properties": {
              "n": {
                "type": "integer",
                "description": "People who have both an inferred and a surveyed score."
              },
              "agreementPercent": {
                "type": [
                  "number",
                  "null"
                ],
                "description": "Share of those People whose inferred band matched their surveyed band, checked leave-one-out. `null` below 2 People."
              },
              "meanAbsoluteError": {
                "type": [
                  "number",
                  "null"
                ],
                "description": "Mean gap on the 1 to 5 scale, checked leave-one-out. `null` below 2 People."
              },
              "map": {
                "type": "array",
                "minItems": 5,
                "maxItems": 5,
                "items": {
                  "type": "number"
                },
                "description": "The calibrated score for raw scores 1 to 5."
              },
              "computedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "published": {
                "type": "boolean",
                "description": "`true` once `n` reaches `minimumN`. Until then no scores are returned."
              },
              "minimumN": {
                "type": "integer",
                "description": "How many People must have both scores before estimates are published."
              }
            }
          },
          "company": {
            "type": [
              "object",
              "null"
            ],
            "description": "The Company's score: the plain mean of its People's inferred scores. `null` when there is nothing to show.",
            "properties": {
              "score": {
                "type": "number",
                "description": "1 to 5, one decimal."
              },
              "people": {
                "type": "integer"
              },
              "positive": {
                "type": "integer"
              },
              "neutral": {
                "type": "integer"
              },
              "negative": {
                "type": "integer"
              }
            }
          },
          "people": {
            "type": "array",
            "description": "Each Person's estimate beside their latest surveyed score, most negative first.",
            "items": {
              "type": "object",
              "properties": {
                "personId": {
                  "type": "string",
                  "format": "uuid"
                },
                "name": {
                  "type": "string"
                },
                "score": {
                  "type": "number",
                  "description": "Calibrated, 1 to 5, one decimal."
                },
                "band": {
                  "type": "string",
                  "enum": [
                    "negative",
                    "neutral",
                    "positive"
                  ]
                },
                "confidence": {
                  "type": "string",
                  "enum": [
                    "low",
                    "medium",
                    "high"
                  ]
                },
                "reason": {
                  "type": "string"
                },
                "evidenceCount": {
                  "type": "integer"
                },
                "lastEvidenceAt": {
                  "type": "string"
                },
                "surveyed": {
                  "type": [
                    "object",
                    "null"
                  ],
                  "description": "The Person's latest surveyed score in the rollup window, never merged with the estimate.",
                  "properties": {
                    "measure": {
                      "type": "string",
                      "enum": [
                        "nps",
                        "csat",
                        "ces"
                      ]
                    },
                    "score": {
                      "type": "integer"
                    },
                    "scaleMax": {
                      "type": "integer"
                    },
                    "answeredAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Companies",
      "description": "Read and manage canonical company records."
    },
    {
      "name": "Signals",
      "description": "Read, create, and manage buyer / risk signals."
    },
    {
      "name": "Ingest",
      "description": "Push product-usage and metric events into GainTrace."
    },
    {
      "name": "Contacts",
      "description": "The original path for People. It shares its handlers with /people, and also offers delete-by-key."
    },
    {
      "name": "Webhooks",
      "description": "Subscribe to workspace events with signed, retried delivery."
    },
    {
      "name": "People",
      "description": "Read and manage People. One Person can belong to many Companies."
    },
    {
      "name": "NPS responses",
      "description": "Import NPS scores from another survey tool and read your NPS history."
    },
    {
      "name": "Surveys",
      "description": "Create and launch surveys, request invitations, record responses and mint in-app sessions."
    },
    {
      "name": "Survey responses",
      "description": "Read the responses collected by your surveys."
    },
    {
      "name": "Survey segments",
      "description": "Save groups of Companies and People that surveys can target."
    },
    {
      "name": "Survey imports",
      "description": "Pull responses from the survey tools your workspace has connected."
    }
  ]
}
