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

# Update document

> Create or update a document record directly. Used to manually set document metadata outside of the template trigger workflow — for example registering an externally produced file, or correcting metadata on an existing record.

The `key` is required and derives the document's storage subject. This is an upsert: it creates the record if absent and merges supplied fields if present.



## OpenAPI

````yaml /api-reference/endpoint/documents/openapi.json patch /file-generator/documents/{key}
openapi: 3.1.0
info:
  title: Documents API
  description: >-
    Document templates, generated documents, e-signature requests, and checkbox
    approvals. Template and document routes are served under `/file-generator`,
    approval routes under `/workspaces/approvals`.
  version: 1.2.0
servers:
  - url: https://api.quiva.ai
    description: Production API server
security:
  - bearerAuth: []
  - apiKeyAuth: []
tags:
  - name: Templates
    description: >-
      Template lifecycle — create, read, publish, validate, trigger, and delete
      document templates. Templates follow a **draft → published** model: writes
      (`POST`, `PATCH`) always target the draft version, and `POST
      /templates/{key}/publish` promotes the draft. Document generation only
      ever uses the published version, so drafts can be edited safely without
      affecting production output. A template's `source` is a DOCX file
      containing angular-expression tags rendered at trigger time.
  - name: Documents
    description: >-
      Document lifecycle — read, update, and delete generated documents. A
      document record is created immediately when a template is triggered and is
      updated asynchronously: first with the generated `output.key` (an `obj://`
      or `kv://` storage URI) or `errors`, then with `signatures` progress as
      signatories sign.
  - name: Signatures
    description: >-
      E-signature workflows powered by HelloSign (Dropbox Sign). Signature
      requests are created automatically when a triggered template defines
      `signatories`. Each signatory tracks a status lifecycle of `DRAFT → SENT →
      SIGNED`, with `EXPIRED` (validity window elapsed) and `FAILED`
      (delivery/signing error) as terminal failure states. Embedded signing URLs
      can be generated for signatures created in embedded mode.
  - name: Approvals
    description: Checkbox approval of a workspace file, recorded as e-signature evidence.
  - name: Generation
  - name: Template Source
paths:
  /file-generator/documents/{key}:
    patch:
      tags:
        - Documents
      summary: Update document
      description: >-
        Create or update a document record directly. Used to manually set
        document metadata outside of the template trigger workflow — for example
        registering an externally produced file, or correcting metadata on an
        existing record.


        The `key` is required and derives the document's storage subject. This
        is an upsert: it creates the record if absent and merges supplied fields
        if present.
      operationId: upsertDocument
      parameters:
        - $ref: '#/components/parameters/DocumentKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpsertDocumentRequest'
            example:
              key: contracts/acme-nda-2024.docx
              name: Acme NDA 2024
              template:
                key: nda-template
      responses:
        '200':
          description: Document updated successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SubjectResponse'
              example:
                subject: ms.document.document.contracts.acme-nda-2024.docx
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '500':
          $ref: '#/components/responses/ServerError'
components:
  parameters:
    DocumentKey:
      name: key
      in: path
      required: true
      description: Unique document key, typically a file path.
      schema:
        type: string
        example: contracts/acme-nda-2024.docx
  schemas:
    UpsertDocumentRequest:
      type: object
      required:
        - key
      properties:
        key:
          type: string
          description: Document key — used to derive the storage subject.
          example: contracts/acme-nda-2024.docx
        created_at:
          type: string
          format: date-time
        name:
          type: string
          example: Acme NDA 2024
        output:
          type:
            - object
            - 'null'
          properties:
            key:
              type: string
              example: obj://microstrate-documents/contracts/acme-nda-2024.pdf
        template:
          type: object
          properties:
            key:
              type: string
              example: nda-template
        signatures:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/DocumentSignatory'
        errors:
          type:
            - array
            - 'null'
          items:
            type: string
    SubjectResponse:
      type: object
      properties:
        subject:
          type: string
          description: >-
            Messaging subject of the created or updated record. Formats: draft
            template `ms.document.draft.template.{key}`, published template
            `ms.document.template.{key}`, document `ms.document.document.{key}`
            — with keys sanitised into subject tokens (`/` → `.`, spaces → `_`,
            other special characters → `uXXXX` codes).
          example: ms.document.draft.template.invoice-template
    DocumentSignatory:
      type: object
      required:
        - name
        - email
        - expiry
        - status
      properties:
        name:
          type: string
          example: Jane Smith
        email:
          type: string
          format: email
          example: jane@acme.com
        expiry:
          type: string
          format: date-time
          description: ISO 8601 datetime after which the signing request expires.
          example: '2024-03-22T10:30:00Z'
        status:
          type: string
          enum:
            - DRAFT
            - SENT
            - SIGNED
            - EXPIRED
            - FAILED
          description: Current signing status.
          example: SIGNED
        order:
          type: integer
          description: Signing order index (0-based).
          example: 0
        signed_at:
          type:
            - string
            - 'null'
          format: date-time
          description: ISO 8601 datetime when the signatory signed. Null if not yet signed.
          example: '2024-03-16T14:22:10Z'
        request:
          allOf:
            - $ref: '#/components/schemas/DocumentSignatoryRequest'
        error:
          type:
            - string
            - 'null'
          description: Error message if the signature request failed.
          example: null
      description: >-
        Per-signatory e-signature state on a document. Status lifecycle: `DRAFT`
        (created at trigger time, request not yet sent) → `SENT` (HelloSign
        request dispatched; `request` populated) → `SIGNED`, or `EXPIRED`
        (validity window elapsed — an expiry cron marks the signature and
        cancels the HelloSign request) / `FAILED` (delivery or signing error —
        see `error`). The `expiry` timestamp is computed at trigger time as now
        + the template signatory's `validity`.
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
          example: '"key" is required'
    DocumentSignatoryRequest:
      type: object
      description: >-
        Signature request object attached to the signatory after a HelloSign
        request is sent.
      properties:
        id:
          type: string
          description: HelloSign signature request ID.
          example: sr_abc123
        signature_id:
          type: string
          description: HelloSign per-signatory signature ID.
          example: hs_sig_xyz789
        is_embedded:
          type: boolean
          description: Whether the signing is done via an embedded iframe.
          example: true
  responses:
    BadRequest:
      description: Invalid or missing request parameters.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error: '"key" is required'
    Unauthorized:
      description: Missing or invalid Authorization header.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error: Authorization header with a bearer token is required
    ServerError:
      description: Internal server error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error: server error
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key

````

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