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

# Replace a document

> Replace an existing document with a new file and/or updated metadata. This is useful when a document was rejected and needs to be re-uploaded. The request must use multipart/form-data.




## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/grid/openapi.documented.yml put /documents/{documentId}
openapi: 3.1.0
info:
  title: Grid API
  description: >
    API for managing global payments on the open Money Grid. Built by
    Lightspark. See the full documentation at https://docs.lightspark.com/.
  version: '2025-10-13'
  contact:
    name: Lightspark Support
    email: support@lightspark.com
  license:
    name: Proprietary
    url: https://lightspark.com/terms
servers:
  - url: https://api.lightspark.com/grid/2025-10-13
    description: Production server
security:
  - BasicAuth: []
  - AgentAuth: []
tags:
  - name: Platform Configuration
    description: >-
      Platform configuration endpoints for managing global settings. You can
      also configure these settings in the Grid dashboard.
  - name: Customers
    description: >-
      Customer management endpoints for creating and updating customer
      information
  - name: KYC/KYB Verifications
    description: >-
      Endpoints for Know Your Customer (KYC) and Know Your Business (KYB)
      verification, including managing beneficial owners and triggering
      verification for customers.
  - name: Documents
    description: >-
      Endpoints for uploading and managing verification documents for customers
      and beneficial owners. Supports KYC and KYB document requirements.
  - name: Internal Accounts
    description: >-
      Internal account management endpoints for creating and managing internal
      accounts
  - name: External Accounts
    description: >-
      External account management endpoints for creating and managing external
      bank accounts
  - name: Same-Currency Transfers
    description: >-
      Endpoints for transferring funds between internal and external accounts
      with the same currency
  - name: Cross-Currency Transfers
    description: Endpoints for creating and confirming quotes for cross-currency transfers
  - name: Transactions
    description: Endpoints for retrieving transaction information
  - name: Webhooks
    description: Webhook endpoints and configuration for receiving notifications
  - name: Invitations
    description: Endpoints for creating, claiming and managing UMA invitations
  - name: Sandbox
    description: Endpoints to trigger test cases in sandbox
  - name: API Tokens
    description: Endpoints to programmatically manage API tokens
  - name: Exchange Rates
    description: >-
      Endpoints for retrieving cached foreign exchange rates. Rates are cached
      for approximately 5 minutes and include platform-specific fees.
  - name: Discoveries
    description: >-
      Endpoints for discovering available payment rails, banks, and providers
      for a given country and currency corridor.
  - name: Embedded Wallet Auth
    description: >-
      Endpoints for registering and verifying end-user authentication
      credentials (email OTP, OAuth, passkey) used to sign Embedded Wallet
      actions.
  - name: Agent Management
    description: >-
      Endpoints for creating and managing agents (experimental), called by the
      partner's backend using platform credentials. Covers the full agent
      lifecycle: creation, policy configuration, pausing, deletion, the device
      code installation flow, and approving or rejecting transactions initiated
      by agents.
  - name: Agent Operations
    description: >-
      Endpoints called by the agent itself using its own credentials (obtained
      via device code redemption). Scoped to the agent's associated customer —
      all requests automatically operate on behalf of that customer and are
      subject to the agent's policy. When an action requires approval, the
      resulting transaction enters a pending state and must be approved by the
      platform via `POST /transactions/{transactionId}/approve`.
  - name: Cards
    description: >-
      Card management endpoints. Issue debit cards against an internal account,
      freeze / unfreeze, close, manage card funding sources, and list card
      transactions.
