> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gaintrace.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Record a survey response

> 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`.

**Scope:** `write:surveys`



## OpenAPI

````yaml /openapi.json post /surveys/{id}/responses
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.


    All endpoints are authenticated with a Bearer API key and scoped to a single
    workspace.


    Each 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: []
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.
paths:
  /surveys/{id}/responses:
    post:
      tags:
        - Surveys
      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`.


        **Scope:** `write:surveys`
      operationId: recordSurveyResponse
      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:
        '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
        '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
        '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'
components:
  parameters:
    surveyId:
      name: id
      in: path
      required: true
      description: The survey's UUID.
      schema:
        type: string
        format: uuid
  schemas:
    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.
    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
              maxLength: 255
              minLength: 1
            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
              maxLength: 255
              minLength: 1
    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.
  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
    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
    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
  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.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.