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

# Create or update a document

> Creates the document with this `external_id`, or updates it. Returns it with `result`: created (201), updated or unchanged. A document is identified by your `external_id`, unique in its knowledge base (titles may repeat). Its words are stored and indexed in the background: the previous version keeps answering until the new one is ready. The same words, title and link again are `unchanged`: nothing is written or indexed again. A 503 that says the document was saved but its indexing could not be started: send it again, and indexing is asked for again. Writes go into a knowledge base this API made or one that takes uploads in the app (`writable`); a connector's is a 409. A digital worker's own key can't write.



## OpenAPI

````yaml /api/statisfy-api.openapi.json put /v1/knowledge_bases/{knowledge_base_id}/documents
openapi: 3.1.0
info:
  description: >-
    The agent-first Statisfy API. Authenticate with an API key (`Authorization:
    Bearer stfy_live_…`), then call `GET /v1/meta/capabilities` to discover
    every operation and its schemas.
  title: Statisfy API
  version: 1.0.0
servers:
  - url: https://api.statisfy.com
    description: Production
security: []
paths:
  /v1/knowledge_bases/{knowledge_base_id}/documents:
    put:
      tags:
        - knowledge_bases
      summary: Create or update a document
      description: >-
        Creates the document with this `external_id`, or updates it. Returns it
        with `result`: created (201), updated or unchanged. A document is
        identified by your `external_id`, unique in its knowledge base (titles
        may repeat). Its words are stored and indexed in the background: the
        previous version keeps answering until the new one is ready. The same
        words, title and link again are `unchanged`: nothing is written or
        indexed again. A 503 that says the document was saved but its indexing
        could not be started: send it again, and indexing is asked for again.
        Writes go into a knowledge base this API made or one that takes uploads
        in the app (`writable`); a connector's is a 409. A digital worker's own
        key can't write.
      operationId: knowledge_bases_upsert_document
      parameters:
        - description: The knowledge base's id, from GET /v1/knowledge_bases
          in: path
          name: knowledge_base_id
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              additionalProperties: false
              properties:
                content:
                  description: >-
                    Its words, up to 256 KB (UTF-8): a larger document is
                    refused, never cut short
                  minLength: 1
                  title: Content
                  type: string
                external_id:
                  description: Your id for the document, unique in its knowledge base
                  maxLength: 200
                  minLength: 1
                  title: External Id
                  type: string
                format:
                  description: 'How content is written: markdown, html or text'
                  enum:
                    - markdown
                    - html
                    - text
                  title: Format
                  type: string
                title:
                  description: 'Its title: a worker sees it beside each passage'
                  maxLength: 500
                  minLength: 1
                  title: Title
                  type: string
                url:
                  anyOf:
                    - maxLength: 2048
                      type: string
                    - type: 'null'
                  default: null
                  description: >-
                    The link a worker gives a customer when it answers from this
                    document (an http or https URL). Without one, the worker
                    names the document without a link
                  title: Url
              required:
                - external_id
                - title
                - content
                - format
              type: object
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UpsertedDocument'
          description: Successful Response
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UpsertedDocument'
          description: Created
      security:
        - HTTPBearer: []
components:
  schemas:
    UpsertedDocument:
      properties:
        account_id:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            Set when the document is filed for one account (from GET
            /v1/objects/account/records): a worker answering that account
            searches it, one answering another account does not. Null: searched
            for every account
          title: Account Id
        created_at:
          description: ISO 8601 UTC
          title: Created At
          type: string
        error:
          anyOf:
            - type: string
            - type: 'null'
          description: Why indexing failed; null unless status is failed
          title: Error
        external_id:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            Your id for a document you pushed through this API; null for an
            upload or a connector's
          title: External Id
        format:
          description: >-
            Its file's type: pdf, docx or doc (an uploaded file); text, markdown
            or html; or another type a connector stored, such as a SharePoint
            spreadsheet or slides (xlsx, xls, pptx, ppt), which isn't indexed
          title: Format
          type: string
        id:
          title: Id
          type: string
        knowledge_base_id:
          title: Knowledge Base Id
          type: string
        result:
          description: >-
            created; updated (its words, title or link changed: new words are
            indexed again); or unchanged (the same words, title and link:
            nothing was written and nothing is indexed again)
          enum:
            - created
            - updated
            - unchanged
          title: Result
          type: string
        searchable:
          description: >-
            Whether a search finds it: true once a version is indexed, and while
            a newer version is queued, indexing or failed the previous one keeps
            answering
          title: Searchable
          type: boolean
        source:
          description: >-
            Its knowledge base's source: Where its documents come from: api
            (pushed through this API), upload (files uploaded in the app),
            team_answers (articles the team approved in the app), or the
            connector that syncs it (intercom, zendesk, notion, google_drive,
            sharepoint, website)
          title: Source
          type: string
        source_url:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            Where its connector found it (a help-center article, a page, a
            file); null otherwise
          title: Source Url
        status:
          description: >-
            queued (waiting to be indexed), indexing, ready, or failed (see
            error): how its latest version stands. `searchable` says whether a
            search finds it
          enum:
            - queued
            - indexing
            - ready
            - failed
          title: Status
          type: string
        title:
          description: >-
            Its title: a file's name for an upload, the page's or article's
            title otherwise
          title: Title
          type: string
        updated_at:
          description: 'ISO 8601 UTC: when its words or details last changed'
          title: Updated At
          type: string
        url:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            The link a worker gives a customer when it answers from this
            document; null when it has none, and the worker then names it
            without a link
          title: Url
      required:
        - id
        - knowledge_base_id
        - title
        - format
        - source
        - status
        - searchable
        - created_at
        - updated_at
        - result
      title: UpsertedDocument
      type: object
  securitySchemes:
    HTTPBearer:
      scheme: bearer
      type: http
      description: >-
        An API key, sent as `Authorization: Bearer stfy_live_…`. See
        [Authentication](/rest-api/authentication) for how to get one and which
        scopes it needs.

````

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