paths:
  /documents/{documentId}:
    put:
      tags:
        - Documents
      summary: Replace a document
      description: >
        Replace an existing document with a new file and/or updated metadata.
        This is useful when a document was rejected and needs to be re-uploaded.
        The request must use multipart/form-data.
      operationId: replaceDocument
      parameters:
        - name: documentId
          in: path
          description: Document ID
          required: true
          schema:
            type: string
      requestBody:
        $ref: '#/components/requestBodies/DocumentReplaceRequestBody'
      responses:
        '200':
          description: Document replaced successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Document'
        '400':
          description: Bad request - Invalid file type, size, or parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error400'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error401'
        '404':
          description: Document not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error404'
        '500':
          description: Internal service error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error500'
      security:
        - BasicAuth: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import LightsparkGrid from '@lightsparkdev/grid';

            const client = new LightsparkGrid({
              username: process.env['GRID_CLIENT_ID'], // This is the default and can be omitted
              password: process.env['GRID_CLIENT_SECRET'], // This is the default and can be omitted
            });

            const document = await client.documents.replace('documentId', {
              DocumentReplaceRequest: {
                country: 'US',
                documentType: 'PASSPORT',
                file: fs.createReadStream('path/to/file'),
              },
            });

            console.log(document.id);
        - lang: Python
          source: |-
            import os
            from grid import LightsparkGrid

            client = LightsparkGrid(
                username=os.environ.get("GRID_CLIENT_ID"),  # This is the default and can be omitted
                password=os.environ.get("GRID_CLIENT_SECRET"),  # This is the default and can be omitted
            )
            document = client.documents.replace(
                document_id="documentId",
                document_replace_request={
                    "country": "US",
                    "document_type": "PASSPORT",
                    "file": b"Example data",
                },
            )
            print(document.id)
        - lang: Go
          source: "package main\n\nimport (\n\t\"bytes\"\n\t\"context\"\n\t\"fmt\"\n\t\"io\"\n\n\t\"github.com/stainless-sdks/grid-go\"\n\t\"github.com/stainless-sdks/grid-go/option\"\n)\n\nfunc main() {\n\tclient := grid.NewClient(\n\t\toption.WithUsername(\"My Username\"),\n\t\toption.WithPassword(\"My Password\"),\n\t)\n\tdocument, err := client.Documents.Replace(\n\t\tcontext.TODO(),\n\t\t\"documentId\",\n\t\tgrid.DocumentReplaceParams{\n\t\t\tDocumentReplaceRequest: grid.DocumentReplaceParamsDocumentReplaceRequest{\n\t\t\t\tCountry:      \"US\",\n\t\t\t\tDocumentType: \"PASSPORT\",\n\t\t\t\tFile:         io.Reader(bytes.NewBuffer([]byte(\"Example data\"))),\n\t\t\t},\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", document.ID)\n}\n"
        - lang: Kotlin
          source: |-
            package com.lightspark.grid.example

            import com.lightspark.grid.client.LightsparkGridClient
            import com.lightspark.grid.client.okhttp.LightsparkGridOkHttpClient
            import com.lightspark.grid.models.documents.Document
            import com.lightspark.grid.models.documents.DocumentReplaceParams
            import java.io.ByteArrayInputStream

            fun main() {
                val client: LightsparkGridClient = LightsparkGridOkHttpClient.fromEnv()

                val params: DocumentReplaceParams = DocumentReplaceParams.builder()
                    .documentId("documentId")
                    .country("US")
                    .documentType(DocumentReplaceParams.DocumentType.PASSPORT)
                    .file("Example data".byteInputStream())
                    .build()
                val document: Document = client.documents().replace(params)
            }
        - lang: Ruby
          source: >-
            require "grid"


            lightspark_grid = Grid::Client.new(username: "My Username",
            password: "My Password")


            document = lightspark_grid.documents.replace(
              "documentId",
              document_replace_request: {country: "US", documentType: :PASSPORT, file: StringIO.new("Example data")}
            )


            puts(document)
        - lang: PHP
          source: |-
            <?php

            require_once dirname(__DIR__) . '/vendor/autoload.php';

            use Grid\Client;
            use Grid\Core\FileParam;
            use Grid\Core\Exceptions\APIException;

            $client = new Client(
              username: getenv('GRID_CLIENT_ID') ?: 'My Username',
              password: getenv('GRID_CLIENT_SECRET') ?: 'My Password',
            );

            try {
              $document = $client->documents->replace(
                'documentId',
                documentReplaceRequest: [
                  'country' => 'US',
                  'documentType' => 'PASSPORT',
                  'file' => FileParam::fromString('Example data', filename: uniqid('file-upload-', true)),
                  'documentNumber' => 'A12345678',
                  'issuingAuthority' => 'U.S. Department of State',
                  'side' => 'FRONT',
                ],
              );

              var_dump($document);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: C#
          source: |-
            using System;
            using System.Text;
            using Grid;
            using Grid.Models.Documents;

            LightsparkGridClient client = new();

            DocumentReplaceParams parameters = new()
            {
                DocumentID = "documentId",
                DocumentReplaceRequest = new()
                {
                    Country = "US",
                    DocumentType = DocumentType.Passport,
                    File = Encoding.UTF8.GetBytes("Example data"),
                    DocumentNumber = "A12345678",
                    IssuingAuthority = "U.S. Department of State",
                    Side = Side.Front,
                },
            };

            var document = await client.Documents.Replace(parameters);

            Console.WriteLine(document);
        - lang: CLI
          source: |-
            grid documents replace \
              --username 'My Username' \
              --password 'My Password' \
              --document-id documentId \
              --document-replace-request '{country: US, documentType: PASSPORT, file: Example data}'
components:
  requestBodies:
    DocumentReplaceRequestBody:
      required: true
      content:
        multipart/form-data:
          schema:
            $ref: '#/components/schemas/DocumentReplaceRequest'
  schemas:
    Document:
      type: object
      required:
        - id
        - documentHolder
        - documentType
        - country
        - fileName
        - createdAt
      properties:
        id:
          type: string
          description: Unique identifier for this document
          example: Document:019542f5-b3e7-1d02-0000-000000000001
        documentHolder:
          type: string
          description: >-
            ID of the entity that owns this document. Can be a Customer ID or a
            BeneficialOwner ID.
          example: BeneficialOwner:019542f5-b3e7-1d02-0000-000000000001
        documentType:
          $ref: '#/components/schemas/DocumentType'
        side:
          type: string
          enum:
            - FRONT
            - BACK
          description: >-
            Which side of the document this upload represents. Relevant for
            two-sided documents like driver's licenses or national IDs.
          example: FRONT
        country:
          type: string
          description: Country that issued the document (ISO 3166-1 alpha-2)
          example: US
        documentNumber:
          type: string
          description: Document identification number (e.g., passport number)
          example: A12345678
        issuingAuthority:
          type: string
          description: >-
            Name of the government agency or organization that issued the
            document
          example: U.S. Department of State
        fileName:
          type: string
          description: Original file name of the uploaded document
          example: passport_scan.pdf
        createdAt:
          type: string
          format: date-time
          description: When this document was uploaded
          example: '2025-10-03T12:00:00Z'
        updatedAt:
          type: string
          format: date-time
          description: When this document was last updated
          example: '2025-10-03T12:00:00Z'
    Error400:
      type: object
      required:
        - message
        - status
        - code
      properties:
        status:
          type: integer
          enum:
            - 400
          description: HTTP status code
        code:
          type: string
          description: >
            | Error Code | Description |

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

            | INVALID_INPUT | Invalid input provided |

            | MISSING_MANDATORY_USER_INFO | Required customer information is
            missing |

            | INVITATION_ALREADY_CLAIMED | Invitation has already been claimed |

            | INVITATIONS_NOT_CONFIGURED | Invitations are not configured |

            | INVALID_UMA_ADDRESS | UMA address format is invalid |

            | INVITATION_CANCELLED | Invitation has been cancelled |

            | QUOTE_REQUEST_FAILED | An issue occurred during the quote process;
            this is retryable |

            | INVALID_PAYREQ_RESPONSE | Counterparty Payreq response was invalid
            |

            | INVALID_RECEIVER | Receiver is invalid |

            | PARSE_PAYREQ_RESPONSE_ERROR | Error parsing receiver PayReq
            response |

            | CERT_CHAIN_INVALID | Counterparty certificate chain is invalid |

            | CERT_CHAIN_EXPIRED | Counterparty certificate chain has expired |

            | INVALID_PUBKEY_FORMAT | Counterparty Public key format is invalid
            |

            | MISSING_REQUIRED_UMA_PARAMETERS | Counterparty required UMA
            parameters are missing |

            | SENDER_NOT_ACCEPTED | Sender is not accepted |

            | AMOUNT_OUT_OF_RANGE | Amount is out of range |

            | INVALID_CURRENCY | Currency is invalid |

            | INVALID_TIMESTAMP | Timestamp is invalid |

            | INVALID_NONCE | Nonce is invalid |

            | INVALID_REQUEST_FORMAT | Request format is invalid |

            | INVALID_BANK_ACCOUNT | Bank account is invalid |

            | SELF_PAYMENT | Self payment not allowed |

            | LOOKUP_REQUEST_FAILED | Lookup request failed |

            | PARSE_LNURLP_RESPONSE_ERROR | Error parsing LNURLP response |

            | INVALID_AMOUNT | Amount is invalid |

            | WEBHOOK_ENDPOINT_NOT_SET | Webhook endpoint is not set |

            | WEBHOOK_DELIVERY_ERROR | Webhook delivery error |

            | LOW_QUALITY | Document quality too low to process |

            | DATA_MISMATCH | Document details don't match provided information
            |

            | EXPIRED | Document has expired |

            | SUSPECTED_FRAUD | Document suspected of being forged or edited |

            | UNSUITABLE_DOCUMENT | Document type is not accepted or not
            supported |

            | INCOMPLETE | Document is missing pages or sides |

            | EMAIL_OTP_CREDENTIAL_ALREADY_EXISTS | An EMAIL_OTP credential is
            already registered on the target internal account; only one email
            OTP credential is supported per internal account at this time |

            | PASSKEY_CREDENTIAL_ALREADY_EXISTS | A PASSKEY credential with the
            same WebAuthn credentialId is already registered on the target
            internal account |
          enum:
            - INVALID_INPUT
            - MISSING_MANDATORY_USER_INFO
            - INVITATION_ALREADY_CLAIMED
            - INVITATIONS_NOT_CONFIGURED
            - INVALID_UMA_ADDRESS
            - INVITATION_CANCELLED
            - QUOTE_REQUEST_FAILED
            - INVALID_PAYREQ_RESPONSE
            - INVALID_RECEIVER
            - PARSE_PAYREQ_RESPONSE_ERROR
            - CERT_CHAIN_INVALID
            - CERT_CHAIN_EXPIRED
            - INVALID_PUBKEY_FORMAT
            - MISSING_REQUIRED_UMA_PARAMETERS
            - SENDER_NOT_ACCEPTED
            - AMOUNT_OUT_OF_RANGE
            - INVALID_CURRENCY
            - INVALID_TIMESTAMP
            - INVALID_NONCE
            - INVALID_REQUEST_FORMAT
            - INVALID_BANK_ACCOUNT
            - SELF_PAYMENT
            - LOOKUP_REQUEST_FAILED
            - PARSE_LNURLP_RESPONSE_ERROR
            - INVALID_AMOUNT
            - WEBHOOK_ENDPOINT_NOT_SET
            - WEBHOOK_DELIVERY_ERROR
            - LOW_QUALITY
            - DATA_MISMATCH
            - EXPIRED
            - SUSPECTED_FRAUD
            - UNSUITABLE_DOCUMENT
            - INCOMPLETE
            - EMAIL_OTP_CREDENTIAL_ALREADY_EXISTS
            - PASSKEY_CREDENTIAL_ALREADY_EXISTS
        message:
          type: string
          description: Error message
        details:
          type: object
          description: Additional error details
          additionalProperties: true
    Error401:
      type: object
      required:
        - message
        - status
        - code
      properties:
        status:
          type: integer
          enum:
            - 401
          description: HTTP status code
        code:
          type: string
          description: >
            | Error Code | Description |

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

            | UNAUTHORIZED | Issue with API credentials |

            | INVALID_SIGNATURE | Signature header is invalid |

            | WALLET_SIGNATURE_MISSING | The `Grid-Wallet-Signature` header is
            required for this Embedded Wallet action but was not supplied |

            | WALLET_SIGNATURE_MALFORMED | The `Grid-Wallet-Signature` header
            could not be parsed (bad encoding, structure, or fields) |

            | WALLET_SIGNATURE_BODY_MISMATCH | The `Grid-Wallet-Signature` was
            computed over a different request body than the one received |

            | WALLET_SIGNATURE_INVALID | The `Grid-Wallet-Signature` failed
            cryptographic verification against the registered credential |

            | REQUEST_ID_MISSING | The `Request-Id` header is required on the
            signed retry but was not supplied (paired with
            `Grid-Wallet-Signature`) |
          enum:
            - UNAUTHORIZED
            - INVALID_SIGNATURE
            - WALLET_SIGNATURE_MISSING
            - WALLET_SIGNATURE_MALFORMED
            - WALLET_SIGNATURE_BODY_MISMATCH
            - WALLET_SIGNATURE_INVALID
            - REQUEST_ID_MISSING
        message:
          type: string
          description: Error message
        details:
          type: object
          description: Additional error details
          additionalProperties: true
    Error404:
      type: object
      required:
        - message
        - status
        - code
      properties:
        status:
          type: integer
          enum:
            - 404
          description: HTTP status code
        code:
          type: string
          description: >
            | Error Code | Description |

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

            | TRANSACTION_NOT_FOUND | Transaction not found |

            | INVITATION_NOT_FOUND | Invitation not found |

            | USER_NOT_FOUND | Customer not found |

            | QUOTE_NOT_FOUND | Quote not found |

            | LOOKUP_REQUEST_NOT_FOUND | Lookup request not found |

            | TOKEN_NOT_FOUND | Token not found |

            | BULK_UPLOAD_JOB_NOT_FOUND | Bulk upload job not found |

            | REFERENCE_NOT_FOUND | Reference not found |

            | UMA_NOT_FOUND | The UMA address is well-formed but no receiver
            exists at the counterparty VASP |
          enum:
            - TRANSACTION_NOT_FOUND
            - INVITATION_NOT_FOUND
            - USER_NOT_FOUND
            - QUOTE_NOT_FOUND
            - LOOKUP_REQUEST_NOT_FOUND
            - TOKEN_NOT_FOUND
            - BULK_UPLOAD_JOB_NOT_FOUND
            - REFERENCE_NOT_FOUND
            - UMA_NOT_FOUND
        message:
          type: string
          description: Error message
        details:
          type: object
          description: Additional error details
          additionalProperties: true
    Error500:
      type: object
      required:
        - message
        - status
        - code
      properties:
        status:
          type: integer
          enum:
            - 500
          description: HTTP status code
        code:
          type: string
          description: |
            | Error Code | Description |
            |------------|-------------|
            | GRID_SWITCH_ERROR | Grid switch error |
            | INTERNAL_ERROR | Internal server or UMA error |
          enum:
            - GRID_SWITCH_ERROR
            - INTERNAL_ERROR
        message:
          type: string
          description: Error message
        details:
          type: object
          description: Additional error details
          additionalProperties: true
    DocumentReplaceRequest:
      title: Document Replace Request
      allOf:
        - $ref: '#/components/schemas/BaseDocumentRequest'
    DocumentType:
      type: string
      enum:
        - PASSPORT
        - DRIVERS_LICENSE
        - NATIONAL_ID
        - PROOF_OF_ADDRESS
        - BANK_STATEMENT
        - TAX_RETURN
        - CERTIFICATE_OF_INCORPORATION
        - ARTICLES_OF_INCORPORATION
        - ARTICLES_OF_ASSOCIATION
        - STATE_REGISTRY_EXCERPT
        - GOOD_STANDING_CERTIFICATE
        - INFORMATION_STATEMENT
        - INCUMBENCY_CERTIFICATE
        - BUSINESS_LICENSE
        - SHAREHOLDER_REGISTER
        - POWER_OF_ATTORNEY
        - UTILITY_BILL
        - ELECTRICITY_BILL
        - RENT_OR_LEASE_AGREEMENT
        - DIRECTOR_REGISTRY
        - TRUST_AGREEMENT
        - STATE_COMPANY_REGISTRY
        - PARTNERSHIP_CONTROL_AGREEMENT
        - PARTNERSHIP_AGREEMENT
        - SELFIE
        - OTHER
      description: >-
        Type of identity or business verification document. Document types are
        grouped by verification category:

        **Identity** — PASSPORT, DRIVERS_LICENSE, NATIONAL_ID

        **Business — Legal presence** — CERTIFICATE_OF_INCORPORATION,
        ARTICLES_OF_INCORPORATION, ARTICLES_OF_ASSOCIATION,
        STATE_REGISTRY_EXCERPT

        **Business — Control structure** — DIRECTOR_REGISTRY, TRUST_AGREEMENT,
        STATE_COMPANY_REGISTRY, PARTNERSHIP_CONTROL_AGREEMENT

        **Business — Ownership structure** — SHAREHOLDER_REGISTER,
        TRUST_AGREEMENT, PARTNERSHIP_AGREEMENT

        **Proof of address** — UTILITY_BILL, RENT_OR_LEASE_AGREEMENT,
        ELECTRICITY_BILL, BANK_STATEMENT, TAX_RETURN
      example: PASSPORT
    BaseDocumentRequest:
      type: object
      required:
        - file
        - documentType
        - country
      properties:
        file:
          type: string
          format: binary
          description: The document file (PDF, JPEG, or PNG, max 10 MB)
        documentType:
          $ref: '#/components/schemas/DocumentType'
        side:
          type: string
          enum:
            - FRONT
            - BACK
          description: >-
            Which side of the document (for two-sided documents like driver's
            licenses)
          example: FRONT
        country:
          type: string
          description: Country that issued the document (ISO 3166-1 alpha-2)
          example: US
        documentNumber:
          type: string
          description: Document identification number (e.g., passport number)
          example: A12345678
        issuingAuthority:
          type: string
          description: >-
            Name of the government agency or organization that issued the
            document
          example: U.S. Department of State
  securitySchemes:
    BasicAuth:
      type: http
      scheme: basic
      description: >-
        API token authentication using format `<api token id>:<api client
        secret>`
    AgentAuth:
      type: http
      scheme: bearer
      description: >-
        Bearer token authentication for agent-scoped endpoints. The token is the
        `accessToken` returned when redeeming a device code via `POST
        /agents/device-codes/{code}/redeem`. Agent credentials are user-scoped:
        all requests are automatically bound to the agent's associated customer
        and subject to the agent's policy.

````