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

# Record a correction to a registered contract

> Records a correction to something the client already asserted about a registered contract, and publishes the fact that names it.

This is NOT a Dataprev operation: no rail credential is used and no government boundary is crossed. Manual 005 revision 1.13 states the rail's retification fields are no longer used and always return null, so the client is the only authority a correction can have — `source_authority` is always `client`.

NOTHING IS MUTATED. A correction is an append that names what it supersedes, and the record it corrects stays immutable in the database exactly as it was. Correcting the same thing twice appends a second correction that supersedes the first.

The gateway takes custody of the corrected resource and computes its SHA-256 itself; a client-declared digest is never accepted. The published fact carries a same-origin path back to this gateway plus that digest, and the consumer fetches and verifies it over authenticated M2M.

| correction_type | payment_reference | supersedes |
|---|---|---|
| `ccb` | must be empty | the previous CCB correction, or nothing on the first |
| `disbursement` | required | the confirmed payment it repairs, then the previous correction of that payment |

A disbursement correction naming a payment this deployment holds no confirmation for is refused with 404: a supersession pointing at nothing is worse than no correction.

X-Idempotency is mandatory, opaque, 1..128 bytes, and never defaulted. PostgreSQL is the authority: the same key replays the identical 202 body and publishes no second fact, and the same key carrying a different correction answers 422 without ever returning the earlier body.



## OpenAPI

````yaml en/openapi/v3-current/consignado.yaml post /v1/consignado/contracts/{numero_contrato}/corrections
openapi: 3.1.0
info:
  contact:
    email: contact@lerian.studio
    name: Lerian Studio
    url: https://lerian.studio
  description: >-
    OpenAPI 3.1 surface for Lerian Consignado — Dataprev. The API covers tenant
    credentials and rail configuration, worker margin, loan auctions and bids,
    contract registration and lifecycle, disbursement confirmation, portability,
    refinancing, renegotiation, FGTS guarantees, reconciliation, funds,
    assignments, usage, throughput, and event subscriptions. Secret material is
    written to the tenant secret store and is never returned by any operation.
  license:
    name: Lerian Studio General License
  title: Lerian Consignado API
  version: v1.0.0
servers:
  - url: https://br-consignado-gw.sandbox.lerian.net
security:
  - BearerAuth: []
tags:
  - description: >-
      Per-tenant Dataprev credential custody and public rail configuration
      (upload, status, rotation, revoke, requester code, and worker portal base
      URL)
    name: Credentials
  - description: >-
      Tenant-scoped consignado gateway usage: priced billable-unit aggregation
      per competência
    name: Consignado Usage
  - description: >-
      Per-tenant streaming-hub subscription control-plane (list, create, get,
      rotate, revoke, and test delivery)
    name: Subscriptions
  - description: >-
      Dataprev payroll-rail surface: FGTS balance and authorization reads, the
      FGTS guarantee execution, contract suspension, reactivation and term
      changes, the rail's own contract documents, and the on-demand reads of
      leilão solicitações, escriturações, repasses and employment terminations
    name: Consignado Rail
  - description: >-
      Synchronous rail command surface: the operations a bancarizador without
      the lender drives over HTTP. Each shares its command implementation with
      the equivalent lender event trigger.
    name: Consignado Rail Commands
  - description: >-
      Gateway-owned disbursement confirmation: a client bank recording money it
      has ALREADY paid to a worker. It crosses no government boundary and
      proxies no Dataprev operation.
    name: Consignado Disbursement
  - description: >-
      Per-tenant self-service outbound Dataprev rail throughput: read and set
      this tenant's own requests-per-second, including a deliberate pause at
      zero
    name: Consignado Throughput
