{
 "openapi": "3.1.0",
 "info": {
  "title": "Ladnai API",
  "version": "1.5.0",
  "description": "Public API of Ladnai. Docs: https://ladnai.com/docs/api (uk), /docs/api/en, /docs/api/ru.",
  "contact": {
   "url": "https://ladnai.com/docs/api"
  }
 },
 "servers": [
  {
   "url": "https://panel.ladnai.com/api/v1"
  }
 ],
 "security": [
  {
   "bearer": []
  }
 ],
 "paths": {
  "/me": {
   "get": {
    "summary": "The key, its access and limits",
    "operationId": "getMe",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ApiKey"
        },
        "example": {
         "object": "api_key",
         "mode": "live",
         "livemode": true,
         "company": {
          "name": "Кава й чай"
         },
         "scopes": {
          "products": "read_write",
          "orders": "none",
          "clients": "none",
          "messages": "none",
          "calls": "none",
          "dictionaries": "read"
         },
         "limits": {
          "per_minute": 60,
          "per_day": 50000,
          "concurrent": 2,
          "batch": 500
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     }
    }
   }
  },
  "/dict/{name}": {
   "get": {
    "summary": "Company dictionary (read-only)",
    "operationId": "getDictionary",
    "parameters": [
     {
      "name": "name",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "price-lists",
        "units",
        "payment-methods",
        "currencies",
        "statuses",
        "warehouses",
        "product-groups",
        "lines",
        "managers",
        "stages",
        "tags"
       ]
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/List"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     },
     "404": {
      "$ref": "#/components/responses/Problem"
     }
    }
   }
  },
  "/products": {
   "post": {
    "summary": "Create a product (one per request; 409 already_exists if the SKU is taken by a product or variant)",
    "operationId": "createProduct",
    "parameters": [
     {
      "$ref": "#/components/parameters/IdempotencyKey"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ProductInput"
       },
       "example": {
        "sku": "KV-KEN-AA",
        "name": "Кенія АА",
        "unit": "кг",
        "group": "coffee",
        "brand": "Своя обсмажка",
        "description": "Арабіка, мита обробка\nОбсмаження: середнє",
        "alt_names": "кенійська кава, Kenya AA",
        "packs": [
         {
          "unit": "кор",
          "qty": 10
         }
        ],
        "prices": {
         "retail": "1350.00",
         "opt": {
          "price": "270.00",
          "per": "кор"
         }
        },
        "stock": {
         "kyiv": 20,
         "odesa": 5
        },
        "min_qty": 1,
        "step_qty": 0.5
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Product"
        },
        "example": {
         "object": "product",
         "id": "pa1",
         "sku": "KV-KEN-AA",
         "name": "Кенія АА",
         "brand": "Своя обсмажка",
         "description": "Арабіка, мита обробка\nОбсмаження: середнє",
         "alt_names": "кенійська кава, Kenya AA",
         "group": {
          "id": "coffee",
          "name": "Кава",
          "min_qty": null,
          "step_qty": null
         },
         "unit": "кг",
         "service": false,
         "packs": [
          {
           "unit": "кор",
           "qty": 10
          }
         ],
         "min_qty": 1,
         "step_qty": 0.5,
         "prices": [
          {
           "price_list": "opt",
           "price": "270.00",
           "currency": "USD",
           "per": "кор"
          },
          {
           "price_list": "retail",
           "price": "1350.00",
           "currency": "UAH",
           "per": "кг"
          }
         ],
         "stock": {
          "on_hand": 25,
          "reserved": 0,
          "available": 25,
          "warehouses": [
           {
            "warehouse": "kyiv",
            "on_hand": 20,
            "reserved": 0,
            "available": 20
           },
           {
            "warehouse": "odesa",
            "on_hand": 5,
            "reserved": 0,
            "available": 5
           }
          ]
         },
         "variants": [],
         "updated_at": "2026-11-15T10:20:31.512Z"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     },
     "403": {
      "$ref": "#/components/responses/Problem"
     },
     "409": {
      "$ref": "#/components/responses/Problem"
     },
     "413": {
      "$ref": "#/components/responses/Problem"
     },
     "415": {
      "$ref": "#/components/responses/Problem"
     },
     "422": {
      "$ref": "#/components/responses/Problem"
     },
     "429": {
      "$ref": "#/components/responses/Problem"
     },
     "503": {
      "$ref": "#/components/responses/Problem"
     }
    }
   },
   "get": {
    "summary": "List products",
    "operationId": "listProducts",
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "description": "1–100, default 50",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100
      }
     },
     {
      "name": "cursor",
      "in": "query",
      "required": false,
      "description": "next_cursor from the previous page",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "q",
      "in": "query",
      "required": false,
      "description": "Search in name and SKU",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "sku",
      "in": "query",
      "required": false,
      "description": "Exact SKU",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "group",
      "in": "query",
      "required": false,
      "description": "Product group id",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "updated_since",
      "in": "query",
      "required": false,
      "description": "RFC 3339 date-time",
      "schema": {
       "type": "string",
       "format": "date-time"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "allOf": [
          {
           "$ref": "#/components/schemas/List"
          },
          {
           "type": "object",
           "properties": {
            "data": {
             "type": "array",
             "items": {
              "$ref": "#/components/schemas/Product"
             }
            }
           }
          }
         ]
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/Problem"
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     },
     "403": {
      "$ref": "#/components/responses/Problem"
     },
     "429": {
      "$ref": "#/components/responses/Problem"
     }
    }
   }
  },
  "/products/{id}": {
   "get": {
    "summary": "One product",
    "operationId": "getProduct",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Product"
        },
        "example": {
         "object": "product",
         "id": "p1",
         "sku": "KV-ETH-YRG",
         "name": "Ефіопія Іргачеф",
         "brand": "Своя обсмажка",
         "description": "Арабіка 100%, мита обробка\nОбсмаження: світле\nВага: 1 кг, зерно",
         "alt_names": "Іргачефф, ефіопська кава",
         "group": {
          "id": "coffee",
          "name": "Кава",
          "min_qty": 1,
          "step_qty": null
         },
         "unit": "кг",
         "service": false,
         "packs": [
          {
           "unit": "кор",
           "qty": 10
          }
         ],
         "min_qty": 2,
         "step_qty": 0.5,
         "prices": [
          {
           "price_list": "opt",
           "price": "241.00",
           "currency": "USD",
           "per": "кор"
          },
          {
           "price_list": "retail",
           "price": "1180.00",
           "currency": "UAH",
           "per": "кг"
          }
         ],
         "stock": {
          "on_hand": 45,
          "reserved": 3,
          "available": 42,
          "warehouses": [
           {
            "warehouse": "kyiv",
            "on_hand": 34,
            "reserved": 3,
            "available": 31
           },
           {
            "warehouse": "odesa",
            "on_hand": 11,
            "reserved": 0,
            "available": 11
           }
          ]
         },
         "variants": [],
         "updated_at": "2026-10-18T09:12:54.947Z"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     },
     "403": {
      "$ref": "#/components/responses/Problem"
     },
     "404": {
      "$ref": "#/components/responses/Problem"
     }
    }
   }
  },
  "/products/batch": {
   "patch": {
    "summary": "Batch update of prices, stock, minimum order and order step (up to 500 items)",
    "operationId": "batchProducts",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/BatchRequest"
       },
       "example": {
        "items": [
         {
          "sku": "KV-ETH-YRG",
          "prices": {
           "retail": "1190.00",
           "opt": {
            "price": "245.00",
            "per": "кор"
           }
          },
          "stock": {
           "kyiv": 40
          },
          "min_qty": 2
         },
         {
          "sku": "MUG-RED",
          "stock": {
           "kyiv": 5
          }
         },
         {
          "sku": "NOPE-1",
          "stock": {
           "kyiv": 1
          }
         },
         {
          "id": "p10",
          "prices": {
           "retail": "0"
          }
         }
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Per-item results",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/BatchResult"
        },
        "example": {
         "object": "batch_result",
         "updated": 2,
         "unchanged": 0,
         "failed": 2,
         "results": [
          {
           "index": 0,
           "status": "updated",
           "id": "p1"
          },
          {
           "index": 1,
           "status": "updated",
           "id": "p14",
           "variant": "v1"
          },
          {
           "index": 2,
           "status": "failed",
           "id": null,
           "errors": [
            {
             "pointer": "/items/2/sku",
             "code": "not_found",
             "detail": "No such product."
            }
           ]
          },
          {
           "index": 3,
           "status": "failed",
           "id": "p10",
           "errors": [
            {
             "pointer": "/items/3/prices/retail",
             "code": "invalid_format",
             "detail": "Price as a string like \"1180.00\": greater than 0, at most 2 decimals."
            }
           ]
          }
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     },
     "403": {
      "$ref": "#/components/responses/Problem"
     },
     "409": {
      "$ref": "#/components/responses/Problem"
     },
     "413": {
      "$ref": "#/components/responses/Problem"
     },
     "415": {
      "$ref": "#/components/responses/Problem"
     },
     "422": {
      "$ref": "#/components/responses/Problem"
     },
     "429": {
      "$ref": "#/components/responses/Problem"
     }
    }
   }
  },
  "/clients": {
   "get": {
    "summary": "List clients",
    "operationId": "listClients",
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "description": "1–100, default 50",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100
      }
     },
     {
      "name": "cursor",
      "in": "query",
      "required": false,
      "description": "next_cursor from the previous page",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "q",
      "in": "query",
      "required": false,
      "description": "Part of name, email or city",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "phone",
      "in": "query",
      "required": false,
      "description": "Phone, 7–15 digits in any notation; only on its own",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "email",
      "in": "query",
      "required": false,
      "description": "Exact email",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "tag",
      "in": "query",
      "required": false,
      "description": "Tag id from /dict/tags",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "updated_since",
      "in": "query",
      "required": false,
      "description": "RFC 3339 date-time",
      "schema": {
       "type": "string",
       "format": "date-time"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "allOf": [
          {
           "$ref": "#/components/schemas/List"
          },
          {
           "type": "object",
           "properties": {
            "data": {
             "type": "array",
             "items": {
              "$ref": "#/components/schemas/Client"
             }
            }
           }
          }
         ]
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/Problem"
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     },
     "403": {
      "$ref": "#/components/responses/Problem"
     },
     "429": {
      "$ref": "#/components/responses/Problem"
     }
    }
   },
   "post": {
    "summary": "Create a client (409 already_exists if the full phone or email is taken)",
    "operationId": "createClient",
    "parameters": [
     {
      "$ref": "#/components/parameters/IdempotencyKey"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ClientInput"
       },
       "example": {
        "name": "Олена Кравець",
        "phone": "+380670000001",
        "email": "olena@example.com",
        "city": "Київ",
        "tags": [
         "vip"
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Client"
        },
        "example": {
         "object": "client",
         "id": "176081234500012",
         "name": "Олена Кравець",
         "phone": "+380 67 000 00 01",
         "phone_e164": "+380670000001",
         "email": "olena@example.com",
         "city": "Київ",
         "channel": "site",
         "accounts": [
          {
           "channel": "site",
           "handle": "+380670000001"
          }
         ],
         "tags": [
          {
           "id": "vip",
           "label": "VIP"
          }
         ],
         "manager": {
          "id": 2,
          "name": "Марія"
         },
         "comment": null,
         "price_list": null,
         "blocked": false,
         "orders_count": 3,
         "updated_at": "2026-10-18T09:12:54.947Z"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     },
     "403": {
      "$ref": "#/components/responses/Problem"
     },
     "409": {
      "$ref": "#/components/responses/Problem"
     },
     "415": {
      "$ref": "#/components/responses/Problem"
     },
     "422": {
      "$ref": "#/components/responses/Problem"
     },
     "429": {
      "$ref": "#/components/responses/Problem"
     }
    }
   }
  },
  "/clients/{id}": {
   "get": {
    "summary": "One client",
    "operationId": "getClient",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Client id",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Client"
        },
        "example": {
         "object": "client",
         "id": "176081234500012",
         "name": "Олена Кравець",
         "phone": "+380 67 000 00 01",
         "phone_e164": "+380670000001",
         "email": "olena@example.com",
         "city": "Київ",
         "channel": "site",
         "accounts": [
          {
           "channel": "site",
           "handle": "+380670000001"
          }
         ],
         "tags": [
          {
           "id": "vip",
           "label": "VIP"
          }
         ],
         "manager": {
          "id": 2,
          "name": "Марія"
         },
         "comment": null,
         "price_list": null,
         "blocked": false,
         "orders_count": 3,
         "updated_at": "2026-10-18T09:12:54.947Z"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     },
     "403": {
      "$ref": "#/components/responses/Problem"
     },
     "404": {
      "$ref": "#/components/responses/Problem"
     }
    }
   },
   "patch": {
    "summary": "Update a client (only the fields sent)",
    "operationId": "updateClient",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Client id",
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ClientInput"
       },
       "example": {
        "city": "Львів",
        "tags": [
         "vip",
         "opt"
        ],
        "manager_id": 2
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Client"
        },
        "example": {
         "object": "client",
         "id": "176081234500012",
         "name": "Олена Кравець",
         "phone": "+380 67 000 00 01",
         "phone_e164": "+380670000001",
         "email": "olena@example.com",
         "city": "Київ",
         "channel": "site",
         "accounts": [
          {
           "channel": "site",
           "handle": "+380670000001"
          }
         ],
         "tags": [
          {
           "id": "vip",
           "label": "VIP"
          }
         ],
         "manager": {
          "id": 2,
          "name": "Марія"
         },
         "comment": null,
         "price_list": null,
         "blocked": false,
         "orders_count": 3,
         "updated_at": "2026-10-18T09:12:54.947Z"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     },
     "403": {
      "$ref": "#/components/responses/Problem"
     },
     "404": {
      "$ref": "#/components/responses/Problem"
     },
     "409": {
      "$ref": "#/components/responses/Problem"
     },
     "415": {
      "$ref": "#/components/responses/Problem"
     },
     "422": {
      "$ref": "#/components/responses/Problem"
     },
     "429": {
      "$ref": "#/components/responses/Problem"
     }
    }
   }
  },
  "/orders": {
   "get": {
    "summary": "List orders",
    "operationId": "listOrders",
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "description": "1–100, default 50",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100
      }
     },
     {
      "name": "cursor",
      "in": "query",
      "required": false,
      "description": "next_cursor from the previous page",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "status",
      "in": "query",
      "required": false,
      "description": "Status name from /dict/statuses",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "client_id",
      "in": "query",
      "required": false,
      "description": "Client id",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "external_id",
      "in": "query",
      "required": false,
      "description": "Order number on your website",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "q",
      "in": "query",
      "required": false,
      "description": "Part of the number or waybill",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "updated_since",
      "in": "query",
      "required": false,
      "description": "RFC 3339 date-time",
      "schema": {
       "type": "string",
       "format": "date-time"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "allOf": [
          {
           "$ref": "#/components/schemas/List"
          },
          {
           "type": "object",
           "properties": {
            "data": {
             "type": "array",
             "items": {
              "$ref": "#/components/schemas/Order"
             }
            }
           }
          }
         ]
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/Problem"
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     },
     "403": {
      "$ref": "#/components/responses/Problem"
     },
     "429": {
      "$ref": "#/components/responses/Problem"
     }
    }
   },
   "post": {
    "summary": "Create an order (e.g. from a website)",
    "operationId": "createOrder",
    "parameters": [
     {
      "$ref": "#/components/parameters/IdempotencyKey"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/OrderInput"
       },
       "example": {
        "external_id": "WC-1042",
        "client": {
         "name": "Олена Кравець",
         "phone": "+380 67 000 00 01",
         "city": "Київ"
        },
        "items": [
         {
          "sku": "KV-ETH-YRG",
          "quantity": 2
         },
         {
          "sku": "MUG-RED",
          "quantity": 1,
          "price": "349.00"
         }
        ],
        "delivery": "Нова Пошта, Київ, відділення №12",
        "payment": {
         "term": "pre",
         "method": "card"
        },
        "paid": {
         "amount": "2709.00",
         "method": "card",
         "note": "LiqPay 4417"
        },
        "comment": "Подзвонити після 18:00"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Order"
        },
        "example": {
         "object": "order",
         "number": "45401",
         "date": "2026-10-18",
         "status": {
          "name": "Нове",
          "step": 0,
          "system": "new"
         },
         "client": {
          "id": "176081234500012",
          "name": "Олена Кравець",
          "phone": "+380670000001"
         },
         "currency": "UAH",
         "total": "2709.00",
         "paid": "2709.00",
         "due": "0.00",
         "subtotal": null,
         "price_list": "retail",
         "rate": null,
         "items": [
          {
           "id": "l1",
           "product_id": "p1",
           "variant_id": null,
           "warehouse": "kyiv",
           "name": "Ефіопія Іргачеф",
           "sku": "KV-ETH-YRG",
           "quantity": 2,
           "unit": "кг",
           "pack_qty": 1,
           "price": "1180.00",
           "amount": "2360.00",
           "reserved": 2,
           "shipped": 0
          },
          {
           "id": "l2",
           "product_id": "p14",
           "variant_id": "v1",
           "warehouse": "kyiv",
           "name": "Чашка · Червоний",
           "sku": "MUG-RED",
           "quantity": 1,
           "unit": "шт",
           "pack_qty": 1,
           "price": "349.00",
           "amount": "349.00",
           "reserved": 1,
           "shipped": 0
          }
         ],
         "delivery": "Нова Пошта, Київ, відділення №12",
         "ttn": null,
         "payment": {
          "term": "pre",
          "method": {
           "id": "card",
           "name": "Картка"
          },
          "text": "Передоплата · Картка",
          "due_date": null
         },
         "payments": [
          {
           "id": "p176081234500077",
           "amount": "2709.00",
           "method": "card",
           "at": "2026-10-18T09:12:54.947Z",
           "reconciled": false
          }
         ],
         "cancel_reason": null,
         "source": "site",
         "external_id": "WC-1042",
         "updated_at": "2026-10-18T09:12:54.947Z"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     },
     "402": {
      "$ref": "#/components/responses/Problem"
     },
     "403": {
      "$ref": "#/components/responses/Problem"
     },
     "409": {
      "$ref": "#/components/responses/Problem"
     },
     "413": {
      "$ref": "#/components/responses/Problem"
     },
     "415": {
      "$ref": "#/components/responses/Problem"
     },
     "422": {
      "$ref": "#/components/responses/Problem"
     },
     "429": {
      "$ref": "#/components/responses/Problem"
     }
    }
   }
  },
  "/orders/{number}": {
   "get": {
    "summary": "One order",
    "operationId": "getOrder",
    "parameters": [
     {
      "name": "number",
      "in": "path",
      "required": true,
      "description": "Order number without #",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Order"
        },
        "example": {
         "object": "order",
         "number": "45401",
         "date": "2026-10-18",
         "status": {
          "name": "Нове",
          "step": 0,
          "system": "new"
         },
         "client": {
          "id": "176081234500012",
          "name": "Олена Кравець",
          "phone": "+380670000001"
         },
         "currency": "UAH",
         "total": "2709.00",
         "paid": "2709.00",
         "due": "0.00",
         "subtotal": null,
         "price_list": "retail",
         "rate": null,
         "items": [
          {
           "id": "l1",
           "product_id": "p1",
           "variant_id": null,
           "warehouse": "kyiv",
           "name": "Ефіопія Іргачеф",
           "sku": "KV-ETH-YRG",
           "quantity": 2,
           "unit": "кг",
           "pack_qty": 1,
           "price": "1180.00",
           "amount": "2360.00",
           "reserved": 2,
           "shipped": 0
          },
          {
           "id": "l2",
           "product_id": "p14",
           "variant_id": "v1",
           "warehouse": "kyiv",
           "name": "Чашка · Червоний",
           "sku": "MUG-RED",
           "quantity": 1,
           "unit": "шт",
           "pack_qty": 1,
           "price": "349.00",
           "amount": "349.00",
           "reserved": 1,
           "shipped": 0
          }
         ],
         "delivery": "Нова Пошта, Київ, відділення №12",
         "ttn": null,
         "payment": {
          "term": "pre",
          "method": {
           "id": "card",
           "name": "Картка"
          },
          "text": "Передоплата · Картка",
          "due_date": null
         },
         "payments": [
          {
           "id": "p176081234500077",
           "amount": "2709.00",
           "method": "card",
           "at": "2026-10-18T09:12:54.947Z",
           "reconciled": false
          }
         ],
         "cancel_reason": null,
         "source": "site",
         "external_id": "WC-1042",
         "updated_at": "2026-10-18T09:12:54.947Z"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     },
     "403": {
      "$ref": "#/components/responses/Problem"
     },
     "404": {
      "$ref": "#/components/responses/Problem"
     }
    }
   },
   "patch": {
    "summary": "Change status, waybill, delivery or add a comment",
    "operationId": "updateOrder",
    "parameters": [
     {
      "name": "number",
      "in": "path",
      "required": true,
      "description": "Order number without #",
      "schema": {
       "type": "string"
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/OrderUpdate"
       },
       "example": {
        "status": "Відправлено",
        "ttn": "20450000000001"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Order"
        },
        "example": {
         "object": "order",
         "number": "45401",
         "date": "2026-10-18",
         "status": {
          "name": "Нове",
          "step": 0,
          "system": "new"
         },
         "client": {
          "id": "176081234500012",
          "name": "Олена Кравець",
          "phone": "+380670000001"
         },
         "currency": "UAH",
         "total": "2709.00",
         "paid": "2709.00",
         "due": "0.00",
         "subtotal": null,
         "price_list": "retail",
         "rate": null,
         "items": [
          {
           "id": "l1",
           "product_id": "p1",
           "variant_id": null,
           "warehouse": "kyiv",
           "name": "Ефіопія Іргачеф",
           "sku": "KV-ETH-YRG",
           "quantity": 2,
           "unit": "кг",
           "pack_qty": 1,
           "price": "1180.00",
           "amount": "2360.00",
           "reserved": 2,
           "shipped": 0
          },
          {
           "id": "l2",
           "product_id": "p14",
           "variant_id": "v1",
           "warehouse": "kyiv",
           "name": "Чашка · Червоний",
           "sku": "MUG-RED",
           "quantity": 1,
           "unit": "шт",
           "pack_qty": 1,
           "price": "349.00",
           "amount": "349.00",
           "reserved": 1,
           "shipped": 0
          }
         ],
         "delivery": "Нова Пошта, Київ, відділення №12",
         "ttn": null,
         "payment": {
          "term": "pre",
          "method": {
           "id": "card",
           "name": "Картка"
          },
          "text": "Передоплата · Картка",
          "due_date": null
         },
         "payments": [
          {
           "id": "p176081234500077",
           "amount": "2709.00",
           "method": "card",
           "at": "2026-10-18T09:12:54.947Z",
           "reconciled": false
          }
         ],
         "cancel_reason": null,
         "source": "site",
         "external_id": "WC-1042",
         "updated_at": "2026-10-18T09:12:54.947Z"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     },
     "403": {
      "$ref": "#/components/responses/Problem"
     },
     "404": {
      "$ref": "#/components/responses/Problem"
     },
     "409": {
      "$ref": "#/components/responses/Problem"
     },
     "415": {
      "$ref": "#/components/responses/Problem"
     },
     "422": {
      "$ref": "#/components/responses/Problem"
     },
     "429": {
      "$ref": "#/components/responses/Problem"
     }
    }
   }
  },
  "/messages": {
   "post": {
    "summary": "Send a text to a client into an existing conversation (202, queued)",
    "operationId": "sendMessage",
    "parameters": [
     {
      "$ref": "#/components/parameters/IdempotencyKey"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/MessageInput"
       },
       "example": {
        "client_id": "176081234500012",
        "text": "Ваше замовлення №45401 прийнято. Дякуємо!"
       }
      }
     }
    },
    "responses": {
     "202": {
      "description": "Accepted",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Message"
        },
        "example": {
         "object": "message",
         "id": "176081234500101",
         "client_id": "176081234500012",
         "dialog_id": "176081234500013",
         "line": {
          "id": "l-tg1",
          "name": "Кава й чай",
          "channel": "telegram"
         },
         "text": "Ваше замовлення №45401 прийнято. Дякуємо!",
         "status": "sending",
         "fail_reason": null,
         "created_at": "2026-10-18T09:13:02.114Z"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     },
     "402": {
      "$ref": "#/components/responses/Problem"
     },
     "403": {
      "$ref": "#/components/responses/Problem"
     },
     "404": {
      "$ref": "#/components/responses/Problem"
     },
     "409": {
      "$ref": "#/components/responses/Problem"
     },
     "415": {
      "$ref": "#/components/responses/Problem"
     },
     "422": {
      "$ref": "#/components/responses/Problem"
     },
     "429": {
      "$ref": "#/components/responses/Problem"
     }
    }
   }
  },
  "/messages/{id}": {
   "get": {
    "summary": "A message sent through the API — delivery status",
    "operationId": "getMessage",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Message id",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Message"
        },
        "example": {
         "object": "message",
         "id": "176081234500101",
         "client_id": "176081234500012",
         "dialog_id": "176081234500013",
         "line": {
          "id": "l-tg1",
          "name": "Кава й чай",
          "channel": "telegram"
         },
         "text": "Ваше замовлення №45401 прийнято. Дякуємо!",
         "status": "sending",
         "fail_reason": null,
         "created_at": "2026-10-18T09:13:02.114Z"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     },
     "403": {
      "$ref": "#/components/responses/Problem"
     },
     "404": {
      "$ref": "#/components/responses/Problem"
     }
    }
   }
  },
  "/calls": {
   "get": {
    "summary": "Call log",
    "operationId": "listCalls",
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "description": "1–100, default 50",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100
      }
     },
     {
      "name": "cursor",
      "in": "query",
      "required": false,
      "description": "next_cursor from the previous page",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "from",
      "in": "query",
      "required": false,
      "description": "Started at or after (RFC 3339)",
      "schema": {
       "type": "string",
       "format": "date-time"
      }
     },
     {
      "name": "to",
      "in": "query",
      "required": false,
      "description": "Started before (RFC 3339)",
      "schema": {
       "type": "string",
       "format": "date-time"
      }
     },
     {
      "name": "client_id",
      "in": "query",
      "required": false,
      "description": "Client id",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "line_id",
      "in": "query",
      "required": false,
      "description": "Line id",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "direction",
      "in": "query",
      "required": false,
      "description": "inbound or outbound",
      "schema": {
       "enum": [
        "inbound",
        "outbound"
       ]
      }
     },
     {
      "name": "state",
      "in": "query",
      "required": false,
      "description": "Call state",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "allOf": [
          {
           "$ref": "#/components/schemas/List"
          },
          {
           "type": "object",
           "properties": {
            "data": {
             "type": "array",
             "items": {
              "$ref": "#/components/schemas/Call"
             }
            }
           }
          }
         ]
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/Problem"
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     },
     "403": {
      "$ref": "#/components/responses/Problem"
     },
     "429": {
      "$ref": "#/components/responses/Problem"
     }
    }
   }
  },
  "/calls/{id}": {
   "get": {
    "summary": "One call",
    "operationId": "getCall",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Call id",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Call"
        },
        "example": {
         "object": "call",
         "id": "176081234500300",
         "direction": "inbound",
         "state": "completed",
         "line": {
          "id": "l-tg1",
          "name": "Кава й чай",
          "channel": "telegram"
         },
         "kind": "telegram",
         "client": {
          "id": "176081234500012",
          "name": "Олена Кравець",
          "phone": "+380670000001"
         },
         "started_at": "2026-10-18T08:01:10.000Z",
         "answered_at": "2026-10-18T08:01:16.000Z",
         "ended_at": "2026-10-18T08:05:40.000Z",
         "duration": 264,
         "answered_by": {
          "id": 2,
          "name": "Марія"
         },
         "initiated_by": null,
         "recording": {
          "size": 1048576,
          "format": "m4a",
          "url": "/v1/calls/176081234500300/recording"
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     },
     "403": {
      "$ref": "#/components/responses/Problem"
     },
     "404": {
      "$ref": "#/components/responses/Problem"
     }
    }
   }
  },
  "/calls/{id}/recording": {
   "get": {
    "summary": "Call recording file (if the company allows downloads)",
    "operationId": "getCallRecording",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "description": "Call id",
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Audio file",
      "content": {
       "audio/mp4": {
        "schema": {
         "type": "string",
         "format": "binary"
        }
       },
       "audio/ogg": {
        "schema": {
         "type": "string",
         "format": "binary"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Problem"
     },
     "403": {
      "$ref": "#/components/responses/Problem"
     },
     "404": {
      "$ref": "#/components/responses/Problem"
     },
     "503": {
      "$ref": "#/components/responses/Problem"
     }
    }
   }
  }
 },
 "webhooks": {
  "message.new": {
   "post": {
    "summary": "A client wrote in any channel",
    "operationId": "webhook_message_new",
    "security": [],
    "parameters": [
     {
      "name": "X-Ladnai-Signature",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "t=<unix seconds>,v1=<hex HMAC-SHA256(secret, t + '.' + raw body)>; two v1 while the old secret is kept for 24 h. Reject if t is more than 5 minutes off."
     },
     {
      "name": "X-Ladnai-Event",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "message.new",
        "call.new",
        "order.status",
        "order.confirmed",
        "stock.changed",
        "test"
       ]
      }
     },
     {
      "name": "X-Ladnai-Event-Id",
      "in": "header",
      "required": true,
      "description": "Same as id in the body; identical in every retry — deduplicate by it",
      "schema": {
       "type": "string",
       "pattern": "^evt_[0-9a-f]{24}$"
      }
     },
     {
      "name": "X-Ladnai-Attempt",
      "in": "header",
      "required": true,
      "schema": {
       "type": "integer",
       "minimum": 1
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "allOf": [
         {
          "$ref": "#/components/schemas/WebhookEvent"
         },
         {
          "type": "object",
          "properties": {
           "event": {
            "const": "message.new"
           },
           "data": {
            "$ref": "#/components/schemas/HookMessageNew"
           }
          }
         }
        ]
       },
       "example": {
        "id": "evt_6f1c2a9e0b7d4c3a8e5f1d20",
        "event": "message.new",
        "created": "2026-10-18T09:41:09.004Z",
        "data": {
         "message": {
          "id": "176078045500137",
          "client_id": "176081234500012",
          "dialog_id": "176081234500013",
          "line": {
           "id": "l-tg1",
           "name": "Кава й чай",
           "channel": "telegram"
          },
          "kind": "text",
          "text": "Добрий день! Ефіопія Іргачеф 1 кг є в наявності?",
          "file": null,
          "created_at": "2026-10-18T09:40:55.137Z"
         },
         "client": {
          "id": "176081234500012",
          "name": "Олена Кравець",
          "phone": "+380 67 000 00 01"
         }
        }
       }
      }
     }
    },
    "responses": {
     "2XX": {
      "description": "Received. No 2xx within 10 s, a connection error or a redirect is retried 1, 5, 15, 30 and 60 min after the first attempt; 410 turns the company's webhooks off."
     }
    }
   }
  },
  "call.new": {
   "post": {
    "summary": "A call ended (a recorded one — once the recording is ready)",
    "operationId": "webhook_call_new",
    "security": [],
    "parameters": [
     {
      "name": "X-Ladnai-Signature",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "t=<unix seconds>,v1=<hex HMAC-SHA256(secret, t + '.' + raw body)>; two v1 while the old secret is kept for 24 h. Reject if t is more than 5 minutes off."
     },
     {
      "name": "X-Ladnai-Event",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "message.new",
        "call.new",
        "order.status",
        "order.confirmed",
        "stock.changed",
        "test"
       ]
      }
     },
     {
      "name": "X-Ladnai-Event-Id",
      "in": "header",
      "required": true,
      "description": "Same as id in the body; identical in every retry — deduplicate by it",
      "schema": {
       "type": "string",
       "pattern": "^evt_[0-9a-f]{24}$"
      }
     },
     {
      "name": "X-Ladnai-Attempt",
      "in": "header",
      "required": true,
      "schema": {
       "type": "integer",
       "minimum": 1
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "allOf": [
         {
          "$ref": "#/components/schemas/WebhookEvent"
         },
         {
          "type": "object",
          "properties": {
           "event": {
            "const": "call.new"
           },
           "data": {
            "type": "object",
            "properties": {
             "call": {
              "$ref": "#/components/schemas/Call"
             }
            }
           }
          }
         }
        ]
       },
       "example": {
        "id": "evt_91d0e4b7a2c35f8e1b6d0a44",
        "event": "call.new",
        "created": "2026-10-18T10:05:31.420Z",
        "data": {
         "call": {
          "object": "call",
          "id": "176081234500300",
          "direction": "inbound",
          "state": "completed",
          "line": {
           "id": "l-tg1",
           "name": "Кава й чай",
           "channel": "telegram"
          },
          "kind": "telegram",
          "client": {
           "id": "176081234500012",
           "name": "Олена Кравець",
           "phone": "+380670000001"
          },
          "started_at": "2026-10-18T08:01:10.000Z",
          "answered_at": "2026-10-18T08:01:16.000Z",
          "ended_at": "2026-10-18T08:05:40.000Z",
          "duration": 264,
          "answered_by": {
           "id": 2,
           "name": "Марія"
          },
          "initiated_by": null,
          "recording": {
           "size": 1048576,
           "format": "m4a",
           "url": "/v1/calls/176081234500300/recording"
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "2XX": {
      "description": "Received. No 2xx within 10 s, a connection error or a redirect is retried 1, 5, 15, 30 and 60 min after the first attempt; 410 turns the company's webhooks off."
     }
    }
   }
  },
  "order.status": {
   "post": {
    "summary": "An order status changed or a new order appeared (previous_status null)",
    "operationId": "webhook_order_status",
    "security": [],
    "parameters": [
     {
      "name": "X-Ladnai-Signature",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "t=<unix seconds>,v1=<hex HMAC-SHA256(secret, t + '.' + raw body)>; two v1 while the old secret is kept for 24 h. Reject if t is more than 5 minutes off."
     },
     {
      "name": "X-Ladnai-Event",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "message.new",
        "call.new",
        "order.status",
        "order.confirmed",
        "stock.changed",
        "test"
       ]
      }
     },
     {
      "name": "X-Ladnai-Event-Id",
      "in": "header",
      "required": true,
      "description": "Same as id in the body; identical in every retry — deduplicate by it",
      "schema": {
       "type": "string",
       "pattern": "^evt_[0-9a-f]{24}$"
      }
     },
     {
      "name": "X-Ladnai-Attempt",
      "in": "header",
      "required": true,
      "schema": {
       "type": "integer",
       "minimum": 1
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "allOf": [
         {
          "$ref": "#/components/schemas/WebhookEvent"
         },
         {
          "type": "object",
          "properties": {
           "event": {
            "const": "order.status"
           },
           "data": {
            "$ref": "#/components/schemas/HookOrderStatus"
           }
          }
         }
        ]
       },
       "example": {
        "id": "evt_c4a87e21f90b3d65a7e2c1b9",
        "event": "order.status",
        "created": "2026-10-18T11:20:02.871Z",
        "data": {
         "order": {
          "number": "45401",
          "external_id": "WC-1042",
          "status": {
           "name": "Відправлено",
           "step": 3,
           "system": null
          },
          "previous_status": {
           "name": "Підтверджено",
           "step": 2,
           "system": null
          },
          "client": {
           "id": "176081234500012",
           "name": "Олена Кравець",
           "phone": "+380 67 000 00 01"
          },
          "total": "2360.00",
          "currency": "UAH",
          "ttn": "20450000000001",
          "source": "site"
         },
         "changed_by": {
          "type": "user",
          "id": 2,
          "name": "Ірина Мельник"
         },
         "changed_at": "2026-10-18T11:20:02.865Z"
        }
       }
      }
     }
    },
    "responses": {
     "2XX": {
      "description": "Received. No 2xx within 10 s, a connection error or a redirect is retried 1, 5, 15, 30 and 60 min after the first attempt; 410 turns the company's webhooks off."
     }
    }
   }
  },
  "order.confirmed": {
   "post": {
    "summary": "The client confirmed the order by the ladn.me link (as is or with changes)",
    "operationId": "webhook_order_confirmed",
    "security": [],
    "parameters": [
     {
      "name": "X-Ladnai-Signature",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "t=<unix seconds>,v1=<hex HMAC-SHA256(secret, t + '.' + raw body)>; two v1 while the old secret is kept for 24 h. Reject if t is more than 5 minutes off."
     },
     {
      "name": "X-Ladnai-Event",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "message.new",
        "call.new",
        "order.status",
        "order.confirmed",
        "stock.changed",
        "test"
       ]
      }
     },
     {
      "name": "X-Ladnai-Event-Id",
      "in": "header",
      "required": true,
      "description": "Same as id in the body; identical in every retry — deduplicate by it",
      "schema": {
       "type": "string",
       "pattern": "^evt_[0-9a-f]{24}$"
      }
     },
     {
      "name": "X-Ladnai-Attempt",
      "in": "header",
      "required": true,
      "schema": {
       "type": "integer",
       "minimum": 1
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "allOf": [
         {
          "$ref": "#/components/schemas/WebhookEvent"
         },
         {
          "type": "object",
          "properties": {
           "event": {
            "const": "order.confirmed"
           },
           "data": {
            "$ref": "#/components/schemas/HookOrderConfirmed"
           }
          }
         }
        ]
       },
       "example": {
        "id": "evt_8d2f6b1e9c0a4e7d3b5f2a61",
        "event": "order.confirmed",
        "created": "2026-10-27T10:12:44.208Z",
        "data": {
         "order": {
          "number": "45401",
          "external_id": "WC-1042",
          "status": "Підтверджено",
          "client": {
           "id": "176081234500012",
           "name": "Олена Кравець",
           "phone": "+380 67 000 00 01"
          },
          "total": "2360.00",
          "currency": "UAH"
         },
         "changes": [
          "адреса: Київ, Відділення №12"
         ],
         "comment": "Зателефонуйте перед відправкою, будь ласка",
         "recipient": {
          "name": "Олена Кравець",
          "phone": "+380 67 000 00 01",
          "city": "Київ",
          "branch": "Відділення №12"
         },
         "confirmed_at": "2026-10-27T10:12:44.193Z"
        }
       }
      }
     }
    },
    "responses": {
     "2XX": {
      "description": "Received. No 2xx within 10 s, a connection error or a redirect is retried 1, 5, 15, 30 and 60 min after the first attempt; 410 turns the company's webhooks off."
     }
    }
   }
  },
  "stock.changed": {
   "post": {
    "summary": "Stock or reservation of a product or variant changed",
    "operationId": "webhook_stock_changed",
    "security": [],
    "parameters": [
     {
      "name": "X-Ladnai-Signature",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "t=<unix seconds>,v1=<hex HMAC-SHA256(secret, t + '.' + raw body)>; two v1 while the old secret is kept for 24 h. Reject if t is more than 5 minutes off."
     },
     {
      "name": "X-Ladnai-Event",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "message.new",
        "call.new",
        "order.status",
        "order.confirmed",
        "stock.changed",
        "test"
       ]
      }
     },
     {
      "name": "X-Ladnai-Event-Id",
      "in": "header",
      "required": true,
      "description": "Same as id in the body; identical in every retry — deduplicate by it",
      "schema": {
       "type": "string",
       "pattern": "^evt_[0-9a-f]{24}$"
      }
     },
     {
      "name": "X-Ladnai-Attempt",
      "in": "header",
      "required": true,
      "schema": {
       "type": "integer",
       "minimum": 1
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "allOf": [
         {
          "$ref": "#/components/schemas/WebhookEvent"
         },
         {
          "type": "object",
          "properties": {
           "event": {
            "const": "stock.changed"
           },
           "data": {
            "$ref": "#/components/schemas/HookStockChanged"
           }
          }
         }
        ]
       },
       "example": {
        "id": "evt_5e2b7d1c8a9f04e3b6a1d7c2",
        "event": "stock.changed",
        "created": "2026-10-18T11:20:02.871Z",
        "data": {
         "product": {
          "id": "p1",
          "sku": "KV-ETH-YRG",
          "name": "Ефіопія Іргачеф",
          "unit": "кг"
         },
         "variant": null,
         "on_hand": 43.0,
         "reserved": 1.0,
         "available": 42.0,
         "warehouses": [
          {
           "warehouse": {
            "id": "kyiv",
            "name": "Київ"
           },
           "on_hand": 32.0,
           "reserved": 1.0,
           "available": 31.0,
           "previous": {
            "on_hand": 34.0,
            "reserved": 3.0,
            "available": 31.0
           }
          }
         ],
         "changed_at": "2026-10-18T11:20:02.866Z"
        }
       }
      }
     }
    },
    "responses": {
     "2XX": {
      "description": "Received. No 2xx within 10 s, a connection error or a redirect is retried 1, 5, 15, 30 and 60 min after the first attempt; 410 turns the company's webhooks off."
     }
    }
   }
  },
  "test": {
   "post": {
    "summary": "Test request from the account",
    "operationId": "webhook_test",
    "security": [],
    "parameters": [
     {
      "name": "X-Ladnai-Signature",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "t=<unix seconds>,v1=<hex HMAC-SHA256(secret, t + '.' + raw body)>; two v1 while the old secret is kept for 24 h. Reject if t is more than 5 minutes off."
     },
     {
      "name": "X-Ladnai-Event",
      "in": "header",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "message.new",
        "call.new",
        "order.status",
        "order.confirmed",
        "stock.changed",
        "test"
       ]
      }
     },
     {
      "name": "X-Ladnai-Event-Id",
      "in": "header",
      "required": true,
      "description": "Same as id in the body; identical in every retry — deduplicate by it",
      "schema": {
       "type": "string",
       "pattern": "^evt_[0-9a-f]{24}$"
      }
     },
     {
      "name": "X-Ladnai-Attempt",
      "in": "header",
      "required": true,
      "schema": {
       "type": "integer",
       "minimum": 1
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "allOf": [
         {
          "$ref": "#/components/schemas/WebhookEvent"
         },
         {
          "type": "object",
          "properties": {
           "event": {
            "const": "test"
           },
           "data": {
            "type": "object",
            "properties": {
             "message": {
              "type": "string"
             },
             "sent_by": {
              "type": "object",
              "properties": {
               "id": {
                "type": "integer"
               },
               "name": {
                "type": "string"
               }
              }
             }
            }
           }
          }
         }
        ]
       },
       "example": {
        "id": "evt_3b9d1f0a7c2e4b6d8a1f5e70",
        "event": "test",
        "created": "2026-10-18T09:41:07.312Z",
        "data": {
         "message": "Тестовий запит з Ладнай — адреса й підпис працюють",
         "sent_by": {
          "id": 1,
          "name": "Олена Кравець"
         }
        }
       }
      }
     }
    },
    "responses": {
     "2XX": {
      "description": "Received. No 2xx within 10 s, a connection error or a redirect is retried 1, 5, 15, 30 and 60 min after the first attempt; 410 turns the company's webhooks off."
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "bearer": {
    "type": "http",
    "scheme": "bearer",
    "description": "ld_live_… or ld_test_… key from Settings → Integrations → API. Header only, never in the URL."
   }
  },
  "responses": {
   "Problem": {
    "description": "RFC 9457 problem",
    "content": {
     "application/problem+json": {
      "schema": {
       "$ref": "#/components/schemas/Problem"
      }
     }
    }
   }
  },
  "parameters": {
   "IdempotencyKey": {
    "name": "Idempotency-Key",
    "in": "header",
    "required": false,
    "description": "8–255 characters [A-Za-z0-9_-:.]. A retry with the same key and body returns the stored response (24 h) with Idempotent-Replayed: true.",
    "schema": {
     "type": "string",
     "pattern": "^[A-Za-z0-9_\\-:.]{8,255}$"
    }
   }
  },
  "schemas": {
   "Problem": {
    "type": "object",
    "required": [
     "type",
     "title",
     "status",
     "code",
     "request_id"
    ],
    "properties": {
     "type": {
      "type": "string",
      "format": "uri"
     },
     "title": {
      "type": "string"
     },
     "status": {
      "type": "integer"
     },
     "code": {
      "type": "string",
      "enum": [
       "https_required",
       "key_in_url",
       "invalid_json",
       "unknown_parameter",
       "invalid_parameter",
       "invalid_cursor",
       "missing_api_key",
       "invalid_api_key",
       "api_key_revoked",
       "api_key_expired",
       "read_only",
       "blocked",
       "trial_limit",
       "plan_limit",
       "line_paused",
       "ip_not_allowed",
       "insufficient_scope",
       "recording_download_disabled",
       "module_key",
       "module_only",
       "module_off",
       "not_found",
       "method_not_allowed",
       "not_acceptable",
       "conflict",
       "already_exists",
       "idempotency_in_progress",
       "client_blocked",
       "payload_too_large",
       "unsupported_media_type",
       "unsupported_encoding",
       "validation_failed",
       "idempotency_key_reused",
       "no_dialog",
       "rate_limited",
       "too_many_concurrent",
       "too_many_failed_auth",
       "server_error",
       "sandbox_unavailable",
       "unavailable",
       "storage_unavailable"
      ]
     },
     "detail": {
      "type": "string"
     },
     "request_id": {
      "type": "string"
     },
     "errors": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/FieldError"
      }
     }
    }
   },
   "FieldError": {
    "type": "object",
    "properties": {
     "pointer": {
      "type": "string",
      "description": "RFC 6901 JSON Pointer"
     },
     "code": {
      "type": "string",
      "enum": [
       "required",
       "unknown_field",
       "invalid_type",
       "invalid_format",
       "invalid_value",
       "not_found",
       "duplicate",
       "not_allowed",
       "below_reserved",
       "conflict",
       "too_long",
       "insufficient_stock",
       "too_many"
      ]
     },
     "detail": {
      "type": "string"
     }
    }
   },
   "List": {
    "type": "object",
    "properties": {
     "object": {
      "const": "list"
     },
     "data": {
      "type": "array"
     },
     "has_more": {
      "type": "boolean"
     },
     "next_cursor": {
      "type": [
       "string",
       "null"
      ]
     }
    }
   },
   "ApiKey": {
    "type": "object",
    "properties": {
     "object": {
      "const": "api_key"
     },
     "mode": {
      "enum": [
       "live",
       "test"
      ]
     },
     "livemode": {
      "type": "boolean"
     },
     "company": {
      "type": "object",
      "properties": {
       "name": {
        "type": "string"
       }
      }
     },
     "scopes": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      }
     },
     "limits": {
      "type": "object",
      "properties": {
       "per_minute": {
        "type": "integer"
       },
       "per_day": {
        "type": "integer"
       },
       "concurrent": {
        "type": "integer"
       },
       "batch": {
        "type": "integer"
       }
      }
     }
    }
   },
   "Product": {
    "type": "object",
    "properties": {
     "object": {
      "const": "product"
     },
     "id": {
      "type": "string"
     },
     "sku": {
      "type": "string"
     },
     "name": {
      "type": "string"
     },
     "brand": {
      "type": "string"
     },
     "description": {
      "type": "string",
      "maxLength": 2000,
      "description": "Description and specifications, plain text (lines separated by \\n)"
     },
     "alt_names": {
      "type": "string",
      "maxLength": 1000,
      "description": "Other names, comma-separated — how customers call the product"
     },
     "group": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "id": {
        "type": "string"
       },
       "name": {
        "type": "string"
       },
       "min_qty": {
        "type": [
         "number",
         "null"
        ],
        "description": "The group's minimum order (base unit); null — none"
       },
       "step_qty": {
        "type": [
         "number",
         "null"
        ],
        "description": "The group's order step (base unit); null — none"
       }
      }
     },
     "unit": {
      "type": "string"
     },
     "service": {
      "type": "boolean"
     },
     "packs": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "unit": {
         "type": "string"
        },
        "qty": {
         "type": "number"
        }
       }
      }
     },
     "min_qty": {
      "type": [
       "number",
       "null"
      ],
      "description": "The product's own minimum order in the base unit; null — the group's applies"
     },
     "step_qty": {
      "type": [
       "number",
       "null"
      ],
      "description": "The product's own order step in the base unit; null — the group's applies"
     },
     "prices": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "price_list": {
         "type": "string"
        },
        "price": {
         "type": "string",
         "pattern": "^\\d+\\.\\d{2}$"
        },
        "currency": {
         "type": "string"
        },
        "per": {
         "type": "string"
        }
       }
      }
     },
     "stock": {
      "oneOf": [
       {
        "type": "object",
        "properties": {
         "on_hand": {
          "type": "number"
         },
         "reserved": {
          "type": "number"
         },
         "available": {
          "type": "number"
         },
         "warehouses": {
          "type": "array",
          "items": {
           "type": "object",
           "properties": {
            "warehouse": {
             "type": "string"
            },
            "on_hand": {
             "type": "number"
            },
            "reserved": {
             "type": "number"
            },
            "available": {
             "type": "number"
            }
           }
          }
         }
        }
       },
       {
        "type": "null"
       }
      ]
     },
     "variants": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "id": {
         "type": "string"
        },
        "name": {
         "type": "string"
        },
        "sku": {
         "type": "string"
        },
        "stock": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "on_hand": {
             "type": "number"
            },
            "reserved": {
             "type": "number"
            },
            "available": {
             "type": "number"
            },
            "warehouses": {
             "type": "array",
             "items": {
              "type": "object",
              "properties": {
               "warehouse": {
                "type": "string"
               },
               "on_hand": {
                "type": "number"
               },
               "reserved": {
                "type": "number"
               },
               "available": {
                "type": "number"
               }
              }
             }
            }
           }
          },
          {
           "type": "null"
          }
         ]
        }
       }
      }
     },
     "updated_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "BatchRequest": {
    "type": "object",
    "required": [
     "items"
    ],
    "additionalProperties": false,
    "properties": {
     "atomic": {
      "type": "boolean",
      "default": false
     },
     "items": {
      "type": "array",
      "minItems": 1,
      "maxItems": 500,
      "items": {
       "type": "object",
       "additionalProperties": false,
       "properties": {
        "id": {
         "type": "string"
        },
        "sku": {
         "type": "string"
        },
        "variant": {
         "type": "string"
        },
        "prices": {
         "type": "object",
         "additionalProperties": {
          "oneOf": [
           {
            "type": "string"
           },
           {
            "type": "null"
           },
           {
            "type": "object",
            "properties": {
             "price": {
              "type": "string"
             },
             "per": {
              "type": "string"
             }
            },
            "required": [
             "price"
            ]
           }
          ]
         }
        },
        "stock": {
         "type": "object",
         "additionalProperties": {
          "type": "number",
          "minimum": 0
         }
        },
        "min_qty": {
         "type": [
          "number",
          "null"
         ],
         "minimum": 0,
         "maximum": 1000000,
         "description": "Product only; null or 0 — as in the group"
        },
        "step_qty": {
         "type": [
          "number",
          "null"
         ],
         "minimum": 0,
         "maximum": 1000000,
         "description": "Product only; null or 0 — as in the group"
        }
       }
      }
     }
    }
   },
   "ProductInput": {
    "type": "object",
    "required": [
     "sku",
     "name",
     "prices"
    ],
    "additionalProperties": false,
    "properties": {
     "sku": {
      "type": "string",
      "minLength": 1,
      "maxLength": 64
     },
     "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 255
     },
     "unit": {
      "type": "string",
      "description": "Unit id from /dict/units; default «шт»"
     },
     "group": {
      "type": [
       "string",
       "null"
      ],
      "description": "Group id from /dict/product-groups"
     },
     "brand": {
      "type": "string",
      "maxLength": 120
     },
     "description": {
      "type": "string",
      "description": "Plain text up to 2000 characters after cleanup (HTML tags removed); longer — too_long"
     },
     "alt_names": {
      "type": "string",
      "maxLength": 1000
     },
     "service": {
      "type": "boolean",
      "default": false
     },
     "packs": {
      "type": "array",
      "maxItems": 10,
      "items": {
       "type": "object",
       "required": [
        "unit",
        "qty"
       ],
       "additionalProperties": false,
       "properties": {
        "unit": {
         "type": "string"
        },
        "qty": {
         "type": "number",
         "exclusiveMinimum": 0
        }
       }
      }
     },
     "prices": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
       "oneOf": [
        {
         "type": "string"
        },
        {
         "type": "object",
         "properties": {
          "price": {
           "type": "string"
          },
          "per": {
           "type": "string"
          }
         },
         "required": [
          "price"
         ]
        }
       ]
      }
     },
     "stock": {
      "type": "object",
      "additionalProperties": {
       "type": "number",
       "minimum": 0
      }
     },
     "min_qty": {
      "type": [
       "number",
       "null"
      ],
      "minimum": 0,
      "maximum": 1000000
     },
     "step_qty": {
      "type": [
       "number",
       "null"
      ],
      "minimum": 0,
      "maximum": 1000000
     },
     "variants": {
      "type": "array",
      "maxItems": 200,
      "items": {
       "type": "object",
       "required": [
        "name"
       ],
       "additionalProperties": false,
       "properties": {
        "name": {
         "type": "string",
         "minLength": 1,
         "maxLength": 190
        },
        "sku": {
         "type": "string",
         "maxLength": 64
        },
        "stock": {
         "type": "object",
         "additionalProperties": {
          "type": "number",
          "minimum": 0
         }
        }
       }
      }
     }
    }
   },
   "BatchResult": {
    "type": "object",
    "properties": {
     "object": {
      "const": "batch_result"
     },
     "updated": {
      "type": "integer"
     },
     "unchanged": {
      "type": "integer"
     },
     "failed": {
      "type": "integer"
     },
     "results": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "index": {
         "type": "integer"
        },
        "status": {
         "enum": [
          "updated",
          "unchanged",
          "failed"
         ]
        },
        "id": {
         "type": [
          "string",
          "null"
         ]
        },
        "variant": {
         "type": "string"
        },
        "errors": {
         "type": "array",
         "items": {
          "$ref": "#/components/schemas/FieldError"
         }
        }
       }
      }
     }
    }
   },
   "Client": {
    "type": "object",
    "properties": {
     "object": {
      "const": "client"
     },
     "id": {
      "type": "string"
     },
     "name": {
      "type": "string"
     },
     "phone": {
      "type": [
       "string",
       "null"
      ]
     },
     "phone_e164": {
      "type": [
       "string",
       "null"
      ]
     },
     "email": {
      "type": [
       "string",
       "null"
      ]
     },
     "city": {
      "type": [
       "string",
       "null"
      ]
     },
     "channel": {
      "type": "string"
     },
     "accounts": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "channel": {
         "type": "string"
        },
        "handle": {
         "type": "string"
        }
       }
      }
     },
     "tags": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "id": {
         "type": "string"
        },
        "label": {
         "type": "string"
        }
       }
      }
     },
     "manager": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "id": {
        "type": "integer"
       },
       "name": {
        "type": "string"
       }
      }
     },
     "comment": {
      "type": [
       "string",
       "null"
      ]
     },
     "price_list": {
      "type": [
       "string",
       "null"
      ]
     },
     "blocked": {
      "type": "boolean"
     },
     "orders_count": {
      "type": "integer"
     },
     "updated_at": {
      "type": "string",
      "format": "date-time"
     },
     "merged_into": {
      "type": "string",
      "description": "Only for a merged duplicate"
     }
    }
   },
   "ClientInput": {
    "type": "object",
    "additionalProperties": false,
    "properties": {
     "name": {
      "type": "string",
      "maxLength": 120
     },
     "phone": {
      "type": "string"
     },
     "email": {
      "type": "string",
      "format": "email"
     },
     "city": {
      "type": "string"
     },
     "comment": {
      "type": "string"
     },
     "tags": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "manager_id": {
      "type": [
       "integer",
       "null"
      ]
     }
    }
   },
   "Order": {
    "type": "object",
    "properties": {
     "object": {
      "const": "order"
     },
     "number": {
      "type": "string"
     },
     "date": {
      "type": "string",
      "format": "date"
     },
     "status": {
      "type": "object",
      "properties": {
       "name": {
        "type": "string"
       },
       "step": {
        "type": [
         "integer",
         "null"
        ]
       },
       "system": {
        "type": [
         "string",
         "null"
        ],
        "enum": [
         "new",
         "done",
         "cancel",
         null
        ]
       }
      }
     },
     "client": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "id": {
        "type": "string"
       },
       "name": {
        "type": "string"
       },
       "phone": {
        "type": [
         "string",
         "null"
        ]
       }
      }
     },
     "currency": {
      "type": "string"
     },
     "total": {
      "type": "string",
      "pattern": "^\\d+\\.\\d{2}$"
     },
     "paid": {
      "type": "string",
      "pattern": "^\\d+\\.\\d{2}$"
     },
     "due": {
      "type": "string",
      "pattern": "^\\d+\\.\\d{2}$"
     },
     "subtotal": {
      "type": [
       "string",
       "null"
      ]
     },
     "price_list": {
      "type": [
       "string",
       "null"
      ]
     },
     "rate": {
      "type": [
       "string",
       "null"
      ]
     },
     "items": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "id": {
         "type": "string"
        },
        "product_id": {
         "type": [
          "string",
          "null"
         ]
        },
        "variant_id": {
         "type": [
          "string",
          "null"
         ]
        },
        "warehouse": {
         "type": [
          "string",
          "null"
         ]
        },
        "name": {
         "type": "string"
        },
        "sku": {
         "type": [
          "string",
          "null"
         ]
        },
        "quantity": {
         "type": "number"
        },
        "unit": {
         "type": "string"
        },
        "pack_qty": {
         "type": "number"
        },
        "price": {
         "type": [
          "string",
          "null"
         ]
        },
        "amount": {
         "type": [
          "string",
          "null"
         ]
        },
        "reserved": {
         "type": "number"
        },
        "shipped": {
         "type": "number"
        }
       }
      }
     },
     "delivery": {
      "type": [
       "string",
       "null"
      ]
     },
     "ttn": {
      "type": [
       "string",
       "null"
      ]
     },
     "payment": {
      "type": "object",
      "properties": {
       "term": {
        "type": [
         "string",
         "null"
        ],
        "enum": [
         "pre",
         "rcv",
         "def",
         "dep",
         null
        ]
       },
       "method": {
        "type": [
         "object",
         "null"
        ],
        "properties": {
         "id": {
          "type": "string"
         },
         "name": {
          "type": "string"
         }
        }
       },
       "text": {
        "type": [
         "string",
         "null"
        ]
       },
       "due_date": {
        "type": [
         "string",
         "null"
        ],
        "format": "date"
       }
      }
     },
     "payments": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "id": {
         "type": "string"
        },
        "amount": {
         "type": "string",
         "pattern": "^\\d+\\.\\d{2}$"
        },
        "method": {
         "type": "string"
        },
        "at": {
         "type": "string",
         "format": "date-time"
        },
        "reconciled": {
         "type": "boolean"
        }
       }
      }
     },
     "cancel_reason": {
      "type": [
       "string",
       "null"
      ]
     },
     "source": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "site",
       "import",
       "manual",
       "chat",
       null
      ]
     },
     "external_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "updated_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "OrderInput": {
    "type": "object",
    "required": [
     "client",
     "items"
    ],
    "additionalProperties": false,
    "properties": {
     "client": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
       "id": {
        "type": "string"
       },
       "name": {
        "type": "string"
       },
       "phone": {
        "type": "string"
       },
       "email": {
        "type": "string"
       },
       "city": {
        "type": "string"
       },
       "comment": {
        "type": "string"
       },
       "manager_id": {
        "type": "integer"
       }
      }
     },
     "items": {
      "type": "array",
      "minItems": 1,
      "maxItems": 200,
      "items": {
       "type": "object",
       "additionalProperties": false,
       "required": [
        "quantity"
       ],
       "properties": {
        "product_id": {
         "type": "string"
        },
        "sku": {
         "type": "string"
        },
        "variant": {
         "type": "string"
        },
        "quantity": {
         "type": "number",
         "exclusiveMinimum": 0
        },
        "unit": {
         "type": "string"
        },
        "price": {
         "type": "string",
         "pattern": "^\\d+\\.\\d{2}$"
        },
        "warehouse": {
         "type": "string"
        }
       }
      }
     },
     "price_list": {
      "type": "string"
     },
     "delivery": {
      "type": "string",
      "maxLength": 255
     },
     "payment": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
       "term": {
        "enum": [
         "pre",
         "rcv",
         "def",
         "dep"
        ]
       },
       "method": {
        "type": "string"
       },
       "days": {
        "type": "integer"
       },
       "deposit": {
        "type": "string",
        "pattern": "^\\d+\\.\\d{2}$"
       }
      }
     },
     "paid": {
      "type": "object",
      "additionalProperties": false,
      "required": [
       "amount"
      ],
      "properties": {
       "amount": {
        "type": "string",
        "pattern": "^\\d+\\.\\d{2}$"
       },
       "method": {
        "type": "string"
       },
       "note": {
        "type": "string"
       }
      }
     },
     "comment": {
      "type": "string"
     },
     "external_id": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_.:#/\\-]{1,64}$"
     }
    }
   },
   "OrderUpdate": {
    "type": "object",
    "additionalProperties": false,
    "properties": {
     "status": {
      "type": "string"
     },
     "cancel_reason": {
      "type": "string"
     },
     "ttn": {
      "type": "string",
      "pattern": "^([A-Za-z0-9\\-]{4,40})?$"
     },
     "delivery": {
      "type": "string"
     },
     "comment": {
      "type": "string"
     }
    }
   },
   "MessageInput": {
    "type": "object",
    "required": [
     "client_id",
     "text"
    ],
    "additionalProperties": false,
    "properties": {
     "client_id": {
      "type": "string"
     },
     "line_id": {
      "type": "string"
     },
     "text": {
      "type": "string",
      "minLength": 1,
      "maxLength": 4000
     }
    }
   },
   "Message": {
    "type": "object",
    "properties": {
     "object": {
      "const": "message"
     },
     "id": {
      "type": "string"
     },
     "client_id": {
      "type": "string"
     },
     "dialog_id": {
      "type": "string"
     },
     "line": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "id": {
        "type": "string"
       },
       "name": {
        "type": [
         "string",
         "null"
        ]
       },
       "channel": {
        "type": [
         "string",
         "null"
        ]
       }
      }
     },
     "text": {
      "type": "string"
     },
     "status": {
      "enum": [
       "sending",
       "sent",
       "delivered",
       "read",
       "failed"
      ]
     },
     "fail_reason": {
      "type": [
       "string",
       "null"
      ]
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "Call": {
    "type": "object",
    "properties": {
     "object": {
      "const": "call"
     },
     "id": {
      "type": "string"
     },
     "direction": {
      "enum": [
       "inbound",
       "outbound"
      ]
     },
     "state": {
      "enum": [
       "ringing",
       "dialing",
       "active",
       "completed",
       "missed",
       "rejected",
       "canceled",
       "busy",
       "failed",
       "answered_elsewhere"
      ]
     },
     "line": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "id": {
        "type": "string"
       },
       "name": {
        "type": [
         "string",
         "null"
        ]
       },
       "channel": {
        "type": [
         "string",
         "null"
        ]
       }
      }
     },
     "kind": {
      "type": "string"
     },
     "client": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "id": {
        "type": "string"
       },
       "name": {
        "type": "string"
       },
       "phone": {
        "type": [
         "string",
         "null"
        ]
       }
      }
     },
     "started_at": {
      "type": "string",
      "format": "date-time"
     },
     "answered_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "ended_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "duration": {
      "type": "integer",
      "description": "seconds"
     },
     "answered_by": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "id": {
        "type": "integer"
       },
       "name": {
        "type": "string"
       }
      }
     },
     "initiated_by": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "id": {
        "type": "integer"
       },
       "name": {
        "type": "string"
       }
      }
     },
     "recording": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "size": {
        "type": "integer"
       },
       "format": {
        "enum": [
         "m4a",
         "ogg"
        ]
       },
       "url": {
        "type": "string"
       }
      }
     }
    }
   },
   "WebhookEvent": {
    "type": "object",
    "required": [
     "id",
     "event",
     "created",
     "data"
    ],
    "properties": {
     "id": {
      "type": "string",
      "pattern": "^evt_[0-9a-f]{24}$"
     },
     "event": {
      "type": "string",
      "enum": [
       "message.new",
       "call.new",
       "order.status",
       "order.confirmed",
       "stock.changed",
       "test"
      ]
     },
     "created": {
      "type": "string",
      "format": "date-time"
     },
     "data": {
      "type": "object"
     }
    }
   },
   "HookMessageNew": {
    "type": "object",
    "properties": {
     "message": {
      "type": "object",
      "properties": {
       "id": {
        "type": "string"
       },
       "client_id": {
        "type": "string"
       },
       "dialog_id": {
        "type": "string"
       },
       "line": {
        "type": [
         "object",
         "null"
        ],
        "properties": {
         "id": {
          "type": "string"
         },
         "name": {
          "type": [
           "string",
           "null"
          ]
         },
         "channel": {
          "type": [
           "string",
           "null"
          ]
         }
        }
       },
       "kind": {
        "enum": [
         "text",
         "photo",
         "voice",
         "file",
         "sticker",
         "video"
        ]
       },
       "text": {
        "type": [
         "string",
         "null"
        ]
       },
       "file": {
        "type": [
         "object",
         "null"
        ],
        "properties": {
         "name": {
          "type": "string"
         },
         "mime": {
          "type": "string"
         },
         "duration": {
          "type": "integer",
          "description": "seconds"
         }
        }
       },
       "created_at": {
        "type": "string",
        "format": "date-time"
       }
      }
     },
     "client": {
      "type": "object",
      "properties": {
       "id": {
        "type": "string"
       },
       "name": {
        "type": "string"
       },
       "phone": {
        "type": [
         "string",
         "null"
        ]
       }
      }
     }
    }
   },
   "HookOrderStatus": {
    "type": "object",
    "properties": {
     "order": {
      "type": "object",
      "properties": {
       "number": {
        "type": "string"
       },
       "external_id": {
        "type": [
         "string",
         "null"
        ]
       },
       "status": {
        "type": [
         "object",
         "null"
        ],
        "properties": {
         "name": {
          "type": "string"
         },
         "step": {
          "type": [
           "integer",
           "null"
          ]
         },
         "system": {
          "type": [
           "string",
           "null"
          ],
          "enum": [
           "new",
           "done",
           "cancel",
           null
          ]
         }
        }
       },
       "previous_status": {
        "type": [
         "object",
         "null"
        ],
        "properties": {
         "name": {
          "type": "string"
         },
         "step": {
          "type": [
           "integer",
           "null"
          ]
         },
         "system": {
          "type": [
           "string",
           "null"
          ],
          "enum": [
           "new",
           "done",
           "cancel",
           null
          ]
         }
        }
       },
       "client": {
        "type": "object",
        "properties": {
         "id": {
          "type": "string"
         },
         "name": {
          "type": "string"
         },
         "phone": {
          "type": [
           "string",
           "null"
          ]
         }
        }
       },
       "total": {
        "type": "string",
        "pattern": "^\\d+\\.\\d{2}$"
       },
       "currency": {
        "type": "string"
       },
       "ttn": {
        "type": [
         "string",
         "null"
        ]
       },
       "source": {
        "type": [
         "string",
         "null"
        ],
        "enum": [
         "site",
         "import",
         "manual",
         "chat",
         null
        ]
       }
      }
     },
     "changed_by": {
      "type": "object",
      "properties": {
       "type": {
        "enum": [
         "user",
         "api",
         "system"
        ]
       },
       "id": {
        "type": "integer"
       },
       "name": {
        "type": "string"
       }
      }
     },
     "changed_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "HookOrderConfirmed": {
    "type": "object",
    "properties": {
     "order": {
      "type": "object",
      "properties": {
       "number": {
        "type": "string"
       },
       "external_id": {
        "type": [
         "string",
         "null"
        ]
       },
       "status": {
        "type": "string",
        "description": "Status name after confirmation"
       },
       "client": {
        "type": "object",
        "properties": {
         "id": {
          "type": "string"
         },
         "name": {
          "type": "string"
         },
         "phone": {
          "type": [
           "string",
           "null"
          ]
         }
        }
       },
       "total": {
        "type": "string",
        "pattern": "^\\d+\\.\\d{2}$"
       },
       "currency": {
        "type": "string"
       }
      }
     },
     "changes": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "What the client changed, as lines in Ukrainian; empty — confirmed as is"
     },
     "comment": {
      "type": [
       "string",
       "null"
      ]
     },
     "recipient": {
      "type": "object",
      "properties": {
       "name": {
        "type": "string"
       },
       "phone": {
        "type": "string"
       },
       "city": {
        "type": [
         "string",
         "null"
        ]
       },
       "branch": {
        "type": [
         "string",
         "null"
        ]
       }
      }
     },
     "confirmed_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "HookStockChanged": {
    "type": "object",
    "properties": {
     "product": {
      "type": "object",
      "properties": {
       "id": {
        "type": "string"
       },
       "sku": {
        "type": [
         "string",
         "null"
        ]
       },
       "name": {
        "type": "string"
       },
       "unit": {
        "type": "string"
       }
      }
     },
     "variant": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "id": {
        "type": "string"
       },
       "sku": {
        "type": [
         "string",
         "null"
        ]
       },
       "name": {
        "type": "string"
       }
      }
     },
     "on_hand": {
      "type": "number"
     },
     "reserved": {
      "type": "number"
     },
     "available": {
      "type": "number"
     },
     "warehouses": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "warehouse": {
         "type": "object",
         "properties": {
          "id": {
           "type": "string"
          },
          "name": {
           "type": [
            "string",
            "null"
           ]
          }
         }
        },
        "on_hand": {
         "type": "number"
        },
        "reserved": {
         "type": "number"
        },
        "available": {
         "type": "number"
        },
        "previous": {
         "type": "object",
         "properties": {
          "on_hand": {
           "type": "number"
          },
          "reserved": {
           "type": "number"
          },
          "available": {
           "type": "number"
          }
         }
        }
       }
      }
     },
     "changed_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   }
  }
 }
}
