> Full index: https://docs.buchungapp.com/llms.txt
> Early access. Use the API base, channel key and allowed origins supplied by Buchung before running examples.

# Replace a document's file

Swap the current file for another validated upload candidate in one step, with expectedRevision. Every custom fact reference and the storefront URL follow; publication is unchanged, and the previous file is deleted. Bytes never leave the private bucket. The document URL is the storefront's own route, which answers a 302 to a short-lived signed URL of the current file only while the document is published, so unpublishing takes effect on the next request. An unusable candidate returns 400 validation_failed as on createDocument. A stale expectedRevision returns 409 revision_conflict with the document's currentRevision in the required details. Requires media:upload. Machine integration bearer credentials only; storefront channel keys never authorize these operations. Buchung-Locale is not used; translations are addressed explicitly. Host enforces a 64 KiB request-body cap before parsing for every method with a body, including DELETE. Per-machine limits: 600 reads/minute, 300 writes/minute; over limit returns 429 rate_limited. Limiter store outage falls back to per-instance memory for reads; writes return 503 service_unavailable with Retry-After: 30.

```json
{
  "operations": [
    {
      "method": "post",
      "path": "/v1/management/documents/{documentId}/file",
      "tags": [
        "management"
      ]
    }
  ],
  "schema": {
    "openapi": "3.2.0",
    "info": {
      "title": "Buchung Storefront API",
      "version": "1.0.0",
      "description": "Public catalogue reads and hosted-checkout handoff scoped to a booking channel, plus bearer-only machine management. Storefront channel keys never authorize management operations; machine credentials never authorize storefront checkout handoffs. Storefront reads enforce a 4 MiB per-page custom-fact budget; result_too_large maps to the 400 validation_failed envelope without truncation. Use GET for simple catalogue queries with the raw request target strictly below 8 KiB (414 validation_failed otherwise); use the corresponding POST /query form when conditions or selections outgrow a URL. POST accepts the decoded GET fields as JSON, including the same defaults, errors and response schemas, uses the same read limiter bucket and returns Cache-Control: private, no-store. There are no per-parameter where/facets character caps. Management caps every method with a body at 64 KiB before parsing; storefront POST bodies are capped at 16 KiB before parsing (413 payload_too_large)."
    },
    "paths": {
      "/v1/management/documents/{documentId}/file": {
        "post": {
          "tags": [
            "management"
          ],
          "operationId": "management.replaceDocumentFile",
          "parameters": [
            {
              "name": "documentId",
              "in": "path",
              "schema": {
                "$ref": "#/components/schemas/Id"
              },
              "required": true,
              "description": "Document UUID scoped to the integration operator; see Id."
            }
          ],
          "security": [
            {
              "integrationBearer": []
            }
          ],
          "responses": {
            "200": {
              "description": "Operator-level document with a stable id, a display name, one current validated PDF and a published flag. Bytes never leave the private bucket. The URL is the storefront's own route, which answers a 302 to a short-lived signed URL of the current file only while the document is published, so unpublishing takes effect on the next request; copies clients already downloaded cannot be recalled.",
              "content": {
                "application/json": {
                  "schema": {
                    "$ref": "#/components/schemas/OperatorDocument"
                  }
                }
              }
            },
            "400": {
              "description": "ValidationFailed",
              "content": {
                "application/json": {
                  "schema": {
                    "$ref": "#/components/schemas/ValidationFailedEncoded"
                  }
                }
              }
            },
            "401": {
              "description": "Unauthorized",
              "content": {
                "application/json": {
                  "schema": {
                    "$ref": "#/components/schemas/UnauthorizedEncoded"
                  }
                }
              }
            },
            "403": {
              "description": "Forbidden",
              "content": {
                "application/json": {
                  "schema": {
                    "$ref": "#/components/schemas/ForbiddenEncoded"
                  }
                }
              }
            },
            "404": {
              "description": "NotFound",
              "content": {
                "application/json": {
                  "schema": {
                    "$ref": "#/components/schemas/NotFoundEncoded"
                  }
                }
              }
            },
            "409": {
              "description": "The expected revision is stale; required object details contain the current revision (null when the value is currently absent; retry with expectedRevision: null) and optionally the stored value. Deleting a value on an archived activity returns currentRevision only; reads there return not_found.",
              "content": {
                "application/json": {
                  "schema": {
                    "$ref": "#/components/schemas/RevisionConflictEncoded"
                  }
                }
              }
            },
            "413": {
              "description": "PayloadTooLarge",
              "content": {
                "application/json": {
                  "schema": {
                    "$ref": "#/components/schemas/PayloadTooLargeEncoded"
                  }
                }
              }
            },
            "429": {
              "description": "RateLimited",
              "content": {
                "application/json": {
                  "schema": {
                    "$ref": "#/components/schemas/RateLimitedEncoded"
                  }
                }
              }
            },
            "500": {
              "description": "Unexpected runtime failure. Configuration errors close the API mount with 404 not_found in the shared error envelope and an api_misconfigured log line (R23), never 500 internal_error.",
              "content": {
                "application/json": {
                  "schema": {
                    "$ref": "#/components/schemas/InternalErrorEncoded"
                  }
                }
              }
            },
            "503": {
              "description": "ServiceUnavailable",
              "content": {
                "application/json": {
                  "schema": {
                    "$ref": "#/components/schemas/ServiceUnavailableEncoded"
                  }
                }
              }
            }
          },
          "description": "Swap the current file for another validated upload candidate in one step, with expectedRevision. Every custom fact reference and the storefront URL follow; publication is unchanged, and the previous file is deleted. Bytes never leave the private bucket. The document URL is the storefront's own route, which answers a 302 to a short-lived signed URL of the current file only while the document is published, so unpublishing takes effect on the next request. An unusable candidate returns 400 validation_failed as on createDocument. A stale expectedRevision returns 409 revision_conflict with the document's currentRevision in the required details. Requires media:upload. Machine integration bearer credentials only; storefront channel keys never authorize these operations. Buchung-Locale is not used; translations are addressed explicitly. Host enforces a 64 KiB request-body cap before parsing for every method with a body, including DELETE. Per-machine limits: 600 reads/minute, 300 writes/minute; over limit returns 429 rate_limited. Limiter store outage falls back to per-instance memory for reads; writes return 503 service_unavailable with Retry-After: 30.",
          "summary": "Replace a document's file",
          "requestBody": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentFileReplace"
                }
              }
            },
            "required": true
          }
        }
      }
    },
    "security": [],
    "tags": [
      {
        "name": "activities"
      },
      {
        "name": "availabilities"
      },
      {
        "name": "bookingOptions"
      },
      {
        "name": "site"
      },
      {
        "name": "checkout"
      },
      {
        "name": "management"
      }
    ],
    "servers": [
      {
        "url": "https://api.buchungapp.com"
      }
    ],
    "components": {
      "schemas": {
        "UnauthorizedEncoded": {
          "type": "object",
          "properties": {
            "error": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string",
                  "enum": [
                    "unauthorized"
                  ],
                  "description": "Closed error discriminator for this HTTP error variant."
                },
                "message": {
                  "type": "string"
                },
                "doc_url": {
                  "type": "string",
                  "enum": [
                    "https://api.buchungapp.com/v1/docs#errors/unauthorized"
                  ],
                  "description": "Closed documentation URL corresponding to this error code."
                },
                "request_id": {
                  "type": "string"
                },
                "details": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ErrorDetail"
                  }
                }
              },
              "required": [
                "code",
                "message",
                "doc_url",
                "request_id"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "error"
          ],
          "additionalProperties": false
        },
        "ErrorDetail": {
          "type": "object",
          "properties": {
            "path": {
              "type": "string"
            },
            "message": {
              "type": "string"
            }
          },
          "required": [
            "path",
            "message"
          ],
          "additionalProperties": false,
          "description": "A validation issue at a request field path."
        },
        "Revision": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991,
          "description": "Monotonic integer optimistic-concurrency revision assigned from a database sequence, starting at 1. Not dense: gaps are normal. Clients compare equality only. A value slot never reuses a revision across delete/recreate, so a stale expectedRevision always conflicts."
        },
        "Id": {
          "type": "string",
          "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|[fF]{8}-[fF]{4}-[fF]{4}-[fF]{4}-[fF]{12})$",
          "format": "uuid",
          "description": "Stable UUID of a public resource."
        },
        "RevisionConflictEncoded": {
          "type": "object",
          "properties": {
            "error": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string",
                  "enum": [
                    "revision_conflict"
                  ],
                  "description": "Closed error discriminator for this HTTP error variant."
                },
                "message": {
                  "type": "string"
                },
                "doc_url": {
                  "type": "string",
                  "enum": [
                    "https://api.buchungapp.com/v1/docs#errors/revision_conflict"
                  ],
                  "description": "Closed documentation URL corresponding to this error code."
                },
                "request_id": {
                  "type": "string"
                },
                "details": {
                  "type": "object",
                  "properties": {
                    "currentRevision": {
                      "anyOf": [
                        {
                          "$ref": "#/components/schemas/Revision"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "currentValue": {
                      "$ref": "#/components/schemas/CustomValuePayloadEncoded"
                    }
                  },
                  "required": [
                    "currentRevision"
                  ],
                  "additionalProperties": false
                }
              },
              "required": [
                "code",
                "message",
                "doc_url",
                "request_id",
                "details"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "error"
          ],
          "additionalProperties": false
        },
        "CustomValuePayloadEncoded": {
          "description": "Server validates the definition codec: text trimmed plain text, maxLength 1..4000 (default 1000), no control characters except newline/tab; text_list maxItems 1..50 (default 20), each item <= 500 characters, whole-list replacement; boolean strict; number finite with |value| <= 1e15, integer/min/max and precision 0..6, no rounding; choice one declared option key; json <= 16 KiB serialized UTF-8, depth <= 16, <= 5000 nodes, keys <= 128 characters, strings <= 8 KiB, rejects __proto__/constructor/prototype; pdf { documentId } must name a live document of the same operator whose current file is a validated catalogue PDF, never an upload candidate's mediaId; public projection additionally requires the document to be published, so a reference to an unpublished document is stored but stays absent from the storefront. For json definitions only, explicit JSON null is a stored value distinct from deletion. Cumulative serialized custom values per activity are capped at 64 KiB at write time; exceeding the budget returns 400 validation_failed with a budget detail. Retired definitions block new value writes and public projection but allow deleting stored values. Host caps management request bodies at 64 KiB before parsing."
        },
        "ForbiddenEncoded": {
          "type": "object",
          "properties": {
            "error": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string",
                  "enum": [
                    "forbidden"
                  ],
                  "description": "Closed error discriminator for this HTTP error variant."
                },
                "message": {
                  "type": "string"
                },
                "doc_url": {
                  "type": "string",
                  "enum": [
                    "https://api.buchungapp.com/v1/docs#errors/forbidden"
                  ],
                  "description": "Closed documentation URL corresponding to this error code."
                },
                "request_id": {
                  "type": "string"
                },
                "details": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ErrorDetail"
                  }
                }
              },
              "required": [
                "code",
                "message",
                "doc_url",
                "request_id"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "error"
          ],
          "additionalProperties": false
        },
        "PayloadTooLargeEncoded": {
          "type": "object",
          "properties": {
            "error": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string",
                  "enum": [
                    "payload_too_large"
                  ],
                  "description": "Closed error discriminator for this HTTP error variant."
                },
                "message": {
                  "type": "string"
                },
                "doc_url": {
                  "type": "string",
                  "enum": [
                    "https://api.buchungapp.com/v1/docs#errors/payload_too_large"
                  ],
                  "description": "Closed documentation URL corresponding to this error code."
                },
                "request_id": {
                  "type": "string"
                },
                "details": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ErrorDetail"
                  }
                }
              },
              "required": [
                "code",
                "message",
                "doc_url",
                "request_id"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "error"
          ],
          "additionalProperties": false
        },
        "NotFoundEncoded": {
          "type": "object",
          "properties": {
            "error": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string",
                  "enum": [
                    "not_found"
                  ],
                  "description": "Closed error discriminator for this HTTP error variant."
                },
                "message": {
                  "type": "string"
                },
                "doc_url": {
                  "type": "string",
                  "enum": [
                    "https://api.buchungapp.com/v1/docs#errors/not_found"
                  ],
                  "description": "Closed documentation URL corresponding to this error code."
                },
                "request_id": {
                  "type": "string"
                },
                "details": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ErrorDetail"
                  }
                }
              },
              "required": [
                "code",
                "message",
                "doc_url",
                "request_id"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "error"
          ],
          "additionalProperties": false
        },
        "InternalErrorEncoded": {
          "type": "object",
          "properties": {
            "error": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string",
                  "enum": [
                    "internal_error"
                  ],
                  "description": "Closed error discriminator for this HTTP error variant."
                },
                "message": {
                  "type": "string"
                },
                "doc_url": {
                  "type": "string",
                  "enum": [
                    "https://api.buchungapp.com/v1/docs#errors/internal_error"
                  ],
                  "description": "Closed documentation URL corresponding to this error code."
                },
                "request_id": {
                  "type": "string"
                },
                "details": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ErrorDetail"
                  }
                }
              },
              "required": [
                "code",
                "message",
                "doc_url",
                "request_id"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "error"
          ],
          "additionalProperties": false
        },
        "ServiceUnavailableEncoded": {
          "type": "object",
          "properties": {
            "error": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string",
                  "enum": [
                    "service_unavailable"
                  ],
                  "description": "Closed error discriminator for this HTTP error variant."
                },
                "message": {
                  "type": "string"
                },
                "doc_url": {
                  "type": "string",
                  "enum": [
                    "https://api.buchungapp.com/v1/docs#errors/service_unavailable"
                  ],
                  "description": "Closed documentation URL corresponding to this error code."
                },
                "request_id": {
                  "type": "string"
                },
                "details": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ErrorDetail"
                  }
                }
              },
              "required": [
                "code",
                "message",
                "doc_url",
                "request_id"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "error"
          ],
          "additionalProperties": false
        },
        "RateLimitedEncoded": {
          "type": "object",
          "properties": {
            "error": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string",
                  "enum": [
                    "rate_limited"
                  ],
                  "description": "Closed error discriminator for this HTTP error variant."
                },
                "message": {
                  "type": "string"
                },
                "doc_url": {
                  "type": "string",
                  "enum": [
                    "https://api.buchungapp.com/v1/docs#errors/rate_limited"
                  ],
                  "description": "Closed documentation URL corresponding to this error code."
                },
                "request_id": {
                  "type": "string"
                },
                "details": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ErrorDetail"
                  }
                }
              },
              "required": [
                "code",
                "message",
                "doc_url",
                "request_id"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "error"
          ],
          "additionalProperties": false
        },
        "ValidationFailedEncoded": {
          "type": "object",
          "properties": {
            "error": {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string",
                  "enum": [
                    "validation_failed"
                  ],
                  "description": "Closed error discriminator for this HTTP error variant."
                },
                "message": {
                  "type": "string"
                },
                "doc_url": {
                  "type": "string",
                  "enum": [
                    "https://api.buchungapp.com/v1/docs#errors/validation_failed"
                  ],
                  "description": "Closed documentation URL corresponding to this error code."
                },
                "request_id": {
                  "type": "string"
                },
                "details": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ErrorDetail"
                  }
                }
              },
              "required": [
                "code",
                "message",
                "doc_url",
                "request_id"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "error"
          ],
          "additionalProperties": false
        },
        "OperatorDocument": {
          "type": "object",
          "properties": {
            "documentId": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Id"
                }
              ],
              "description": "Stable document UUID. Custom fact references and the storefront URL keep it across file replacement and renaming."
            },
            "displayName": {
              "$ref": "#/components/schemas/DocumentDisplayName"
            },
            "published": {
              "type": "boolean"
            },
            "publishedAt": {
              "anyOf": [
                {
                  "$ref": "#/components/schemas/Instant"
                },
                {
                  "type": "null"
                }
              ],
              "description": "When the current publication began; null while unpublished."
            },
            "revision": {
              "$ref": "#/components/schemas/Revision"
            },
            "file": {
              "type": "object",
              "properties": {
                "size": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 20971520,
                  "description": "Byte size of the current file, at most 20 MiB."
                },
                "validatedAt": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Instant"
                    }
                  ],
                  "description": "When finalization validated the current file's bytes."
                }
              },
              "required": [
                "size",
                "validatedAt"
              ],
              "additionalProperties": false,
              "description": "Current validated PDF. Its bytes stay in the private bucket; there is no public storage URL."
            },
            "referenceCount": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991,
              "description": "Total references that block deletion: custom fact values (including on archived activities) plus event attachments. Deletion is refused with 409 document_referenced while it is above zero; that error lists the custom fact value slots."
            },
            "url": {
              "anyOf": [
                {
                  "$ref": "#/components/schemas/PublicUrl"
                },
                {
                  "type": "null"
                }
              ],
              "description": "While published, the storefront's own document route (/documents/{documentId}/{slug}.pdf on the operator's storefront host); null while unpublished. The slug is cosmetic."
            }
          },
          "required": [
            "documentId",
            "displayName",
            "published",
            "publishedAt",
            "revision",
            "file",
            "referenceCount",
            "url"
          ],
          "additionalProperties": false,
          "description": "Operator-level document with a stable id, a display name, one current validated PDF and a published flag. Bytes never leave the private bucket. The URL is the storefront's own route, which answers a 302 to a short-lived signed URL of the current file only while the document is published, so unpublishing takes effect on the next request; copies clients already downloaded cannot be recalled."
        },
        "PublicUrl": {
          "type": "string",
          "format": "uri",
          "pattern": "^[Hh][Tt][Tt][Pp][Ss]?:\\/\\/\\S+$",
          "description": "Absolute public HTTP(S) URL; data and javascript URLs are not allowed."
        },
        "Instant": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}T(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|[+-](?:[01]\\d|2[0-3]):[0-5]\\d)$",
          "format": "date-time",
          "description": "ISO 8601 absolute instant with explicit UTC offset (including Z). Render using the resource's documented display timezone; the serialized offset need not equal that zone."
        },
        "DocumentDisplayName": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255,
          "pattern": "^[^\\u0000-\\u001F\\u007F]+$",
          "description": "Display name of a document, 1 to 255 characters with no control characters (U+0000-U+001F, U+007F). The storefront fileName is the display name with .pdf, and the slug of the document URL derives from it."
        },
        "DocumentFileReplace": {
          "type": "object",
          "properties": {
            "candidateMediaId": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Id"
                }
              ],
              "description": "mediaId of a ready catalogue document upload (DocumentUploadStatus): a validated catalogue PDF of the same operator that no document owns yet. Anything else returns 400 validation_failed."
            },
            "expectedRevision": {
              "$ref": "#/components/schemas/Revision"
            }
          },
          "required": [
            "candidateMediaId",
            "expectedRevision"
          ],
          "additionalProperties": false,
          "description": "Swap the document's current file for another validated upload candidate in one step; every reference and the storefront URL follow, and the previous file is deleted."
        }
      },
      "securitySchemes": {
        "integrationBearer": {
          "description": "Machine integration credential: Authorization: Bearer bg_it_<32 lowercase hex characters> (^bg_it_[0-9a-f]{32}$). Resolved uncached on each request. Middleware binds the resolved principal once; handlers run under it and never re-derive authority. The request context includes credentialId for per-request logging alongside machineId, operatorId, organizationId and capabilities; the principal is opaque and server-owned. Storefront channel keys never authorize management operations; machine credentials never authorize storefront checkout handoffs. Invalid, expired, revoked, disabled or ungranted credentials return 401 unauthorized.",
          "type": "http",
          "scheme": "Bearer"
        }
      }
    }
  }
}
```
