Développeurs

Comptable.ma API v1

REST • JSON • Serveur à serveur • OpenAPI 3.1

Spécification OpenAPI

Exemple

curl 'https://comptable.ma/api/v1/customers?limit=100' \
  -H "Authorization: Bearer $COMPTABLE_API_KEY"

Sur un site publié protégé par la plateforme, utilisez /api/public/v1 à la place de /api/v1.

curl 'https://comptable.ma/api/public/v1/expenses' \
  -H "Authorization: Bearer $COMPTABLE_API_KEY" \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: expense-2026-001' \
  -d '{"date":"2026-10-21","description":"Fournitures","amount_ht":100,"tva_rate":20,"tva_amount":20,"amount_ttc":120,"currency":"MAD"}'

Référence

GET/api/v1/customersread:customers
GET/api/v1/customers/{id}read:customers
GET/api/v1/suppliersread:suppliers
GET/api/v1/suppliers/{id}read:suppliers
GET/api/v1/invoicesread:invoices
GET/api/v1/invoices/{id}read:invoices
GET/api/v1/quotesread:quotes
GET/api/v1/quotes/{id}read:quotes
GET/api/v1/vendor_invoicesread:vendor_invoices
GET/api/v1/vendor_invoices/{id}read:vendor_invoices
GET/api/v1/expensesread:expenses
GET/api/v1/expenses/{id}read:expenses
GET/api/v1/ledgerread:ledger
GET/api/v1/ledger/{id}read:ledger
GET/api/v1/reports/trial-balanceread:reports
GET/api/v1/reports/pnlread:reports
GET/api/v1/reports/balance-sheetread:reports
POST/api/v1/customerswrite:customers
PATCH/api/v1/customers/{id}write:customers
POST/api/v1/invoiceswrite:draft_invoices
PATCH/api/v1/invoices/{id}write:draft_invoices
POST/api/v1/expenseswrite:expenses
POST/api/v1/documentswrite:documents

États financiers

GET /reports/trial-balance, /reports/pnl et /reports/balance-sheet : start et end au format AAAA-MM-JJ, données comptabilisées uniquement.

Webhooks

Paramètres → API → Webhooks. URL HTTPS publique uniquement (port 443, pas d’adresse IP ni d’hôte interne, 500 caractères max.). Requête POST JSON, délai 10 s, aucune redirection suivie, réponse ignorée. Toute réponse 2xx vaut réception.

En-têtes : X-Comptable-Signature: t=<unix>,v1=<hex> (HMAC-SHA256 de t.corps ; pendant 24 h après un renouvellement, deux valeurs v1), X-Comptable-Event, X-Comptable-Delivery (identifiant d’idempotence, identique à chaque nouvelle tentative).

Nouvelles tentatives après 1, 5, 30, 120, 360, 1440 minutes, puis échec définitif. Après 20 échecs consécutifs, le webhook est désactivé et le propriétaire est notifié dans l’application.

  • invoice.issued — Facture émise
  • invoice.paid — Facture payée
  • invoice.cancelled — Facture annulée
  • vendor_invoice.created — Facture fournisseur créée
  • vendor_invoice.paid — Facture fournisseur payée
  • expense.validated — Dépense validée
  • payment.recorded — Paiement enregistré
  • document_request.created — Demande de justificatif créée
  • approval.decided — Approbation décidée
  • ping — Événement test

Contenu

{
  "id": "1b6f…",               // identifiant de l’événement
  "type": "invoice.issued",
  "created_at": "2026-10-22T10:00:00Z",
  "company_id": "…",
  "data": { "id": "…", "invoice_number": "F-2026-0042", "status": "issued", "total_ttc": 1200, "currency": "MAD", … }
}

data reprend les mêmes champs que la ressource API correspondante (paiements : direction in/out). Jamais de paie, d’équipe, de facturation ni de secret.

Vérification — Node.js

import crypto from "node:crypto";