paths:
  /v1/consignado/contracts/{numero_contrato}/corrections:
    post:
      tags:
        - Consignado Corrections
      summary: Record a correction to a registered contract
      description: >-
        Records a correction to something the client already asserted about a
        registered contract, and publishes the fact that names it.


        This is NOT a Dataprev operation: no rail credential is used and no
        government boundary is crossed. Manual 005 revision 1.13 states the
        rail's retification fields are no longer used and always return null, so
        the client is the only authority a correction can have —
        `source_authority` is always `client`.


        NOTHING IS MUTATED. A correction is an append that names what it
        supersedes, and the record it corrects stays immutable in the database
        exactly as it was. Correcting the same thing twice appends a second
        correction that supersedes the first.


        The gateway takes custody of the corrected resource and computes its
        SHA-256 itself; a client-declared digest is never accepted. The
        published fact carries a same-origin path back to this gateway plus that
        digest, and the consumer fetches and verifies it over authenticated M2M.


        | correction_type | payment_reference | supersedes |

        |---|---|---|

        | `ccb` | must be empty | the previous CCB correction, or nothing on the
        first |

        | `disbursement` | required | the confirmed payment it repairs, then the
        previous correction of that payment |


        A disbursement correction naming a payment this deployment holds no
        confirmation for is refused with 404: a supersession pointing at nothing
        is worse than no correction.


        X-Idempotency is mandatory, opaque, 1..128 bytes, and never defaulted.
        PostgreSQL is the authority: the same key replays the identical 202 body
        and publishes no second fact, and the same key carrying a different
        correction answers 422 without ever returning the earlier body.
      operationId: recordConsignadoContractCorrection
      parameters:
        - description: >-
            The rail contract number the correction is about. Exact,
            control-free UTF-8, bounded in BYTES: 2..15, which is the consumer's
            own bound for this field.
          in: path
          name: numero_contrato
          required: true
          schema:
            description: >-
              The rail contract number the correction is about. Exact,
              control-free UTF-8, bounded in BYTES: 2..15, which is the
              consumer's own bound for this field.
            examples:
              - 99999999999AN1
            maxLength: 15
            minLength: 2
            type: string
        - description: >-
            Mandatory opaque replay key, 1..128 bytes of valid UTF-8, preserved
            byte for byte. No default, no alias header, no case folding: two
            keys differing in one byte are two keys.
          in: header
          name: X-Idempotency
          required: true
          schema:
            description: >-
              Mandatory opaque replay key, 1..128 bytes of valid UTF-8,
              preserved byte for byte. No default, no alias header, no case
              folding: two keys differing in one byte are two keys.
            examples:
              - idem-correcao-0001
            maxLength: 128
            minLength: 1
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractCorrectionRequest'
        required: true
      responses:
        '202':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractCorrectionResponse'
          description: >-
            The correction is durably recorded and its fact queued. A replay
            under the same key answers with the identical body.
        '401':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Authentication is required to access this resource.
        '403':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: You do not have permission to access this resource.
        '404':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: >-
            A disbursement correction named a payment reference this deployment
            holds no confirmation for.
        '409':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: >-
            Another correction already supersedes the same event. The chain is a
            list, not a tree: re-read the head and retry.
        '422':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: >-
            The transport key, the contract number or the body is refused. A key
            that already bought a DIFFERENT correction lands here too, and the
            earlier body is never returned.
        '501':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: This deployment does not record contract corrections.
        '503':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Contract correction persistence is temporarily unavailable.
      security:
        - BearerAuth: []
