{
    "openapi": "3.1.0",
    "info": {
        "title": "Prof API",
        "version": "1.0.0",
        "description": "Read and write your Prof account (customers, suppliers, products, stock, sales and purchase bills, payments, expenses) from your own programs and AI agents. Every request runs with the same rules as the Prof app, limited to the token's permissions and branches.",
        "contact": {
            "name": "Silver Thinking",
            "url": "https://prof.silverthinking.net"
        }
    },
    "servers": [
        {
            "url": "https://prof-api.silverthinking.net"
        }
    ],
    "security": [
        {
            "bearerAuth": []
        }
    ],
    "paths": {
        "/v1/me": {
            "get": {
                "operationId": "me",
                "summary": "The token itself: its name, permissions, branches, expiry and rate limits.",
                "tags": [
                    "Account"
                ],
                "x-cost": 1,
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/Me"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/branches": {
            "get": {
                "operationId": "branches_list",
                "summary": "The branches this token may work in.",
                "tags": [
                    "Lookups"
                ],
                "x-cost": 1,
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Branch"
                                            }
                                        },
                                        "pagination": {
                                            "$ref": "#/components/schemas/Pagination"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/warehouses": {
            "get": {
                "operationId": "warehouses_list",
                "summary": "Warehouses, with the branches each one serves.",
                "tags": [
                    "Lookups"
                ],
                "x-cost": 1,
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Warehouse"
                                            }
                                        },
                                        "pagination": {
                                            "$ref": "#/components/schemas/Pagination"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/vaults": {
            "get": {
                "operationId": "vaults_list",
                "summary": "Vaults (cash boxes) per branch. No balances.",
                "tags": [
                    "Lookups"
                ],
                "x-cost": 1,
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Vault"
                                            }
                                        },
                                        "pagination": {
                                            "$ref": "#/components/schemas/Pagination"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/payment-methods": {
            "get": {
                "operationId": "payment_methods_list",
                "summary": "Payment methods (InstaPay, wallets, cards...).",
                "tags": [
                    "Lookups"
                ],
                "x-cost": 1,
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/PaymentMethod"
                                            }
                                        },
                                        "pagination": {
                                            "$ref": "#/components/schemas/Pagination"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/categories": {
            "get": {
                "operationId": "categories_list",
                "summary": "Product categories.",
                "tags": [
                    "Lookups"
                ],
                "x-cost": 1,
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Category"
                                            }
                                        },
                                        "pagination": {
                                            "$ref": "#/components/schemas/Pagination"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/customers": {
            "get": {
                "operationId": "customers_list",
                "summary": "Customers, newest first, with what each one owes.",
                "tags": [
                    "Customers"
                ],
                "x-cost": 1,
                "x-permissions": [
                    "view_customers"
                ],
                "description": "Token permissions: view_customers.",
                "parameters": [
                    {
                        "name": "search",
                        "in": "query",
                        "required": false,
                        "description": "Name, phone, company or code.",
                        "schema": {
                            "type": "string",
                            "description": "Name, phone, company or code."
                        }
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "required": false,
                        "description": "Rows per page, 1–100 (default 25). More than 50 costs 3 units.",
                        "schema": {
                            "type": "integer",
                            "description": "Rows per page, 1–100 (default 25). More than 50 costs 3 units."
                        }
                    },
                    {
                        "name": "offset",
                        "in": "query",
                        "required": false,
                        "description": "Rows to skip (default 0).",
                        "schema": {
                            "type": "integer",
                            "description": "Rows to skip (default 0)."
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Customer"
                                            }
                                        },
                                        "pagination": {
                                            "$ref": "#/components/schemas/Pagination"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "post": {
                "operationId": "customers_create",
                "summary": "Add a customer. The code is given automatically. A phone another customer or supplier already has is refused.",
                "tags": [
                    "Customers"
                ],
                "x-cost": 2,
                "x-permissions": [
                    "add_customer",
                    "view_customers"
                ],
                "description": "Token permissions: add_customer, view_customers.",
                "parameters": [
                    {
                        "name": "Idempotency-Key",
                        "in": "header",
                        "required": false,
                        "description": "Send the same key when you retry: the write happens once.",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "The name."
                                    },
                                    "phone": {
                                        "type": "string",
                                        "description": "Mobile number, e.g. 01012345678."
                                    },
                                    "phone2": {
                                        "type": "string",
                                        "description": "A second mobile number."
                                    },
                                    "company": {
                                        "type": "string",
                                        "description": "Company."
                                    },
                                    "address": {
                                        "type": "string",
                                        "description": "Address."
                                    },
                                    "gender": {
                                        "type": "string",
                                        "description": "Gender (some accounts require it).",
                                        "enum": [
                                            "male",
                                            "female",
                                            ""
                                        ]
                                    },
                                    "opening_balance": {
                                        "type": "number",
                                        "description": "What the customer already owes from before (0 if nothing)."
                                    },
                                    "notes": {
                                        "type": "string",
                                        "description": "Notes."
                                    },
                                    "allow_similar": {
                                        "type": "boolean",
                                        "description": "false (default): a customer with the same name is reported (409 SIMILAR_RECORDS_EXIST) instead of added. true: add anyway."
                                    }
                                },
                                "required": [
                                    "name"
                                ]
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/Customer"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/customers/{code}": {
            "get": {
                "operationId": "customers_get",
                "summary": "One customer.",
                "tags": [
                    "Customers"
                ],
                "x-cost": 1,
                "x-permissions": [
                    "view_customers"
                ],
                "description": "Token permissions: view_customers.",
                "parameters": [
                    {
                        "name": "code",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/Customer"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "patch": {
                "operationId": "customers_update",
                "summary": "Change a customer. Only the fields sent change; an empty string clears a field.",
                "tags": [
                    "Customers"
                ],
                "x-cost": 2,
                "x-permissions": [
                    "edit_customer",
                    "view_customers"
                ],
                "description": "Token permissions: edit_customer, view_customers.",
                "parameters": [
                    {
                        "name": "code",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Name."
                                    },
                                    "phone": {
                                        "type": "string",
                                        "description": "Phone."
                                    },
                                    "phone2": {
                                        "type": "string",
                                        "description": "Second phone."
                                    },
                                    "company": {
                                        "type": "string",
                                        "description": "Company."
                                    },
                                    "address": {
                                        "type": "string",
                                        "description": "Address."
                                    },
                                    "gender": {
                                        "type": "string",
                                        "description": "Gender.",
                                        "enum": [
                                            "male",
                                            "female"
                                        ]
                                    },
                                    "notes": {
                                        "type": "string",
                                        "description": "Notes."
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/Customer"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "customers_delete",
                "summary": "Delete a customer. Refused (CUSTOMER_HAS_BILLS) once the customer has any bill, like in the app.",
                "tags": [
                    "Customers"
                ],
                "x-cost": 2,
                "x-permissions": [
                    "delete_customer"
                ],
                "description": "Token permissions: delete_customer.",
                "parameters": [
                    {
                        "name": "code",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "object",
                                            "properties": {
                                                "code": {
                                                    "type": "string"
                                                },
                                                "deleted": {
                                                    "type": "boolean"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/suppliers": {
            "get": {
                "operationId": "suppliers_list",
                "summary": "Suppliers, newest first, with what is owed to each one.",
                "tags": [
                    "Suppliers"
                ],
                "x-cost": 1,
                "x-permissions": [
                    "view_suppliers"
                ],
                "description": "Token permissions: view_suppliers.",
                "parameters": [
                    {
                        "name": "search",
                        "in": "query",
                        "required": false,
                        "description": "Name, phone, company or code.",
                        "schema": {
                            "type": "string",
                            "description": "Name, phone, company or code."
                        }
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "required": false,
                        "description": "Rows per page, 1–100 (default 25). More than 50 costs 3 units.",
                        "schema": {
                            "type": "integer",
                            "description": "Rows per page, 1–100 (default 25). More than 50 costs 3 units."
                        }
                    },
                    {
                        "name": "offset",
                        "in": "query",
                        "required": false,
                        "description": "Rows to skip (default 0).",
                        "schema": {
                            "type": "integer",
                            "description": "Rows to skip (default 0)."
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Supplier"
                                            }
                                        },
                                        "pagination": {
                                            "$ref": "#/components/schemas/Pagination"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "post": {
                "operationId": "suppliers_create",
                "summary": "Add a supplier. The code is given automatically.",
                "tags": [
                    "Suppliers"
                ],
                "x-cost": 2,
                "x-permissions": [
                    "add_supplier",
                    "view_suppliers"
                ],
                "description": "Token permissions: add_supplier, view_suppliers.",
                "parameters": [
                    {
                        "name": "Idempotency-Key",
                        "in": "header",
                        "required": false,
                        "description": "Send the same key when you retry: the write happens once.",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "The name."
                                    },
                                    "phone": {
                                        "type": "string",
                                        "description": "Mobile number."
                                    },
                                    "phone2": {
                                        "type": "string",
                                        "description": "A second mobile number."
                                    },
                                    "address": {
                                        "type": "string",
                                        "description": "Address."
                                    },
                                    "field": {
                                        "type": "string",
                                        "description": "Line of business."
                                    },
                                    "allow_similar": {
                                        "type": "boolean",
                                        "description": "See POST /v1/customers."
                                    }
                                },
                                "required": [
                                    "name"
                                ]
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/Supplier"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/suppliers/{code}": {
            "get": {
                "operationId": "suppliers_get",
                "summary": "One supplier.",
                "tags": [
                    "Suppliers"
                ],
                "x-cost": 1,
                "x-permissions": [
                    "view_suppliers"
                ],
                "description": "Token permissions: view_suppliers.",
                "parameters": [
                    {
                        "name": "code",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/Supplier"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "patch": {
                "operationId": "suppliers_update",
                "summary": "Change a supplier. Only the fields sent change; an empty string clears a field.",
                "tags": [
                    "Suppliers"
                ],
                "x-cost": 2,
                "x-permissions": [
                    "edit_supplier",
                    "view_suppliers"
                ],
                "description": "Token permissions: edit_supplier, view_suppliers.",
                "parameters": [
                    {
                        "name": "code",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Name."
                                    },
                                    "phone": {
                                        "type": "string",
                                        "description": "Phone."
                                    },
                                    "phone2": {
                                        "type": "string",
                                        "description": "Second phone."
                                    },
                                    "company": {
                                        "type": "string",
                                        "description": "Company."
                                    },
                                    "address": {
                                        "type": "string",
                                        "description": "Address."
                                    },
                                    "field": {
                                        "type": "string",
                                        "description": "Line of business."
                                    },
                                    "notes": {
                                        "type": "string",
                                        "description": "Notes."
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/Supplier"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "suppliers_delete",
                "summary": "Delete a supplier. Refused (SUPPLIER_HAS_BILLS) once the supplier has any bill.",
                "tags": [
                    "Suppliers"
                ],
                "x-cost": 2,
                "x-permissions": [
                    "delete_supplier"
                ],
                "description": "Token permissions: delete_supplier.",
                "parameters": [
                    {
                        "name": "code",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "object",
                                            "properties": {
                                                "code": {
                                                    "type": "string"
                                                },
                                                "deleted": {
                                                    "type": "boolean"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/products": {
            "get": {
                "operationId": "products_list",
                "summary": "Products (not deleted), newest first. Purchase cost only with view_purchase_prices.",
                "tags": [
                    "Products"
                ],
                "x-cost": 1,
                "x-permissions": [
                    "view_warehouses"
                ],
                "description": "Token permissions: view_warehouses.",
                "parameters": [
                    {
                        "name": "search",
                        "in": "query",
                        "required": false,
                        "description": "Part of the name.",
                        "schema": {
                            "type": "string",
                            "description": "Part of the name."
                        }
                    },
                    {
                        "name": "category",
                        "in": "query",
                        "required": false,
                        "description": "A category code.",
                        "schema": {
                            "type": "string",
                            "description": "A category code."
                        }
                    },
                    {
                        "name": "barcode",
                        "in": "query",
                        "required": false,
                        "description": "Exact product code / barcode.",
                        "schema": {
                            "type": "string",
                            "description": "Exact product code / barcode."
                        }
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "required": false,
                        "description": "Rows per page, 1–100 (default 25). More than 50 costs 3 units.",
                        "schema": {
                            "type": "integer",
                            "description": "Rows per page, 1–100 (default 25). More than 50 costs 3 units."
                        }
                    },
                    {
                        "name": "offset",
                        "in": "query",
                        "required": false,
                        "description": "Rows to skip (default 0).",
                        "schema": {
                            "type": "integer",
                            "description": "Rows to skip (default 0)."
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Product"
                                            }
                                        },
                                        "pagination": {
                                            "$ref": "#/components/schemas/Pagination"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "post": {
                "operationId": "products_create",
                "summary": "Register a new product (quantity comes with a purchase bill or a stock-take). The same name and specs twice is refused.",
                "tags": [
                    "Products"
                ],
                "x-cost": 2,
                "x-permissions": [
                    "edit_warehouse"
                ],
                "description": "Token permissions: edit_warehouse.",
                "parameters": [
                    {
                        "name": "Idempotency-Key",
                        "in": "header",
                        "required": false,
                        "description": "Send the same key when you retry: the write happens once.",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Product name."
                                    },
                                    "sale_price": {
                                        "type": "number",
                                        "description": "Retail price."
                                    },
                                    "wholesale_price": {
                                        "type": "number",
                                        "description": "Wholesale price."
                                    },
                                    "unit": {
                                        "type": "string",
                                        "description": "Unit (piece, box, kilo...)."
                                    },
                                    "barcode": {
                                        "type": "string",
                                        "description": "Barcode; empty = given automatically."
                                    },
                                    "specs": {
                                        "type": "array",
                                        "description": "Specifications, e.g. [{\"name\":\"Size\",\"value\":\"1 L\"}].",
                                        "items": {
                                            "type": "object",
                                            "properties": {
                                                "name": {
                                                    "type": "string",
                                                    "description": "string"
                                                },
                                                "value": {
                                                    "type": "string",
                                                    "description": "string"
                                                }
                                            }
                                        }
                                    }
                                },
                                "required": [
                                    "name",
                                    "sale_price"
                                ]
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/Product"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/products/{code}": {
            "get": {
                "operationId": "products_get",
                "summary": "One product (every variant sharing the code).",
                "tags": [
                    "Products"
                ],
                "x-cost": 1,
                "x-permissions": [
                    "view_warehouses"
                ],
                "description": "Token permissions: view_warehouses.",
                "parameters": [
                    {
                        "name": "code",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/Product"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "products_delete",
                "summary": "Delete a product (soft delete, like the app: old bills and batches keep it).",
                "tags": [
                    "Products"
                ],
                "x-cost": 2,
                "x-permissions": [
                    "edit_warehouse"
                ],
                "description": "Token permissions: edit_warehouse.",
                "parameters": [
                    {
                        "name": "code",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "object",
                                            "properties": {
                                                "code": {
                                                    "type": "string"
                                                },
                                                "deleted": {
                                                    "type": "boolean"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/products/{code}/stock": {
            "get": {
                "operationId": "products_stock",
                "summary": "Quantity of one product per warehouse.",
                "tags": [
                    "Products"
                ],
                "x-cost": 1,
                "x-permissions": [
                    "view_warehouses"
                ],
                "description": "Token permissions: view_warehouses.",
                "parameters": [
                    {
                        "name": "code",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/StockRow"
                                            }
                                        },
                                        "pagination": {
                                            "$ref": "#/components/schemas/Pagination"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/stock": {
            "get": {
                "operationId": "stock_list",
                "summary": "Stock batches (product, warehouse, quantity, expiry).",
                "tags": [
                    "Products"
                ],
                "x-cost": 1,
                "x-permissions": [
                    "view_warehouses"
                ],
                "description": "Token permissions: view_warehouses.",
                "parameters": [
                    {
                        "name": "warehouse",
                        "in": "query",
                        "required": false,
                        "description": "A warehouse code.",
                        "schema": {
                            "type": "string",
                            "description": "A warehouse code."
                        }
                    },
                    {
                        "name": "product_code",
                        "in": "query",
                        "required": false,
                        "description": "A product code.",
                        "schema": {
                            "type": "string",
                            "description": "A product code."
                        }
                    },
                    {
                        "name": "in_stock",
                        "in": "query",
                        "required": false,
                        "description": "Only batches with quantity above zero.",
                        "schema": {
                            "type": "boolean",
                            "description": "Only batches with quantity above zero."
                        }
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "required": false,
                        "description": "Rows per page, 1–100 (default 25). More than 50 costs 3 units.",
                        "schema": {
                            "type": "integer",
                            "description": "Rows per page, 1–100 (default 25). More than 50 costs 3 units."
                        }
                    },
                    {
                        "name": "offset",
                        "in": "query",
                        "required": false,
                        "description": "Rows to skip (default 0).",
                        "schema": {
                            "type": "integer",
                            "description": "Rows to skip (default 0)."
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/StockRow"
                                            }
                                        },
                                        "pagination": {
                                            "$ref": "#/components/schemas/Pagination"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/sales-bills": {
            "get": {
                "operationId": "sales_bills_list",
                "summary": "Sales bills, newest first (headers only).",
                "tags": [
                    "Sales bills"
                ],
                "x-cost": 1,
                "x-permissions": [
                    "view_sales"
                ],
                "description": "Token permissions: view_sales.",
                "parameters": [
                    {
                        "name": "customer",
                        "in": "query",
                        "required": false,
                        "description": "A customer code.",
                        "schema": {
                            "type": "string",
                            "description": "A customer code."
                        }
                    },
                    {
                        "name": "search",
                        "in": "query",
                        "required": false,
                        "description": "Bill code, customer name or phone.",
                        "schema": {
                            "type": "string",
                            "description": "Bill code, customer name or phone."
                        }
                    },
                    {
                        "name": "from",
                        "in": "query",
                        "required": false,
                        "description": "Only rows on or after this date (YYYY-MM-DD).",
                        "schema": {
                            "type": "string",
                            "description": "Only rows on or after this date (YYYY-MM-DD)."
                        }
                    },
                    {
                        "name": "to",
                        "in": "query",
                        "required": false,
                        "description": "Only rows on or before this date (YYYY-MM-DD).",
                        "schema": {
                            "type": "string",
                            "description": "Only rows on or before this date (YYYY-MM-DD)."
                        }
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "required": false,
                        "description": "Rows per page, 1–100 (default 25). More than 50 costs 3 units.",
                        "schema": {
                            "type": "integer",
                            "description": "Rows per page, 1–100 (default 25). More than 50 costs 3 units."
                        }
                    },
                    {
                        "name": "offset",
                        "in": "query",
                        "required": false,
                        "description": "Rows to skip (default 0).",
                        "schema": {
                            "type": "integer",
                            "description": "Rows to skip (default 0)."
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/SalesBill"
                                            }
                                        },
                                        "pagination": {
                                            "$ref": "#/components/schemas/Pagination"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "post": {
                "operationId": "sales_bills_create",
                "summary": "Create a sales bill. Stock, price limits, selling-at-loss and the account's rules are checked exactly like the bill screen; the bill, its lines, the stock movement and the payment are saved together or not at all.",
                "tags": [
                    "Sales bills"
                ],
                "x-cost": 2,
                "x-permissions": [
                    "add_sales_bill"
                ],
                "description": "Token permissions: add_sales_bill.",
                "parameters": [
                    {
                        "name": "Idempotency-Key",
                        "in": "header",
                        "required": false,
                        "description": "Send the same key when you retry: the write happens once.",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "branch": {
                                        "type": "string",
                                        "description": "The branch the operation belongs to (a code from GET /v1/branches). Optional when the token is limited to one branch."
                                    },
                                    "customer_code": {
                                        "type": "string",
                                        "description": "The customer (every bill needs one)."
                                    },
                                    "warehouse_code": {
                                        "type": "string",
                                        "description": "The warehouse the goods leave; empty if the branch has one."
                                    },
                                    "sale_type": {
                                        "type": "string",
                                        "description": "Price list used when unit_price is 0.",
                                        "enum": [
                                            "retail",
                                            "wholesale"
                                        ]
                                    },
                                    "items": {
                                        "type": "array",
                                        "description": "1–30 lines.",
                                        "items": {
                                            "type": "object",
                                            "properties": {
                                                "product_code": {
                                                    "type": "string",
                                                    "description": "string"
                                                },
                                                "quantity": {
                                                    "type": "number",
                                                    "description": "number"
                                                },
                                                "unit_price": {
                                                    "type": "number",
                                                    "description": "number (0 = the product's own price)"
                                                }
                                            }
                                        }
                                    },
                                    "payment": {
                                        "type": "string",
                                        "description": "cash = paid in full now; credit = the rest stays on the account.",
                                        "enum": [
                                            "cash",
                                            "credit"
                                        ]
                                    },
                                    "paid_amount": {
                                        "type": "number",
                                        "description": "Credit only: what is paid now (0 if nothing)."
                                    },
                                    "discount": {
                                        "type": "number",
                                        "description": "A discount amount on the whole bill (0 if none)."
                                    },
                                    "notes": {
                                        "type": "string",
                                        "description": "Notes saved with the bill."
                                    },
                                    "vault_code": {
                                        "type": "string",
                                        "description": "The vault the money goes into / comes out of (GET /v1/vaults). Empty when the branch has one vault or a payment method is used."
                                    },
                                    "payment_method_code": {
                                        "type": "string",
                                        "description": "A payment method (GET /v1/payment-methods) instead of a vault: InstaPay, a wallet..."
                                    }
                                },
                                "required": [
                                    "customer_code",
                                    "items"
                                ]
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/SalesBill"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/sales-bills/{code}": {
            "get": {
                "operationId": "sales_bills_get",
                "summary": "One sales bill with its lines.",
                "tags": [
                    "Sales bills"
                ],
                "x-cost": 1,
                "x-permissions": [
                    "view_sales"
                ],
                "description": "Token permissions: view_sales.",
                "parameters": [
                    {
                        "name": "code",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/SalesBill"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "sales_bills_delete",
                "summary": "Delete a whole sales bill (its lines, stock and payments go back). A single line can never be deleted; a bill with returns or a closed shipment is refused, like in the app.",
                "tags": [
                    "Sales bills"
                ],
                "x-cost": 2,
                "x-permissions": [
                    "delete_sales_bill"
                ],
                "description": "Token permissions: delete_sales_bill.",
                "parameters": [
                    {
                        "name": "code",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "object",
                                            "properties": {
                                                "code": {
                                                    "type": "string"
                                                },
                                                "deleted": {
                                                    "type": "boolean"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/purchase-bills": {
            "get": {
                "operationId": "purchase_bills_list",
                "summary": "Purchase (supply) bills, newest first.",
                "tags": [
                    "Purchase bills"
                ],
                "x-cost": 1,
                "x-permissions": [
                    "view_procurement"
                ],
                "description": "Token permissions: view_procurement.",
                "parameters": [
                    {
                        "name": "supplier",
                        "in": "query",
                        "required": false,
                        "description": "A supplier code.",
                        "schema": {
                            "type": "string",
                            "description": "A supplier code."
                        }
                    },
                    {
                        "name": "search",
                        "in": "query",
                        "required": false,
                        "description": "Bill code or supplier name.",
                        "schema": {
                            "type": "string",
                            "description": "Bill code or supplier name."
                        }
                    },
                    {
                        "name": "from",
                        "in": "query",
                        "required": false,
                        "description": "Only rows on or after this date (YYYY-MM-DD).",
                        "schema": {
                            "type": "string",
                            "description": "Only rows on or after this date (YYYY-MM-DD)."
                        }
                    },
                    {
                        "name": "to",
                        "in": "query",
                        "required": false,
                        "description": "Only rows on or before this date (YYYY-MM-DD).",
                        "schema": {
                            "type": "string",
                            "description": "Only rows on or before this date (YYYY-MM-DD)."
                        }
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "required": false,
                        "description": "Rows per page, 1–100 (default 25). More than 50 costs 3 units.",
                        "schema": {
                            "type": "integer",
                            "description": "Rows per page, 1–100 (default 25). More than 50 costs 3 units."
                        }
                    },
                    {
                        "name": "offset",
                        "in": "query",
                        "required": false,
                        "description": "Rows to skip (default 0).",
                        "schema": {
                            "type": "integer",
                            "description": "Rows to skip (default 0)."
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/PurchaseBill"
                                            }
                                        },
                                        "pagination": {
                                            "$ref": "#/components/schemas/Pagination"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "post": {
                "operationId": "purchase_bills_create",
                "summary": "Create a purchase bill into one warehouse. A line with an empty product_code registers a new product.",
                "tags": [
                    "Purchase bills"
                ],
                "x-cost": 2,
                "x-permissions": [
                    "add_purchase_bill"
                ],
                "description": "Token permissions: add_purchase_bill.",
                "parameters": [
                    {
                        "name": "Idempotency-Key",
                        "in": "header",
                        "required": false,
                        "description": "Send the same key when you retry: the write happens once.",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "branch": {
                                        "type": "string",
                                        "description": "The branch the operation belongs to (a code from GET /v1/branches). Optional when the token is limited to one branch."
                                    },
                                    "supplier_code": {
                                        "type": "string",
                                        "description": "The supplier."
                                    },
                                    "warehouse_code": {
                                        "type": "string",
                                        "description": "The warehouse the goods enter; empty if the branch has one."
                                    },
                                    "items": {
                                        "type": "array",
                                        "description": "1–30 lines.",
                                        "items": {
                                            "type": "object",
                                            "properties": {
                                                "product_code": {
                                                    "type": "string",
                                                    "description": "string (empty = new product)"
                                                },
                                                "name": {
                                                    "type": "string",
                                                    "description": "string (new product)"
                                                },
                                                "quantity": {
                                                    "type": "number",
                                                    "description": "number"
                                                },
                                                "cost_price": {
                                                    "type": "number",
                                                    "description": "number"
                                                },
                                                "sale_price": {
                                                    "type": "number",
                                                    "description": "number (new product)"
                                                },
                                                "wholesale_price": {
                                                    "type": "number",
                                                    "description": "number"
                                                },
                                                "unit": {
                                                    "type": "string",
                                                    "description": "string"
                                                },
                                                "expiry_date": {
                                                    "type": "string",
                                                    "description": "YYYY-MM-DD"
                                                }
                                            }
                                        }
                                    },
                                    "payment": {
                                        "type": "string",
                                        "description": "cash = paid in full now; credit = the rest stays on the account.",
                                        "enum": [
                                            "cash",
                                            "credit"
                                        ]
                                    },
                                    "paid_amount": {
                                        "type": "number",
                                        "description": "Credit only: what is paid now (0 if nothing)."
                                    },
                                    "discount": {
                                        "type": "number",
                                        "description": "A discount amount on the whole bill (0 if none)."
                                    },
                                    "notes": {
                                        "type": "string",
                                        "description": "Notes saved with the bill."
                                    },
                                    "vault_code": {
                                        "type": "string",
                                        "description": "The vault the money goes into / comes out of (GET /v1/vaults). Empty when the branch has one vault or a payment method is used."
                                    },
                                    "payment_method_code": {
                                        "type": "string",
                                        "description": "A payment method (GET /v1/payment-methods) instead of a vault: InstaPay, a wallet..."
                                    }
                                },
                                "required": [
                                    "supplier_code",
                                    "items"
                                ]
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/PurchaseBill"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/purchase-bills/{code}": {
            "get": {
                "operationId": "purchase_bills_get",
                "summary": "One purchase bill with its lines.",
                "tags": [
                    "Purchase bills"
                ],
                "x-cost": 1,
                "x-permissions": [
                    "view_procurement"
                ],
                "description": "Token permissions: view_procurement.",
                "parameters": [
                    {
                        "name": "code",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/PurchaseBill"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "delete": {
                "operationId": "purchase_bills_delete",
                "summary": "Delete a whole purchase bill. Refused when its goods were already sold, like in the app.",
                "tags": [
                    "Purchase bills"
                ],
                "x-cost": 2,
                "x-permissions": [
                    "delete_purchase_bill"
                ],
                "description": "Token permissions: delete_purchase_bill.",
                "parameters": [
                    {
                        "name": "code",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "object",
                                            "properties": {
                                                "code": {
                                                    "type": "string"
                                                },
                                                "deleted": {
                                                    "type": "boolean"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/payments": {
            "get": {
                "operationId": "payments_list",
                "summary": "Money collected from customers or paid to suppliers.",
                "tags": [
                    "Payments"
                ],
                "x-cost": 1,
                "x-permissions": [
                    "view_customers",
                    "view_suppliers"
                ],
                "description": "Token permissions: view_customers, view_suppliers.",
                "parameters": [
                    {
                        "name": "account",
                        "in": "query",
                        "required": true,
                        "description": "Which side (required).",
                        "schema": {
                            "type": "string",
                            "description": "Which side (required).",
                            "enum": [
                                "customer",
                                "supplier"
                            ]
                        }
                    },
                    {
                        "name": "code",
                        "in": "query",
                        "required": false,
                        "description": "A customer / supplier code.",
                        "schema": {
                            "type": "string",
                            "description": "A customer / supplier code."
                        }
                    },
                    {
                        "name": "from",
                        "in": "query",
                        "required": false,
                        "description": "Only rows on or after this date (YYYY-MM-DD).",
                        "schema": {
                            "type": "string",
                            "description": "Only rows on or after this date (YYYY-MM-DD)."
                        }
                    },
                    {
                        "name": "to",
                        "in": "query",
                        "required": false,
                        "description": "Only rows on or before this date (YYYY-MM-DD).",
                        "schema": {
                            "type": "string",
                            "description": "Only rows on or before this date (YYYY-MM-DD)."
                        }
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "required": false,
                        "description": "Rows per page, 1–100 (default 25). More than 50 costs 3 units.",
                        "schema": {
                            "type": "integer",
                            "description": "Rows per page, 1–100 (default 25). More than 50 costs 3 units."
                        }
                    },
                    {
                        "name": "offset",
                        "in": "query",
                        "required": false,
                        "description": "Rows to skip (default 0).",
                        "schema": {
                            "type": "integer",
                            "description": "Rows to skip (default 0)."
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Payment"
                                            }
                                        },
                                        "pagination": {
                                            "$ref": "#/components/schemas/Pagination"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/customer-payments": {
            "post": {
                "operationId": "customer_payments_create",
                "summary": "Collect money from a customer (lowers what they owe).",
                "tags": [
                    "Payments"
                ],
                "x-cost": 2,
                "x-permissions": [
                    "collect_from_customer",
                    "view_customers"
                ],
                "description": "Token permissions: collect_from_customer, view_customers.",
                "parameters": [
                    {
                        "name": "Idempotency-Key",
                        "in": "header",
                        "required": false,
                        "description": "Send the same key when you retry: the write happens once.",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "branch": {
                                        "type": "string",
                                        "description": "The branch the operation belongs to (a code from GET /v1/branches). Optional when the token is limited to one branch."
                                    },
                                    "customer_code": {
                                        "type": "string",
                                        "description": "The customer."
                                    },
                                    "amount": {
                                        "type": "number",
                                        "description": "The amount."
                                    },
                                    "notes": {
                                        "type": "string",
                                        "description": "Notes."
                                    },
                                    "vault_code": {
                                        "type": "string",
                                        "description": "The vault the money goes into / comes out of (GET /v1/vaults). Empty when the branch has one vault or a payment method is used."
                                    },
                                    "payment_method_code": {
                                        "type": "string",
                                        "description": "A payment method (GET /v1/payment-methods) instead of a vault: InstaPay, a wallet..."
                                    }
                                },
                                "required": [
                                    "customer_code",
                                    "amount"
                                ]
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/Payment"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/supplier-payments": {
            "post": {
                "operationId": "supplier_payments_create",
                "summary": "Pay money to a supplier (lowers what is owed to them). The vault or payment method must hold enough.",
                "tags": [
                    "Payments"
                ],
                "x-cost": 2,
                "x-permissions": [
                    "pay_supplier",
                    "view_suppliers"
                ],
                "description": "Token permissions: pay_supplier, view_suppliers.",
                "parameters": [
                    {
                        "name": "Idempotency-Key",
                        "in": "header",
                        "required": false,
                        "description": "Send the same key when you retry: the write happens once.",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "branch": {
                                        "type": "string",
                                        "description": "The branch the operation belongs to (a code from GET /v1/branches). Optional when the token is limited to one branch."
                                    },
                                    "supplier_code": {
                                        "type": "string",
                                        "description": "The supplier."
                                    },
                                    "amount": {
                                        "type": "number",
                                        "description": "The amount."
                                    },
                                    "notes": {
                                        "type": "string",
                                        "description": "Notes."
                                    },
                                    "vault_code": {
                                        "type": "string",
                                        "description": "The vault the money goes into / comes out of (GET /v1/vaults). Empty when the branch has one vault or a payment method is used."
                                    },
                                    "payment_method_code": {
                                        "type": "string",
                                        "description": "A payment method (GET /v1/payment-methods) instead of a vault: InstaPay, a wallet..."
                                    }
                                },
                                "required": [
                                    "supplier_code",
                                    "amount"
                                ]
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/Payment"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/expenses": {
            "get": {
                "operationId": "expenses_list",
                "summary": "Expenses, newest first.",
                "tags": [
                    "Expenses"
                ],
                "x-cost": 1,
                "x-permissions": [
                    "view_expenses"
                ],
                "description": "Token permissions: view_expenses.",
                "parameters": [
                    {
                        "name": "search",
                        "in": "query",
                        "required": false,
                        "description": "Description or code.",
                        "schema": {
                            "type": "string",
                            "description": "Description or code."
                        }
                    },
                    {
                        "name": "from",
                        "in": "query",
                        "required": false,
                        "description": "Only rows on or after this date (YYYY-MM-DD).",
                        "schema": {
                            "type": "string",
                            "description": "Only rows on or after this date (YYYY-MM-DD)."
                        }
                    },
                    {
                        "name": "to",
                        "in": "query",
                        "required": false,
                        "description": "Only rows on or before this date (YYYY-MM-DD).",
                        "schema": {
                            "type": "string",
                            "description": "Only rows on or before this date (YYYY-MM-DD)."
                        }
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "required": false,
                        "description": "Rows per page, 1–100 (default 25). More than 50 costs 3 units.",
                        "schema": {
                            "type": "integer",
                            "description": "Rows per page, 1–100 (default 25). More than 50 costs 3 units."
                        }
                    },
                    {
                        "name": "offset",
                        "in": "query",
                        "required": false,
                        "description": "Rows to skip (default 0).",
                        "schema": {
                            "type": "integer",
                            "description": "Rows to skip (default 0)."
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Expense"
                                            }
                                        },
                                        "pagination": {
                                            "$ref": "#/components/schemas/Pagination"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "post": {
                "operationId": "expenses_create",
                "summary": "Record an expense paid from a vault or a payment method.",
                "tags": [
                    "Expenses"
                ],
                "x-cost": 2,
                "x-permissions": [
                    "add_expense"
                ],
                "description": "Token permissions: add_expense.",
                "parameters": [
                    {
                        "name": "Idempotency-Key",
                        "in": "header",
                        "required": false,
                        "description": "Send the same key when you retry: the write happens once.",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "branch": {
                                        "type": "string",
                                        "description": "The branch the operation belongs to (a code from GET /v1/branches). Optional when the token is limited to one branch."
                                    },
                                    "description": {
                                        "type": "string",
                                        "description": "What it was for."
                                    },
                                    "amount": {
                                        "type": "number",
                                        "description": "The amount."
                                    },
                                    "category": {
                                        "type": "string",
                                        "description": "Category.",
                                        "enum": [
                                            "electricity",
                                            "water",
                                            "gas",
                                            "internet_phone",
                                            "rent",
                                            "salaries",
                                            "maintenance",
                                            "transport",
                                            "packaging",
                                            "marketing",
                                            "cleaning",
                                            "other",
                                            ""
                                        ]
                                    },
                                    "vault_code": {
                                        "type": "string",
                                        "description": "The vault the money goes into / comes out of (GET /v1/vaults). Empty when the branch has one vault or a payment method is used."
                                    },
                                    "payment_method_code": {
                                        "type": "string",
                                        "description": "A payment method (GET /v1/payment-methods) instead of a vault: InstaPay, a wallet..."
                                    }
                                },
                                "required": [
                                    "description",
                                    "amount"
                                ]
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/Expense"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/expenses/{code}": {
            "delete": {
                "operationId": "expenses_delete",
                "summary": "Delete an expense (its vault movement goes with it).",
                "tags": [
                    "Expenses"
                ],
                "x-cost": 2,
                "x-permissions": [
                    "delete_expense"
                ],
                "description": "Token permissions: delete_expense.",
                "parameters": [
                    {
                        "name": "code",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "object",
                                            "properties": {
                                                "code": {
                                                    "type": "string"
                                                },
                                                "deleted": {
                                                    "type": "boolean"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/v1/events": {
            "get": {
                "operationId": "events_list",
                "summary": "What was created, changed or deleted, oldest first after a cursor — sync incrementally instead of re-reading everything. Only entities the token may read.",
                "tags": [
                    "Events"
                ],
                "x-cost": 1,
                "parameters": [
                    {
                        "name": "after",
                        "in": "query",
                        "required": false,
                        "description": "Return events with an id greater than this (0 = from the oldest kept).",
                        "schema": {
                            "type": "integer",
                            "description": "Return events with an id greater than this (0 = from the oldest kept)."
                        }
                    },
                    {
                        "name": "type",
                        "in": "query",
                        "required": false,
                        "description": "Filter, e.g. sales_bill or sales_bill.deleted.",
                        "schema": {
                            "type": "string",
                            "description": "Filter, e.g. sales_bill or sales_bill.deleted."
                        }
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "required": false,
                        "description": "1–100 (default 50).",
                        "schema": {
                            "type": "integer",
                            "description": "1–100 (default 50)."
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Event"
                                            }
                                        },
                                        "pagination": {
                                            "type": "object",
                                            "properties": {
                                                "next_after": {
                                                    "type": "integer"
                                                },
                                                "has_more": {
                                                    "type": "boolean"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "default": {
                        "description": "An error (see Errors).",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "securitySchemes": {
            "bearerAuth": {
                "type": "http",
                "scheme": "bearer",
                "bearerFormat": "prof_live_…",
                "description": "Create a token in Prof → Settings → API & integrations."
            }
        },
        "schemas": {
            "Error": {
                "type": "object",
                "required": [
                    "error"
                ],
                "properties": {
                    "error": {
                        "type": "object",
                        "required": [
                            "code",
                            "message"
                        ],
                        "properties": {
                            "code": {
                                "type": "string",
                                "description": "Stable machine-readable code (see Errors)."
                            },
                            "message": {
                                "type": "string",
                                "description": "Human-readable explanation (English)."
                            },
                            "details": {
                                "type": "object",
                                "description": "Extra fields for some codes (missing_permission, existing, retry_after...)."
                            },
                            "request_id": {
                                "type": "string",
                                "description": "Quote it when you contact support."
                            }
                        }
                    }
                }
            },
            "Pagination": {
                "type": "object",
                "properties": {
                    "limit": {
                        "type": "integer"
                    },
                    "offset": {
                        "type": "integer"
                    },
                    "has_more": {
                        "type": "boolean"
                    },
                    "next_offset": {
                        "type": [
                            "integer",
                            "null"
                        ],
                        "description": "Pass as offset for the next page; null on the last page."
                    }
                }
            },
            "Me": {
                "type": "object",
                "properties": {
                    "token": {
                        "type": "object",
                        "properties": {
                            "name": {
                                "type": "string"
                            },
                            "last4": {
                                "type": "string"
                            },
                            "expires_at": {
                                "type": [
                                    "string",
                                    "null"
                                ],
                                "description": "ISO 8601 UTC, or null when it never expires."
                            }
                        }
                    },
                    "permissions": {
                        "type": "array",
                        "items": {
                            "type": "string"
                        },
                        "description": "The permission keys this token holds."
                    },
                    "branches": {
                        "type": [
                            "array",
                            "null"
                        ],
                        "items": {
                            "type": "string"
                        },
                        "description": "Branch codes the token may work in; null = all."
                    },
                    "rate_limit": {
                        "type": "object",
                        "properties": {
                            "per_minute": {
                                "type": "integer"
                            },
                            "per_day": {
                                "type": "integer"
                            },
                            "used_today": {
                                "type": "integer"
                            }
                        }
                    },
                    "api_version": {
                        "type": "string"
                    }
                }
            },
            "Branch": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "string",
                        "description": ""
                    },
                    "name": {
                        "type": "string",
                        "description": ""
                    },
                    "address": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "phone": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "default_warehouse": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "default_vault": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    }
                }
            },
            "Warehouse": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "string",
                        "description": ""
                    },
                    "name": {
                        "type": "string",
                        "description": ""
                    },
                    "branches": {
                        "type": "array",
                        "items": {
                            "type": "string"
                        }
                    },
                    "default_branch": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    }
                }
            },
            "Vault": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "string",
                        "description": ""
                    },
                    "name": {
                        "type": "string",
                        "description": ""
                    },
                    "branch": {
                        "type": "string",
                        "description": "Branch name."
                    }
                }
            },
            "PaymentMethod": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "string",
                        "description": ""
                    },
                    "name": {
                        "type": "string",
                        "description": ""
                    },
                    "deferred": {
                        "type": "boolean",
                        "description": "Money arrives later (e.g. a card settlement)."
                    }
                }
            },
            "Category": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "string",
                        "description": ""
                    },
                    "name": {
                        "type": "string",
                        "description": ""
                    },
                    "parent_code": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    }
                }
            },
            "Customer": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "string",
                        "description": ""
                    },
                    "name": {
                        "type": "string",
                        "description": ""
                    },
                    "phone": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "phone2": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "email": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "company": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "address": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "gender": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "male | female"
                    },
                    "notes": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "branch": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "blacklisted": {
                        "type": "boolean",
                        "description": "Marked as not committed (غير ملتزم)."
                    },
                    "credit_limit": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "balance": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": "What the customer owes (positive) — null without permission to see balances."
                    },
                    "net_balance": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": "Balance netted with a linked supplier account."
                    },
                    "created_by": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Who created it: a user name, or \"API · <token name>\" when made through the API."
                    },
                    "edited_by": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Who last edited it (same form as created_by)."
                    }
                }
            },
            "Supplier": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "string",
                        "description": ""
                    },
                    "name": {
                        "type": "string",
                        "description": ""
                    },
                    "phone": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "phone2": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "phone3": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "company": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "address": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "field": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Line of business."
                    },
                    "notes": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "balance": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": "What you owe the supplier — null without permission to see balances."
                    },
                    "net_balance": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "created_by": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Who created it: a user name, or \"API · <token name>\" when made through the API."
                    },
                    "edited_by": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Who last edited it (same form as created_by)."
                    }
                }
            },
            "Product": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "string",
                        "description": ""
                    },
                    "name": {
                        "type": "string",
                        "description": ""
                    },
                    "specs": {
                        "type": "array",
                        "description": "Specifications.",
                        "items": {
                            "type": "object",
                            "properties": {
                                "name": {
                                    "type": "string"
                                },
                                "value": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "unit": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "category_code": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "retail_price": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "wholesale_price": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "compare_at_price": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": "Price before discount."
                    },
                    "min_price": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": "Lowest price allowed on a bill."
                    },
                    "max_price": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": "Highest price allowed on a bill."
                    },
                    "low_stock_alert": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "variant_group": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Products sharing it are variants of one item."
                    },
                    "image": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "description": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "HTML."
                    },
                    "hidden": {
                        "type": "boolean",
                        "description": ""
                    },
                    "created_by": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Who created it: a user name, or \"API · <token name>\" when made through the API."
                    },
                    "edited_by": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Who last edited it (same form as created_by)."
                    }
                }
            },
            "StockRow": {
                "type": "object",
                "description": "One stock batch.",
                "properties": {
                    "product_code": {
                        "type": "string",
                        "description": ""
                    },
                    "name": {
                        "type": "string",
                        "description": ""
                    },
                    "specs": {
                        "type": "array",
                        "description": "Specifications.",
                        "items": {
                            "type": "object",
                            "properties": {
                                "name": {
                                    "type": "string"
                                },
                                "value": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "warehouse": {
                        "type": "string",
                        "description": "Warehouse code."
                    },
                    "batch_code": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "quantity": {
                        "type": "number",
                        "description": ""
                    },
                    "expiry_date": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "supply_date": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "ISO 8601 UTC."
                    },
                    "unit_cost": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": "Only with view_purchase_prices."
                    }
                }
            },
            "SalesLine": {
                "type": "object",
                "properties": {
                    "product_code": {
                        "type": "string",
                        "description": ""
                    },
                    "name": {
                        "type": "string",
                        "description": ""
                    },
                    "specs": {
                        "type": "array",
                        "description": "Specifications.",
                        "items": {
                            "type": "object",
                            "properties": {
                                "name": {
                                    "type": "string"
                                },
                                "value": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "quantity": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "unit_price": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": "Price sold at."
                    },
                    "list_price": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "sale_type": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "retail | wholesale"
                    },
                    "gift": {
                        "type": "boolean",
                        "description": "Given free."
                    },
                    "returned_quantity": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "warehouse": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "notes": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "unit_cost": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": "Only with view_purchase_prices."
                    }
                }
            },
            "SalesBill": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "string",
                        "description": ""
                    },
                    "date": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "ISO 8601 UTC."
                    },
                    "type": {
                        "type": "string",
                        "description": "BILL, ORDER (sales order), RETURN..."
                    },
                    "customer_code": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "customer_name": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "branch": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Branch code."
                    },
                    "warehouse": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "subtotal": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "discount": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "total": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "paid": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "remaining": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "is_credit": {
                        "type": "boolean",
                        "description": "On account (آجل)."
                    },
                    "returned": {
                        "type": "boolean",
                        "description": ""
                    },
                    "return_of": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "For a return: the original bill."
                    },
                    "sale_type": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "sales_channel": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "payment_method": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "vault": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "shipping": {
                        "type": [
                            "object",
                            "null"
                        ],
                        "properties": {
                            "company": {
                                "type": [
                                    "string",
                                    "null"
                                ],
                                "description": ""
                            },
                            "governorate": {
                                "type": [
                                    "string",
                                    "null"
                                ],
                                "description": ""
                            },
                            "address": {
                                "type": [
                                    "string",
                                    "null"
                                ],
                                "description": ""
                            },
                            "fee": {
                                "type": [
                                    "number",
                                    "null"
                                ],
                                "description": ""
                            },
                            "customer_pays": {
                                "type": [
                                    "number",
                                    "null"
                                ],
                                "description": ""
                            },
                            "collection": {
                                "type": [
                                    "string",
                                    "null"
                                ],
                                "description": ""
                            },
                            "deposit": {
                                "type": [
                                    "number",
                                    "null"
                                ],
                                "description": ""
                            }
                        }
                    },
                    "store_order": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Online-store order it came from."
                    },
                    "notes": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "cashier": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "lines": {
                        "type": "array",
                        "items": {
                            "$ref": "#/components/schemas/SalesLine"
                        },
                        "description": "Only on single-bill reads."
                    },
                    "created_by": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Who created it: a user name, or \"API · <token name>\" when made through the API."
                    },
                    "edited_by": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Who last edited it (same form as created_by)."
                    }
                }
            },
            "PurchaseLine": {
                "type": "object",
                "properties": {
                    "product_code": {
                        "type": "string",
                        "description": ""
                    },
                    "name": {
                        "type": "string",
                        "description": ""
                    },
                    "specs": {
                        "type": "array",
                        "description": "Specifications.",
                        "items": {
                            "type": "object",
                            "properties": {
                                "name": {
                                    "type": "string"
                                },
                                "value": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "quantity": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "retail_price": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "wholesale_price": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "expiry_date": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "batch_code": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "returned_quantity": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "unit_cost": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": "Only with view_purchase_prices."
                    }
                }
            },
            "PurchaseBill": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "string",
                        "description": ""
                    },
                    "date": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "ISO 8601 UTC."
                    },
                    "type": {
                        "type": "string",
                        "description": ""
                    },
                    "supplier_code": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "warehouse": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "subtotal": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "discount": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "total": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "paid": {
                        "type": [
                            "number",
                            "null"
                        ],
                        "description": ""
                    },
                    "is_credit": {
                        "type": "boolean",
                        "description": ""
                    },
                    "returned": {
                        "type": "boolean",
                        "description": ""
                    },
                    "return_of": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "notes": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "lines": {
                        "type": "array",
                        "items": {
                            "$ref": "#/components/schemas/PurchaseLine"
                        },
                        "description": "Only on single-bill reads."
                    },
                    "created_by": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Who created it: a user name, or \"API · <token name>\" when made through the API."
                    },
                    "edited_by": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Who last edited it (same form as created_by)."
                    }
                }
            },
            "Payment": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "string",
                        "description": ""
                    },
                    "date": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "ISO 8601 UTC."
                    },
                    "account": {
                        "type": "string",
                        "description": "customer | supplier"
                    },
                    "party_code": {
                        "type": "string",
                        "description": ""
                    },
                    "amount": {
                        "type": "number",
                        "description": ""
                    },
                    "bill_code": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "The bill it settled, if any."
                    },
                    "branch": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "notes": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "created_by": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Who created it: a user name, or \"API · <token name>\" when made through the API."
                    },
                    "edited_by": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Who last edited it (same form as created_by)."
                    }
                }
            },
            "Expense": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "string",
                        "description": ""
                    },
                    "date": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "ISO 8601 UTC."
                    },
                    "description": {
                        "type": "string",
                        "description": ""
                    },
                    "amount": {
                        "type": "number",
                        "description": ""
                    },
                    "category": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": ""
                    },
                    "branch": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Branch name."
                    },
                    "created_by": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Who created it: a user name, or \"API · <token name>\" when made through the API."
                    },
                    "edited_by": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "description": "Who last edited it (same form as created_by)."
                    }
                }
            },
            "Event": {
                "type": "object",
                "description": "The same object is the body of a webhook call.",
                "properties": {
                    "id": {
                        "type": "integer",
                        "description": "Increasing. Use it as the cursor (after=) and to ignore repeats."
                    },
                    "type": {
                        "type": "string",
                        "description": "<entity>.<created|updated|deleted>, e.g. sales_bill.deleted"
                    },
                    "entity": {
                        "type": "string",
                        "description": "customer, supplier, product, sales_bill, purchase_bill, payment, expense"
                    },
                    "code": {
                        "type": "string",
                        "description": "The record code. Read the record itself for its current state."
                    },
                    "source": {
                        "type": "string",
                        "description": "app (someone in Prof), api (a token) or system (Prof itself: store sync, workers)."
                    },
                    "actor": {
                        "type": "string",
                        "description": "The user, or \"API · <token name>\"."
                    },
                    "occurred_at": {
                        "type": "string",
                        "description": "ISO 8601 UTC."
                    },
                    "deleted": {
                        "type": [
                            "object",
                            "null"
                        ],
                        "description": "Deletes only: the record as it was (same shape as the resource)."
                    }
                }
            }
        }
    },
    "x-errors": [
        {
            "status": 400,
            "code": "INVALID_JSON",
            "meaning": "The body is not a JSON object."
        },
        {
            "status": 400,
            "code": "INVALID_PARAMETER / INVALID_DATE / INVALID_CODE",
            "meaning": "A query value or path code is not valid (dates are YYYY-MM-DD)."
        },
        {
            "status": 400,
            "code": "INVALID_IDEMPOTENCY_KEY",
            "meaning": "Idempotency-Key must be 8–100 characters of letters, digits, \"-\" or \"_\"."
        },
        {
            "status": 401,
            "code": "MISSING_TOKEN",
            "meaning": "No \"Authorization: Bearer <token>\" header."
        },
        {
            "status": 401,
            "code": "INVALID_TOKEN",
            "meaning": "Unknown token."
        },
        {
            "status": 401,
            "code": "TOKEN_EXPIRED",
            "meaning": "The token passed its expiry date. Extend it in Prof."
        },
        {
            "status": 401,
            "code": "TOKEN_REVOKED",
            "meaning": "Someone revoked the token in Prof."
        },
        {
            "status": 403,
            "code": "IP_NOT_ALLOWED",
            "meaning": "The token is limited to other IP addresses."
        },
        {
            "status": 403,
            "code": "FORBIDDEN",
            "meaning": "The token lacks a permission; details.missing_permission names it when known."
        },
        {
            "status": 403,
            "code": "BRANCH_ACCESS_DENIED",
            "meaning": "The token is limited to other branches."
        },
        {
            "status": 403,
            "code": "PLAN_NOT_PREMIUM",
            "meaning": "The account is not on a paid plan."
        },
        {
            "status": 403,
            "code": "API_DISABLED / DOMAIN_SUSPENDED",
            "meaning": "The API or the account is switched off. Contact support."
        },
        {
            "status": 404,
            "code": "NOT_FOUND",
            "meaning": "No such endpoint, or no such record (or not visible to this token)."
        },
        {
            "status": 405,
            "code": "METHOD_NOT_ALLOWED",
            "meaning": "The path exists with another method."
        },
        {
            "status": 409,
            "code": "SIMILAR_RECORDS_EXIST",
            "meaning": "A customer/supplier with this phone (or name) exists; details.existing lists them. A phone can never be reused; for the same name with another phone send \"allow_similar\": true."
        },
        {
            "status": 409,
            "code": "IDEMPOTENCY_IN_PROGRESS",
            "meaning": "The first request with this key is still running. Retry in a moment."
        },
        {
            "status": 413,
            "code": "BODY_TOO_LARGE",
            "meaning": "Bodies are limited to 256 KB."
        },
        {
            "status": 422,
            "code": "VALIDATION_FAILED",
            "meaning": "The request breaks one of the account's rules (stock, prices, missing data...); message says which."
        },
        {
            "status": 422,
            "code": "INSUFFICIENT_FUNDS",
            "meaning": "The vault or payment method does not hold enough money."
        },
        {
            "status": 422,
            "code": "BRANCH_REQUIRED",
            "meaning": "Say which branch (the token works in more than one)."
        },
        {
            "status": 422,
            "code": "IDEMPOTENCY_KEY_REUSED",
            "meaning": "The same key was used with a different request."
        },
        {
            "status": 422,
            "code": "<business codes>",
            "meaning": "The same refusals the app gives, e.g. CUSTOMER_HAS_BILLS, SUPPLIER_HAS_BILLS, INSUFFICIENT_STOCK, BILL_HAS_RETURNS, SUPPLY_BILL_GOODS_SOLD."
        },
        {
            "status": 429,
            "code": "RATE_LIMITED",
            "meaning": "Over the per-minute budget. Wait Retry-After seconds."
        },
        {
            "status": 429,
            "code": "DAILY_LIMIT_REACHED",
            "meaning": "Over the per-day budget; resets at midnight Cairo time."
        },
        {
            "status": 429,
            "code": "TOKEN_PAUSED",
            "meaning": "Went over the limit repeatedly; paused for 15 minutes."
        },
        {
            "status": 500,
            "code": "SERVER_ERROR",
            "meaning": "Our fault. Safe to retry with the same Idempotency-Key."
        },
        {
            "status": 503,
            "code": "MAINTENANCE / API_UNAVAILABLE",
            "meaning": "Try again shortly (Retry-After)."
        }
    ]
}
