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

# Reassign a document schema

> Pin a published schema version onto one batch document.

Pins a different published version onto one `BatchDocument`. Does not extract by itself — follow with [Reprocess](/api-reference/batches/reprocess) if you want a fresh run.


## OpenAPI

````yaml POST /api/v2/batches/{batch_id}/documents/{doc_id}/version/
openapi: 3.1.0
info:
  title: Abacus Docs API
  version: 1.0.0
  description: |
    REST + SSE surface for Abacus Docs on the same host as the web app
    (`https://abacusdocs.com`). Paths are `/api/v2/…`.

    Authenticate with an organisation API key (`sk-abacus-*`) as a Bearer
    token, or an Auth0 access token. Cross-tenant reads return **404**, not
    403. Page-based lists use `?page=` and `?page_size=`.

    Extraction, reprocess, schema tests, and chat turns spend credits.
    See the help centre Credits pages for rates.
  contact:
    name: Abacus Docs
    url: https://abacusdocs.com/contact
servers:
  - url: https://abacusdocs.com
    description: Production (Extract)
security: []
paths:
  /api/v2/batches/{batch_id}/documents/{doc_id}/version/:
    post:
      tags:
        - v2/batches
      summary: Reassign a single BatchDocument's StructVersion
      description: >-
        Repoints a single ``BatchDocument.struct_version`` at a different
        published version of the batch's parent struct. Only PENDING / FAILED
        docs accept reassignment — PROCESSING and COMPLETED return 409 (the
        extraction has already started or finished; changing the schema
        mid-flight would yield an ambiguous result).


        Validation:

        - The doc must already have a ``struct_version`` (plain   no-schema docs
        return 400).

        - The target ``version_number`` must exist on the parent   struct (404
        otherwise).

        - Deprecated versions are rejected with 400.

        - PROCESSING / COMPLETED docs return 409 (the doc's   extraction state
        is immutable).
      operationId: v2_batches_documents_version_create
      parameters:
        - in: path
          name: batch_id
          schema:
            type: integer
          required: true
        - in: path
          name: doc_id
          schema:
            type: integer
          required: true
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BatchVersionRequestRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BatchDocVersionReassignResponse'
          description: ''
        '400':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
        '404':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
        '409':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
      security:
        - extractApiKey: []
        - bearerAuth: []
        - cookieAuth: []
components:
  schemas:
    BatchVersionRequestRequest:
      type: object
      description: >-
        Body for batch version reassignment endpoints (Task 16).


        Accepts a single ``version_number`` field; the consuming view resolves
        it

        against the parent batch's struct and rejects deprecated versions.
      properties:
        version_number:
          type: integer
          minimum: 1
      required:
        - version_number
    BatchDocVersionReassignResponse:
      type: object
      description: >-
        Response shape for ``POST
        /api/v2/batches/{id}/documents/{doc_id}/version/``.


        Extends the summary with ``id`` (so the grid can repoint

        ``row.struct_version_id``), ``pinned_field_ids`` (the sorted list of

        field IDs in the new version's ``schema_json`` — needed by the JS grid

        so the per-row out-of-schema mask refreshes after reassignment without

        a full page reload), the per-row output-language hints

        (``output_language`` / ``output_language_label`` /

        ``output_language_is_rtl``), and ``source_languages`` /

        ``source_language_labels`` from the new version's pinned schema.


        The output-language hints are read by
        ``batch_grid.js::reassignDocVersion``

        to refresh ``row.output_language*`` after a reassignment — without

        them, a doc reassigned from a French-only version to an Arabic version

        would still render its cells LTR (the per-row RTL flag would stay

        stale until a full page reload), and the inline editor + sub-table

        modal would inherit the wrong language label too.


        AD-205 clean cut: this serializer no longer reads or emits

        ``translation_language``. Stored ``schema_json`` blobs were rewritten

        by ``backfill_schema_keys`` before deploy, so every read site can

        safely assume ``output_language`` is the only key.
      properties:
        id:
          type: integer
          readOnly: true
        version_number:
          type: integer
          maximum: 2147483647
          minimum: 0
        published_at:
          type: string
          format: date-time
          readOnly: true
        published_by:
          oneOf:
            - $ref: '#/components/schemas/_PublishedBy'
            - type: 'null'
          readOnly: true
        publish_note:
          type: string
          maxLength: 500
        field_count:
          type: integer
          readOnly: true
        is_deprecated:
          type: boolean
          readOnly: true
        deprecated_at:
          type:
            - string
            - 'null'
          format: date-time
        deprecated_by:
          oneOf:
            - $ref: '#/components/schemas/_PublishedBy'
            - type: 'null'
          readOnly: true
        deprecation_note:
          type: string
          maxLength: 500
        pinned_field_ids:
          type: array
          items:
            type: string
          readOnly: true
        output_language:
          type:
            - string
            - 'null'
          readOnly: true
        output_language_label:
          type: string
          readOnly: true
        output_language_is_rtl:
          type: boolean
          readOnly: true
        source_languages:
          type: array
          items:
            type: string
          readOnly: true
        source_language_labels:
          type: array
          items:
            type: string
          readOnly: true
      required:
        - deprecated_by
        - field_count
        - id
        - is_deprecated
        - output_language
        - output_language_is_rtl
        - output_language_label
        - pinned_field_ids
        - published_at
        - published_by
        - source_language_labels
        - source_languages
        - version_number
    _PublishedBy:
      type: object
      description: Compact projection of the user who published / deprecated a version.
      properties:
        id:
          type: integer
        email:
          type: string
          format: email
      required:
        - email
        - id
  securitySchemes:
    extractApiKey:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: |
        Organisation API key from Settings → API / `/api/keys/`. The secret is
        shown once. Send `Authorization: Bearer sk-abacus-…`. One active key
        per organisation. Ingest (`/api/v2/ingest/*`) refuses API keys — that
        surface is Auth0-only with `ingest:read` / `ingest:write` scopes.
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >
        Auth0 access token for a signed-in user. Send `Authorization: Bearer
        <token>`.

        The SPA and desktop agent use this. Prefer an organisation API key for

        server-to-server integrations.
    cookieAuth:
      type: apiKey
      in: cookie
      name: sessionid
      description: |
        Django session cookie from a browser login. Present so the web app can
        call `/api/v2` without a header. Do not rely on this for integrations.

````