components:
  schemas:
    ContractCorrectionRequest:
      additionalProperties: false
      properties:
        content_type:
          description: >-
            Media type of the corrected resource. Its media type must be
            application/pdf or application/zip — parameters are permitted — and
            the bytes are sniffed against it.
          examples:
            - application/pdf
          maxLength: 128
          type: string
        correction_type:
          description: >-
            What this correction corrects. Selects which fact is published; the
            payload shape is identical for both.
          enum:
            - ccb
            - disbursement
          examples:
            - ccb
          type: string
        file_name:
          description: Original file name of the corrected resource.
          examples:
            - ccb-corrigida.pdf
          maxLength: 255
          type: string
        payment_reference:
          description: >-
            The payment_reference of the confirmed disbursement this correction
            repairs. Required when correction_type is disbursement, and must be
            empty otherwise.
          examples:
            - E32074986202608011200A1B2C3D4E5F
          maxLength: 256
          type: string
        resource_base64:
          description: >-
            Canonical base64 of the corrected resource. The gateway computes the
            SHA-256 itself; no client-declared digest is accepted.
          examples:
            - JVBERi0xLjcKJSVFT0Y=
          maxLength: 8388608
          type: string
      required:
        - content_type
        - correction_type
        - file_name
        - payment_reference
        - resource_base64
      type: object
    ContractCorrectionResponse:
      additionalProperties: false
      properties:
        correction_id:
          description: >-
            The gateway's identity for this correction. It is also the published
            event id.
          examples:
            - 1f5b9c26-6f5a-4f77-9c1c-5d1c0f0a9b21
          type: string
        correction_type:
          description: What was corrected.
          examples:
            - ccb
          type: string
        gateway_received_at:
          description: When the gateway took custody, strict RFC 3339 UTC.
          examples:
            - '2026-08-29T12:00:05Z'
          type: string
        numero_contrato:
          description: The rail contract number, echoed from the path.
          examples:
            - 99999999999AN1
          type: string
        resource_digest_sha256:
          description: Lowercase hex SHA-256 the gateway computed over the corrected bytes.
          examples:
            - e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
          type: string
        resource_uri:
          description: >-
            Same-origin relative path serving the corrected resource under M2M
            bearer auth.
          examples:
            - >-
              /v1/consignado/contracts/99999999999AN1/corrections/1f5b9c26-6f5a-4f77-9c1c-5d1c0f0a9b21
          type: string
        source_authority:
          description: >-
            Who is authoritative for the corrected value. Always client on this
            gateway.
          examples:
            - client
          type: string
        supersedes_event_id:
          description: >-
            The event id this correction supersedes: the corrected disbursement
            confirmation, or the previous correction. ABSENT on a first CCB
            correction, meaning the original contract fact.
          examples:
            - 7c2a1b40-11f4-4a1e-9a44-1f4d7cbb8e02
          type: string
      required:
        - correction_id
        - numero_contrato
        - correction_type
        - source_authority
        - resource_uri
        - resource_digest_sha256
        - gateway_received_at
      type: object
    Detail:
      additionalProperties: false
      properties:
        code:
          description: >-
            Stable, machine-readable domain error code scoped to the emitting
            service (format: <SERVICE>-NNNN).
          examples:
            - ERR-0001
          type: string
        detail:
          description: >-
            A human-readable explanation specific to this occurrence of the
            problem.
          examples:
            - Property foo is required but is missing.
          type: string
        errors:
          description: Optional list of individual error details
          items:
            $ref: '#/components/schemas/ErrorDetail'
          type:
            - array
            - 'null'
        instance:
          description: >-
            A URI reference that identifies the specific occurrence of the
            problem.
          examples:
            - https://example.com/error-log/abc123
          format: uri
          type: string
        status:
          description: HTTP status code
          examples:
            - 400
          format: int64
          type: integer
        title:
          description: >-
            A short, human-readable summary of the problem type. This value
            should not change between occurrences of the error.
          examples:
            - Bad Request
          type: string
        type:
          default: about:blank
          description: A URI reference to human-readable documentation for the error.
          examples:
            - https://example.com/errors/example
          format: uri
          type: string
        upstream:
          $ref: '#/components/schemas/Upstream'
          description: >-
            RFC 9457 extension member: the error a proxied third-party provider
            reported. Absent unless the emitting service explicitly surfaced
            one.
      type: object
    ErrorDetail:
      additionalProperties: false
      properties:
        location:
          description: >-
            Where the error occurred, e.g. 'body.items[3].tags' or
            'path.thing-id'
          type: string
        message:
          description: Error message text
          type: string
        value:
          description: The value at the given location
      type: object
    Upstream:
      additionalProperties: false
      properties:
        code:
          description: The upstream provider's own error code, verbatim.
          examples:
            - E4001
          type: string
        message:
          description: >-
            The upstream provider's own error message, verbatim (bounded, never
            its raw response body).
          examples:
            - account not found at provider
          type: string
      type: object
  securitySchemes:
    BearerAuth:
      bearerFormat: JWT
      description: JWT bearer token issued by the identity provider.
      scheme: bearer
      type: http

````