{
    "openapi": "3.1.0",
    "info": {
        "title": "filehub Gateway für DATEV – API",
        "version": "1.0.0",
        "description": "REST-API für eigene Software und Partnerprodukte. filehub reicht DATEVconnect durch: Pfade, Parameter und Antworten unter `/connect/` sind die von DATEVconnect (siehe die DATEV-Spezifikationen der jeweiligen Schnittstelle). filehub prüft davor Schlüssel, Rechte, Mandantenfreigabe und Abfrageregeln und schreibt jeden Aufruf ins Zugriffsprotokoll der Kanzlei. Diese Datei beschreibt nur die filehub-eigenen Endpunkte, die Anmeldung und die Fehler. Dokumentation: https://filehub.one/de/entwickler/gateway-fuer-datev",
        "contact": {
            "name": "filehub",
            "url": "https://filehub.one/de/entwickler/gateway-fuer-datev"
        }
    },
    "servers": [
        {
            "url": "https://filehub.one/api/datev/v1"
        }
    ],
    "security": [
        {
            "bearerAuth": []
        }
    ],
    "paths": {
        "/systems": {
            "get": {
                "operationId": "listSystems",
                "summary": "DATEV-Systeme des Schlüssels",
                "description": "Das DATEV-System, an das der Schlüssel gebunden ist, mit Status und den Rechten, die der Schlüssel dort tatsächlich hat (Schnittmenge aus Schlüssel und Freigaben der Kanzlei).",
                "responses": {
                    "200": {
                        "description": "Liste der Systeme",
                        "headers": {
                            "X-Request-Id": {
                                "$ref": "#/components/headers/X-Request-Id"
                            }
                        },
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "required": ["data"],
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/System"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Error"
                    },
                    "403": {
                        "$ref": "#/components/responses/Error"
                    },
                    "429": {
                        "$ref": "#/components/responses/Error"
                    }
                },
                "x-codeSamples": [
                    {
                        "lang": "cURL",
                        "label": "Systeme abrufen",
                        "source": "curl -s https://filehub.one/api/datev/v1/systems \\\n  -H \"Authorization: Bearer $FILEHUB_API_KEY\" \\\n  -H \"Accept: application/json\""
                    }
                ]
            }
        },
        "/systems/{system}/clients": {
            "get": {
                "operationId": "listClients",
                "summary": "Freigegebene Mandanten",
                "description": "Die Mandanten, die die Kanzlei für das System freigegeben hat, beschränkt auf die Mandanten des Schlüssels. Kommt aus filehub, ohne Aufruf bei DATEV.",
                "parameters": [
                    {
                        "$ref": "#/components/parameters/System"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Liste der Mandanten",
                        "headers": {
                            "X-Request-Id": {
                                "$ref": "#/components/headers/X-Request-Id"
                            }
                        },
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "required": ["data"],
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Client"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Error"
                    },
                    "403": {
                        "$ref": "#/components/responses/Error"
                    },
                    "404": {
                        "$ref": "#/components/responses/Error"
                    },
                    "429": {
                        "$ref": "#/components/responses/Error"
                    }
                }
            }
        },
        "/systems/{system}/connect/{path}": {
            "description": "Durchreichen an DATEVconnect: `{path}` ist der Pfad unter `/datev/api/`, z. B. `accounting/v1/clients` oder `accounting/v1/clients/{client-id}/fiscal-years`, mit Schrägstrichen. Methode, Abfrageparameter und JSON-Body gehen unverändert an DATEVconnect, die Antwort (Status und Body) unverändert zurück. Die Mandantenlisten `accounting/v1/clients` und `master-data/v1/clients` enthalten nur freigegebene Mandanten; kanzleiweite Stammdatenlisten (z. B. `master-data/v1/responsibilities`) nur Einträge freigegebener Mandanten und mit einem auf Mandanten beschränkten Schlüssel gar nicht. Lehnt filehub ab, kommt 403 mit dem Grund; ist das System nicht erreichbar, 503.",
            "parameters": [
                {
                    "$ref": "#/components/parameters/System"
                },
                {
                    "name": "path",
                    "in": "path",
                    "required": true,
                    "description": "DATEVconnect-Pfad unter /datev/api/ (darf Schrägstriche enthalten).",
                    "schema": {
                        "type": "string",
                        "pattern": "^[A-Za-z0-9/_-]+$"
                    },
                    "example": "accounting/v1/clients"
                }
            ],
            "get": {
                "operationId": "connectGet",
                "summary": "DATEVconnect lesen",
                "responses": {
                    "200": {
                        "$ref": "#/components/responses/Passthrough"
                    },
                    "default": {
                        "$ref": "#/components/responses/Error"
                    }
                },
                "x-codeSamples": [
                    {
                        "lang": "cURL",
                        "label": "Mandanten aus DATEV Rechnungswesen",
                        "source": "curl -s https://filehub.one/api/datev/v1/systems/$SYSTEM_ID/connect/accounting/v1/clients \\\n  -H \"Authorization: Bearer $FILEHUB_API_KEY\" \\\n  -H \"Accept: application/json\""
                    }
                ]
            },
            "post": {
                "operationId": "connectPost",
                "summary": "DATEVconnect schreiben (anlegen)",
                "requestBody": {
                    "$ref": "#/components/requestBodies/Passthrough"
                },
                "responses": {
                    "200": {
                        "$ref": "#/components/responses/Passthrough"
                    },
                    "default": {
                        "$ref": "#/components/responses/Error"
                    }
                }
            },
            "put": {
                "operationId": "connectPut",
                "summary": "DATEVconnect schreiben (ersetzen)",
                "requestBody": {
                    "$ref": "#/components/requestBodies/Passthrough"
                },
                "responses": {
                    "200": {
                        "$ref": "#/components/responses/Passthrough"
                    },
                    "default": {
                        "$ref": "#/components/responses/Error"
                    }
                }
            },
            "patch": {
                "operationId": "connectPatch",
                "summary": "DATEVconnect schreiben (ändern)",
                "requestBody": {
                    "$ref": "#/components/requestBodies/Passthrough"
                },
                "responses": {
                    "200": {
                        "$ref": "#/components/responses/Passthrough"
                    },
                    "default": {
                        "$ref": "#/components/responses/Error"
                    }
                }
            },
            "delete": {
                "operationId": "connectDelete",
                "summary": "DATEVconnect löschen",
                "responses": {
                    "200": {
                        "$ref": "#/components/responses/Passthrough"
                    },
                    "default": {
                        "$ref": "#/components/responses/Error"
                    }
                }
            }
        }
    },
    "components": {
        "securitySchemes": {
            "bearerAuth": {
                "type": "http",
                "scheme": "bearer",
                "description": "API-Schlüssel aus dem filehub-Dashboard (DATEV-Verbindungen → System → API-Schlüssel). Wird nur einmal angezeigt."
            }
        },
        "parameters": {
            "System": {
                "name": "system",
                "in": "path",
                "required": true,
                "description": "ID des DATEV-Systems (Feld `id` aus `/systems`).",
                "schema": {
                    "type": "string",
                    "format": "uuid"
                }
            }
        },
        "headers": {
            "X-Request-Id": {
                "description": "Kennung des Aufrufs. Bei Aufrufen unter /connect/ dieselbe Kennung wie im Zugriffsprotokoll der Kanzlei (Spalte Request-ID). Bei Rückfragen an filehub angeben.",
                "schema": {
                    "type": "string",
                    "format": "uuid"
                }
            },
            "Retry-After": {
                "description": "Sekunden bis zur nächsten erlaubten Anfrage (nur bei 429).",
                "schema": {
                    "type": "integer"
                }
            }
        },
        "requestBodies": {
            "Passthrough": {
                "description": "JSON-Body nach der DATEV-Spezifikation der Schnittstelle, für Dateirouten (z. B. `POST dms/v2/document-files`) die Datei als `application/octet-stream` (höchstens 50 MB, `datev_gateway.binary.max_bytes`). Andere Inhaltstypen werden mit 415 abgelehnt.",
                "required": false,
                "content": {
                    "application/json": {
                        "schema": {}
                    },
                    "application/octet-stream": {
                        "schema": {
                            "type": "string",
                            "format": "binary"
                        }
                    }
                }
            }
        },
        "responses": {
            "Passthrough": {
                "description": "Antwort von DATEVconnect, Status und Body unverändert (auch Fehler von DATEV, z. B. 400 oder 404). Dateien (z. B. `GET dms/v2/document-files/{id}`) kommen Byte für Byte mit dem Inhaltstyp von DATEV.",
                "headers": {
                    "X-Request-Id": {
                        "$ref": "#/components/headers/X-Request-Id"
                    }
                },
                "content": {
                    "application/json": {
                        "schema": {}
                    },
                    "application/octet-stream": {
                        "schema": {
                            "type": "string",
                            "format": "binary"
                        }
                    }
                }
            },
            "Error": {
                "description": "Fehler von filehub: 400 ungültige Anfrage, 401 Schlüssel fehlt, ungültig, widerrufen oder abgelaufen, 403 Ablehnung (Grund in `error`), 404 System unbekannt, 413 Body zu groß, 415 Inhaltstyp nicht unterstützt, 429 Rate-Limit, 503 DATEV-System nicht erreichbar.",
                "headers": {
                    "X-Request-Id": {
                        "$ref": "#/components/headers/X-Request-Id"
                    },
                    "Retry-After": {
                        "$ref": "#/components/headers/Retry-After"
                    }
                },
                "content": {
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/Error"
                        }
                    }
                }
            }
        },
        "schemas": {
            "System": {
                "type": "object",
                "required": ["id", "name", "status", "demo", "online", "rights", "clients_limited"],
                "properties": {
                    "id": {
                        "type": "string",
                        "format": "uuid"
                    },
                    "name": {
                        "type": "string"
                    },
                    "status": {
                        "type": "string",
                        "enum": ["pending", "enrolled", "active", "suspended", "revoked"]
                    },
                    "demo": {
                        "type": "boolean",
                        "description": "Testumgebung mit synthetischen Daten, ohne DATEV-Installation."
                    },
                    "online": {
                        "type": "boolean"
                    },
                    "last_seen_at": {
                        "type": ["string", "null"],
                        "format": "date-time"
                    },
                    "rights": {
                        "type": "array",
                        "description": "Rechte, die der Schlüssel auf diesem System hat, z. B. accounting.clients.read.",
                        "items": {
                            "type": "string"
                        }
                    },
                    "clients_limited": {
                        "type": "boolean",
                        "description": "true: Der Schlüssel ist auf einzelne Mandanten beschränkt."
                    }
                }
            },
            "Client": {
                "type": "object",
                "required": ["id", "berater_nr", "mandant_nr"],
                "properties": {
                    "id": {
                        "type": "string",
                        "format": "uuid",
                        "description": "Mandanten-GUID aus DATEVconnect."
                    },
                    "berater_nr": {
                        "type": "string"
                    },
                    "mandant_nr": {
                        "type": "string"
                    },
                    "name": {
                        "type": ["string", "null"]
                    }
                }
            },
            "Error": {
                "type": "object",
                "required": ["error", "message", "request_id"],
                "properties": {
                    "error": {
                        "type": "string",
                        "enum": [
                            "api_disabled",
                            "unauthenticated",
                            "key_revoked",
                            "key_expired",
                            "workspace_disabled",
                            "ip_not_allowed",
                            "rate_limited",
                            "system_not_found",
                            "invalid_query",
                            "invalid_json",
                            "body_too_large",
                            "unsupported_media_type",
                            "key_right_not_granted",
                            "key_client_not_allowed",
                            "key_client_scope_unknown",
                            "invalid_path",
                            "route_not_allowed",
                            "right_not_granted",
                            "client_not_released",
                            "query_not_allowed",
                            "unreadable_client_list",
                            "filter_not_allowed",
                            "body_not_allowed",
                            "response_too_large",
                            "client_filter_required",
                            "client_unknown",
                            "client_ambiguous",
                            "client_lookup_failed",
                            "client_list_unreadable",
                            "file_not_in_document",
                            "file_not_uploaded_here",
                            "personal_right_needs_person",
                            "person_not_linked",
                            "datev_user_inactive",
                            "personal_right_not_granted",
                            "system_not_active",
                            "not_enrolled",
                            "no_credentials",
                            "no_pinned_certificate",
                            "connection_failed"
                        ]
                    },
                    "message": {
                        "type": "string"
                    },
                    "request_id": {
                        "type": "string",
                        "format": "uuid"
                    }
                }
            }
        }
    }
}