// rawBody : corps brut (string) de la requête, avant JSON.parse
export function verify(secret, header, rawBody, tolerance = 300) {
  let t = null;
  const sigs = [];
  for (const p of header.split(",")) {
    const [k, v] = p.split("=");
    if (k === "t") t = Number(v);
    if (k === "v1") sigs.push(v);
  }
  if (!t || Math.abs(Date.now() / 1000 - t) > tolerance) return false;
  const expected = crypto.createHmac("sha256", secret).update(`${t}.${rawBody}`).digest();
  return sigs.some((s) => {
    const got = Buffer.from(s, "hex");
    return got.length === expected.length && crypto.timingSafeEqual(got, expected);
  });
}

Vérification — PHP

<?php
function verify(string $secret, string $header, string $rawBody, int $tolerance = 300): bool {
  $t = null; $sigs = [];
  foreach (explode(',', $header) as $part) {
    [$k, $v] = array_pad(explode('=', $part, 2), 2, '');
    if ($k === 't') $t = (int) $v;
    if ($k === 'v1') $sigs[] = $v;
  }
  if (!$t || abs(time() - $t) > $tolerance) return false;
  $expected = hash_hmac('sha256', $t . '.' . $rawBody, $secret);
  foreach ($sigs as $sig) {
    if (hash_equals($expected, $sig)) return true;
  }
  return false;
}
// $ok = verify(getenv('COMPTABLE_WEBHOOK_SECRET'), $_SERVER['HTTP_X_COMPTABLE_SIGNATURE'], file_get_contents('php://input'));
OpenAPI 3.1
{
  "openapi": "3.1.0",
  "info": {
    "title": "Comptable.ma API",
    "version": "1.0.0",
    "description": "Serveur à serveur. 120 requêtes/minute/clé. Brouillons et dépenses à contrôler uniquement. Aucun CORS."
  },
  "servers": [
    {
      "url": "/api/v1"
    },
    {
      "url": "/api/public/v1",
      "description": "Accès externe publié compatible avec l’authentification de la plateforme"
    }
  ],
  "paths": {
    "/customers": {
      "get": {
        "summary": "Liste customers",
        "x-required-scope": "read:customers",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Créer un client",
        "x-required-scope": "write:customers",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Customer"
              }
            }
          }
        }
      }
    },
    "/customers/{id}": {
      "get": {
        "summary": "Détail customers",
        "x-required-scope": "read:customers",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "patch": {
        "summary": "Modifier un client",
        "x-required-scope": "write:customers",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Customer"
              }
            }
          }
        }
      }
    },
    "/suppliers": {
      "get": {
        "summary": "Liste suppliers",
        "x-required-scope": "read:suppliers",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/suppliers/{id}": {
      "get": {
        "summary": "Détail suppliers",
        "x-required-scope": "read:suppliers",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/invoices": {
      "get": {
        "summary": "Liste invoices",
        "x-required-scope": "read:invoices",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Créer une facture brouillon",
        "x-required-scope": "write:draft_invoices",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DraftInvoice"
              }
            }
          }
        }
      }
    },
    "/invoices/{id}": {
      "get": {
        "summary": "Détail invoices",
        "x-required-scope": "read:invoices",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "patch": {
        "summary": "Modifier un brouillon",
        "x-required-scope": "write:draft_invoices",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DraftInvoice"
              }
            }
          }
        }
      }
    },
    "/quotes": {
      "get": {
        "summary": "Liste quotes",
        "x-required-scope": "read:quotes",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/quotes/{id}": {
      "get": {
        "summary": "Détail quotes",
        "x-required-scope": "read:quotes",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/vendor_invoices": {
      "get": {
        "summary": "Liste vendor_invoices",
        "x-required-scope": "read:vendor_invoices",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/vendor_invoices/{id}": {
      "get": {
        "summary": "Détail vendor_invoices",
        "x-required-scope": "read:vendor_invoices",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/expenses": {
      "get": {
        "summary": "Liste expenses",
        "x-required-scope": "read:expenses",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Créer une dépense à contrôler",
        "x-required-scope": "write:expenses",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Expense"
              }
            }
          }
        }
      }
    },
    "/expenses/{id}": {
      "get": {
        "summary": "Détail expenses",
        "x-required-scope": "read:expenses",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/ledger": {
      "get": {
        "summary": "Liste ledger",
        "x-required-scope": "read:ledger",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/ledger/{id}": {
      "get": {
        "summary": "Détail ledger",
        "x-required-scope": "read:ledger",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/reports/trial-balance": {
      "get": {
        "summary": "trial-balance",
        "x-required-scope": "read:reports",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "start",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "end",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/reports/pnl": {
      "get": {
        "summary": "pnl",
        "x-required-scope": "read:reports",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "start",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "end",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/reports/balance-sheet": {
      "get": {
        "summary": "balance-sheet",
        "x-required-scope": "read:reports",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "start",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "end",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/documents": {
      "post": {
        "summary": "Téléverser un PDF, JPEG ou PNG (10 Mo)",
        "x-required-scope": "write:documents",
        "security": [
          {
            "companyKey": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          },
          {
            "name": "filename",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 255
            }
          }
        ],
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "201": {
            "description": "201",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "401",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "403",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "404",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "409": {
            "description": "409",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "422": {
            "description": "422",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "description": "120 requêtes/minute, Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "503": {
            "description": "Indisponible : refus fermé",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/pdf": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/jpeg": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/png": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        }
      }
    }
  },
  "webhooks": {
    "invoice.issued": {
      "post": {
        "summary": "Facture émise",
        "parameters": [
          {
            "name": "X-Comptable-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "t=1761140000,v1=<hex>"
            }
          },
          {
            "name": "X-Comptable-Event",
            "in": "header",
            "required": true,
            "schema": {
              "const": "invoice.issued"
            }
          },
          {
            "name": "X-Comptable-Delivery",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "type",
                  "created_at",
                  "company_id",
                  "data"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "type": {
                    "const": "invoice.issued"
                  },
                  "created_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "company_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "data": {
                    "type": "object",
                    "properties": {
                      "id": {},
                      "invoice_number": {},
                      "kind": {},
                      "customer_id": {},
                      "customer_name": {},
                      "issue_date": {},
                      "due_date": {},
                      "status": {},
                      "currency": {},
                      "line_items": {},
                      "subtotal_ht": {},
                      "total_tva": {},
                      "total_ttc": {},
                      "paid_amount": {},
                      "fx_rate_to_mad": {},
                      "issued_at": {},
                      "created_at": {}
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Reçu. Toute autre réponse déclenche une nouvelle tentative."
          }
        }
      }
    },
    "invoice.paid": {
      "post": {
        "summary": "Facture payée",
        "parameters": [
          {
            "name": "X-Comptable-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "t=1761140000,v1=<hex>"
            }
          },
          {
            "name": "X-Comptable-Event",
            "in": "header",
            "required": true,
            "schema": {
              "const": "invoice.paid"
            }
          },
          {
            "name": "X-Comptable-Delivery",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "type",
                  "created_at",
                  "company_id",
                  "data"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "type": {
                    "const": "invoice.paid"
                  },
                  "created_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "company_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "data": {
                    "type": "object",
                    "properties": {
                      "id": {},
                      "invoice_number": {},
                      "kind": {},
                      "customer_id": {},
                      "customer_name": {},
                      "issue_date": {},
                      "due_date": {},
                      "status": {},
                      "currency": {},
                      "line_items": {},
                      "subtotal_ht": {},
                      "total_tva": {},
                      "total_ttc": {},
                      "paid_amount": {},
                      "fx_rate_to_mad": {},
                      "issued_at": {},
                      "created_at": {}
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Reçu. Toute autre réponse déclenche une nouvelle tentative."
          }
        }
      }
    },
    "invoice.cancelled": {
      "post": {
        "summary": "Facture annulée",
        "parameters": [
          {
            "name": "X-Comptable-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "t=1761140000,v1=<hex>"
            }
          },
          {
            "name": "X-Comptable-Event",
            "in": "header",
            "required": true,
            "schema": {
              "const": "invoice.cancelled"
            }
          },
          {
            "name": "X-Comptable-Delivery",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "type",
                  "created_at",
                  "company_id",
                  "data"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "type": {
                    "const": "invoice.cancelled"
                  },
                  "created_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "company_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "data": {
                    "type": "object",
                    "properties": {
                      "id": {},
                      "invoice_number": {},
                      "kind": {},
                      "customer_id": {},
                      "customer_name": {},
                      "issue_date": {},
                      "due_date": {},
                      "status": {},
                      "currency": {},
                      "line_items": {},
                      "subtotal_ht": {},
                      "total_tva": {},
                      "total_ttc": {},
                      "paid_amount": {},
                      "fx_rate_to_mad": {},
                      "issued_at": {},
                      "created_at": {}
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Reçu. Toute autre réponse déclenche une nouvelle tentative."
          }
        }
      }
    },
    "vendor_invoice.created": {
      "post": {
        "summary": "Facture fournisseur créée",
        "parameters": [
          {
            "name": "X-Comptable-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "t=1761140000,v1=<hex>"
            }
          },
          {
            "name": "X-Comptable-Event",
            "in": "header",
            "required": true,
            "schema": {
              "const": "vendor_invoice.created"
            }
          },
          {
            "name": "X-Comptable-Delivery",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "type",
                  "created_at",
                  "company_id",
                  "data"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "type": {
                    "const": "vendor_invoice.created"
                  },
                  "created_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "company_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "data": {
                    "type": "object",
                    "properties": {
                      "id": {},
                      "supplier_id": {},
                      "vendor_invoice_number": {},
                      "issue_date": {},
                      "due_date": {},
                      "currency": {},
                      "subtotal_ht": {},
                      "total_tva": {},
                      "total_ttc": {},
                      "paid_amount": {},
                      "status": {},
                      "created_at": {}
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Reçu. Toute autre réponse déclenche une nouvelle tentative."
          }
        }
      }
    },
    "vendor_invoice.paid": {
      "post": {
        "summary": "Facture fournisseur payée",
        "parameters": [
          {
            "name": "X-Comptable-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "t=1761140000,v1=<hex>"
            }
          },
          {
            "name": "X-Comptable-Event",
            "in": "header",
            "required": true,
            "schema": {
              "const": "vendor_invoice.paid"
            }
          },
          {
            "name": "X-Comptable-Delivery",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "type",
                  "created_at",
                  "company_id",
                  "data"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "type": {
                    "const": "vendor_invoice.paid"
                  },
                  "created_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "company_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "data": {
                    "type": "object",
                    "properties": {
                      "id": {},
                      "supplier_id": {},
                      "vendor_invoice_number": {},
                      "issue_date": {},
                      "due_date": {},
                      "currency": {},
                      "subtotal_ht": {},
                      "total_tva": {},
                      "total_ttc": {},
                      "paid_amount": {},
                      "status": {},
                      "created_at": {}
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Reçu. Toute autre réponse déclenche une nouvelle tentative."
          }
        }
      }
    },
    "expense.validated": {
      "post": {
        "summary": "Dépense validée",
        "parameters": [
          {
            "name": "X-Comptable-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "t=1761140000,v1=<hex>"
            }
          },
          {
            "name": "X-Comptable-Event",
            "in": "header",
            "required": true,
            "schema": {
              "const": "expense.validated"
            }
          },
          {
            "name": "X-Comptable-Delivery",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "type",
                  "created_at",
                  "company_id",
                  "data"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "type": {
                    "const": "expense.validated"
                  },
                  "created_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "company_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "data": {
                    "type": "object",
                    "properties": {
                      "id": {},
                      "date": {},
                      "description": {},
                      "vendor_name": {},
                      "invoice_number": {},
                      "amount_ht": {},
                      "tva_amount": {},
                      "amount_ttc": {},
                      "currency": {},
                      "category_cgnc": {},
                      "status": {},
                      "created_at": {}
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Reçu. Toute autre réponse déclenche une nouvelle tentative."
          }
        }
      }
    },
    "payment.recorded": {
      "post": {
        "summary": "Paiement enregistré",
        "parameters": [
          {
            "name": "X-Comptable-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "t=1761140000,v1=<hex>"
            }
          },
          {
            "name": "X-Comptable-Event",
            "in": "header",
            "required": true,
            "schema": {
              "const": "payment.recorded"
            }
          },
          {
            "name": "X-Comptable-Delivery",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "type",
                  "created_at",
                  "company_id",
                  "data"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "type": {
                    "const": "payment.recorded"
                  },
                  "created_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "company_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "data": {
                    "type": "object",
                    "properties": {
                      "id": {},
                      "customer_id": {},
                      "supplier_id": {},
                      "payment_date": {},
                      "amount_mad": {},
                      "currency": {},
                      "method": {},
                      "reference": {},
                      "created_at": {},
                      "direction": {}
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Reçu. Toute autre réponse déclenche une nouvelle tentative."
          }
        }
      }
    },
    "document_request.created": {
      "post": {
        "summary": "Demande de justificatif créée",
        "parameters": [
          {
            "name": "X-Comptable-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "t=1761140000,v1=<hex>"
            }
          },
          {
            "name": "X-Comptable-Event",
            "in": "header",
            "required": true,
            "schema": {
              "const": "document_request.created"
            }
          },
          {
            "name": "X-Comptable-Delivery",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "type",
                  "created_at",
                  "company_id",
                  "data"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "type": {
                    "const": "document_request.created"
                  },
                  "created_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "company_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "data": {
                    "type": "object",
                    "properties": {
                      "id": {},
                      "title": {},
                      "description": {},
                      "due_date": {},
                      "status": {},
                      "created_at": {}
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Reçu. Toute autre réponse déclenche une nouvelle tentative."
          }
        }
      }
    },
    "approval.decided": {
      "post": {
        "summary": "Approbation décidée",
        "parameters": [
          {
            "name": "X-Comptable-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "t=1761140000,v1=<hex>"
            }
          },
          {
            "name": "X-Comptable-Event",
            "in": "header",
            "required": true,
            "schema": {
              "const": "approval.decided"
            }
          },
          {
            "name": "X-Comptable-Delivery",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "type",
                  "created_at",
                  "company_id",
                  "data"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "type": {
                    "const": "approval.decided"
                  },
                  "created_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "company_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "data": {
                    "type": "object",
                    "properties": {
                      "id": {},
                      "entity_type": {},
                      "entity_id": {},
                      "amount_mad": {},
                      "required_levels": {},
                      "status": {},
                      "created_at": {}
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Reçu. Toute autre réponse déclenche une nouvelle tentative."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "companyKey": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Customer": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "ice": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "phone": {
            "type": "string"
          },
          "address": {
            "type": "string"
          },
          "city": {
            "type": "string"
          },
          "payment_terms_days": {
            "type": "integer",
            "minimum": 0,
            "maximum": 365
          },
          "credit_limit_mad": {
            "type": "number",
            "minimum": 0,
            "maximum": 1000000000
          }
        }
      },
      "DraftInvoice": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "customer_name",
          "issue_date",
          "line_items"
        ],
        "properties": {
          "customer_name": {
            "type": "string"
          },
          "customer_id": {
            "type": "string",
            "format": "uuid"
          },
          "issue_date": {
            "type": "string",
            "format": "date"
          },
          "currency": {
            "type": "string",
            "minLength": 3,
            "maxLength": 3
          },
          "discount_pct": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "payment_terms": {
            "enum": [
              "immediate",
              "net_30",
              "net_60",
              "custom"
            ]
          },
          "line_items": {
            "type": "array",
            "minItems": 1,
            "maxItems": 100,
            "items": {
              "type": "object",
              "required": [
                "label",
                "quantity",
                "unit_price_ht",
                "tva_rate"
              ],
              "properties": {
                "label": {
                  "type": "string"
                },
                "quantity": {
                  "type": "number",
                  "exclusiveMinimum": 0
                },
                "unit_price_ht": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1000000000
                },
                "tva_rate": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1000000000
                },
                "remise_pct": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 100
                }
              }
            }
          }
        }
      },
      "Expense": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "date",
          "description",
          "amount_ht",
          "tva_rate",
          "tva_amount",
          "amount_ttc"
        ],
        "properties": {
          "date": {
            "type": "string",
            "format": "date"
          },
          "description": {
            "type": "string"
          },
          "amount_ht": {
            "type": "number",
            "minimum": 0,
            "maximum": 1000000000
          },
          "tva_rate": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "tva_amount": {
            "type": "number",
            "minimum": 0,
            "maximum": 1000000000
          },
          "amount_ttc": {
            "type": "number",
            "minimum": 0,
            "maximum": 1000000000
          },
          "currency": {
            "type": "string"
          },
          "vendor_name": {
            "type": "string"
          }
        }
      }
    }
  }
}