{
  "openapi": "3.1.0",
  "info": {
    "title": "Databek Counter API",
    "version": "0.1.0",
    "description": "The HTTP API of counter.databek.com, the inventory counting PWA. Most of the product runs on\nNext.js pages and server actions; this document covers its route handlers: the counter phone's sync API\n(`/api/count/*`), the admin's live session data and Excel files (`/api/sessions/*`, `/api/reports/*`), Google\nsign-in, spreadsheet uploads and health.\n\n**Auth.** One httpOnly cookie for every role, `__Host-counter_session` (Secure, Path=/, no Domain, SameSite=Lax). An admin (`org_admin`) gets it by signing\nin (`/login`, Google); a counter (`org_counter`) gets it by opening the personal join link the admin made for\nit (`/join/<token>`), and that login works for that one session. No CSRF header: a write (any method but GET and HEAD) must come from this site's\nown pages, by `Sec-Fetch-Site: same-origin`, or by `Origin` where a browser sends no `Sec-Fetch-Site`; another site's\npage, a sibling `*.databek.com` host included, gets 403 `request.cross_site`.\n\n**Errors.** Two shapes: the counter API answers `{\"code\", \"message\", \"field\"?}`; the admin file endpoints, live\nsession data and uploads answer `{\"error\": {\"code\", \"message\"}}`. Messages are for display only: fixed English\ntext, except on uploads and the downloads' 409, 422 and 429 (the person's language, Uzbek or Russian).\n\n**Numbers.** Quantities and money are decimal strings (`\"12.5\"`), never floats.\n\n**Request id.** Every response except uploads and static files carries `X-Request-ID` (the caller's, or a new one).\n\nNot covered: the server actions behind the web pages (Next.js' internal calls, not a public API)."
  },
  "servers": [
    {
      "url": "https://counter.databek.com",
      "description": "Production"
    }
  ],
  "tags": [
    {
      "name": "counting",
      "description": "The counter phone: catalog, entries, totals, zone and heartbeat."
    },
    {
      "name": "sessions",
      "description": "The admin's live session data and Excel downloads."
    },
    {
      "name": "reports",
      "description": "Reports across stores."
    },
    {
      "name": "auth",
      "description": "Google sign-in for admins."
    },
    {
      "name": "uploads",
      "description": "Spreadsheet uploads of the import wizard and the template builder; any other action than these four answers 404 `upload.not_found`. Until 2026-11-08 they lived under `/app/inventarizatsiyalar/yangi/upload/`; that address answers 308 to the same action here."
    },
    {
      "name": "system",
      "description": "Health and the service worker's asset list."
    }
  ],
  "paths": {
    "/api/count/catalog": {
      "get": {
        "tags": [
          "counting"
        ],
        "summary": "Session catalog",
        "operationId": "count_catalog",
        "description": "The session's item list for offline search: id, barcode, alternate codes, article, name and unit, never book quantities or prices. The ETag is the session's catalog version, so a phone that already has it gets a cheap 304. Gzipped when the client accepts gzip.",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_counter",
          "summary": "Counter login (`org_counter`) made by a session's join link; it works for that one session only."
        },
        "parameters": [
          {
            "name": "If-None-Match",
            "in": "header",
            "required": false,
            "description": "The ETag of the catalog the phone has.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "Accept-Encoding",
            "in": "header",
            "required": false,
            "description": "With `gzip` the body comes compressed (`Content-Encoding: gzip`).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Catalog"
                },
                "example": {
                  "version": "\"6f1c2a7e-3b4d-4e5f-8a9b-0c1d2e3f4a5b.2\"",
                  "items": [
                    {
                      "id": "0b9e8d7c-6a5f-4e3d-9c2b-1a0f9e8d7c6b",
                      "b": "4780012345678",
                      "a": "MW-05",
                      "n": "Mineral water 0.5 l",
                      "u": "pcs"
                    }
                  ]
                }
              }
            },
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string"
                },
                "description": "`\"<session id>.<catalog version>\"`"
              },
              "Cache-Control": {
                "schema": {
                  "type": "string"
                },
                "description": "`no-store`: no browser cache keeps the catalog (also on 304)."
              }
            }
          },
          "304": {
            "description": "The phone's catalog is current (ETag matched)."
          },
          "404": {
            "description": "The session is gone.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountError"
                },
                "example": {
                  "code": "session.not_found",
                  "message": "Session not found"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/CountUnauthorized"
          },
          "403": {
            "$ref": "#/components/responses/CountForbidden"
          },
          "500": {
            "$ref": "#/components/responses/CountServerError"
          }
        }
      }
    },
    "/api/count/entries": {
      "get": {
        "tags": [
          "counting"
        ],
        "summary": "Own entries",
        "operationId": "count_entries_list",
        "description": "The caller's own latest entries, newest first (the History tab; at most 500). With `?item=` only the live entries of that item, however old (at most 5000). Totals come from `/api/count/totals`.",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_counter",
          "summary": "Counter login (`org_counter`) made by a session's join link; it works for that one session only."
        },
        "parameters": [
          {
            "name": "item",
            "in": "query",
            "required": false,
            "description": "Only this item's live entries.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "entries"
                  ],
                  "properties": {
                    "entries": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/OwnEntry"
                      }
                    }
                  }
                },
                "example": {
                  "entries": [
                    {
                      "id": "2d4f6a8c-1e3b-4d5f-a7c9-e1b3d5f7a9c2",
                      "itemId": "0b9e8d7c-6a5f-4e3d-9c2b-1a0f9e8d7c6b",
                      "code": "4780012345678",
                      "name": "Mineral water 0.5 l",
                      "qtyGood": "12",
                      "qtyDamaged": "0",
                      "qtyReturned": "0",
                      "damageReason": null,
                      "zoneId": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
                      "inputMethod": "camera",
                      "createdAt": "2026-11-08T04:30:12.512Z",
                      "deleted": false,
                      "recountEpoch": 0
                    }
                  ]
                }
              }
            }
          },
          "422": {
            "description": "`item` is not a UUID.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountError"
                },
                "example": {
                  "code": "request.invalid",
                  "message": "invalid"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/CountUnauthorized"
          },
          "403": {
            "$ref": "#/components/responses/CountForbidden"
          },
          "500": {
            "$ref": "#/components/responses/CountServerError"
          }
        }
      },
      "post": {
        "tags": [
          "counting"
        ],
        "summary": "Upload entries",
        "operationId": "count_entries_upload",
        "description": "A batch from the phone's offline outbox (1–200 entries, body up to 1 000 000 bytes). Every entry is judged on its own: `accepted` is stored, `late` waits for an admin (the session is closed), `rejected` will never fit. Entries are append-only and keyed by their id, so resending a batch is safe. At most 3000 entries a minute per counter.",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_counter",
          "summary": "Counter login (`org_counter`) made by a session's join link; it works for that one session only."
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "entries"
                ],
                "properties": {
                  "entries": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 200,
                    "items": {
                      "$ref": "#/components/schemas/EntryInput"
                    }
                  }
                }
              },
              "example": {
                "entries": [
                  {
                    "id": "2d4f6a8c-1e3b-4d5f-a7c9-e1b3d5f7a9c2",
                    "itemId": "0b9e8d7c-6a5f-4e3d-9c2b-1a0f9e8d7c6b",
                    "code": "4780012345678",
                    "zoneId": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
                    "qtyGood": "12",
                    "qtyDamaged": "0",
                    "qtyReturned": "0",
                    "inputMethod": "camera",
                    "rawScan": "4780012345678",
                    "recountEpoch": 0,
                    "clientCreatedAt": "2026-11-08T09:30:12.512+05:00"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EntriesResult"
                },
                "example": {
                  "accepted": [
                    "2d4f6a8c-1e3b-4d5f-a7c9-e1b3d5f7a9c2"
                  ],
                  "late": [],
                  "rejected": []
                }
              }
            }
          },
          "400": {
            "description": "Not JSON (`request.invalid_json`) or not a batch of 1–200 entries (`request.invalid`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountError"
                },
                "example": {
                  "code": "request.invalid",
                  "message": "Invalid batch"
                }
              }
            }
          },
          "404": {
            "description": "The session is gone.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountError"
                },
                "example": {
                  "code": "session.not_found",
                  "message": "Session not found"
                }
              }
            }
          },
          "409": {
            "description": "The session is a draft.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountError"
                },
                "example": {
                  "code": "session.closed",
                  "message": "Session is not open"
                }
              }
            }
          },
          "413": {
            "description": "The body is over 1 000 000 bytes.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountError"
                },
                "example": {
                  "code": "request.too_large",
                  "message": "Body too large"
                }
              }
            }
          },
          "423": {
            "description": "The admin paused counting.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountError"
                },
                "example": {
                  "code": "session.locked",
                  "message": "Session is locked"
                }
              }
            }
          },
          "429": {
            "description": "Over 3000 entries in a minute.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountError"
                },
                "example": {
                  "code": "rate.limited",
                  "message": "Too many entries"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/CountUnauthorized"
          },
          "403": {
            "$ref": "#/components/responses/CountForbidden"
          },
          "500": {
            "$ref": "#/components/responses/CountServerError"
          }
        }
      }
    },
    "/api/count/entries/{id}": {
      "delete": {
        "tags": [
          "counting"
        ],
        "summary": "Delete own entry",
        "operationId": "count_entry_delete",
        "description": "Soft delete of the caller's own entry while the session is open; the row stays for the audit trail. Deleting an entry that is already deleted answers 200 again.",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_counter",
          "summary": "Counter login (`org_counter`) made by a session's join link; it works for that one session only."
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Entry id.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "deleted": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                },
                "example": {
                  "deleted": "2d4f6a8c-1e3b-4d5f-a7c9-e1b3d5f7a9c2"
                }
              }
            }
          },
          "404": {
            "description": "Not one of the caller's entries.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountError"
                },
                "example": {
                  "code": "entry.not_found",
                  "message": "Entry not found"
                }
              }
            }
          },
          "409": {
            "description": "The session is not open.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountError"
                },
                "example": {
                  "code": "session.closed",
                  "message": "Session is not open"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/CountUnauthorized"
          },
          "403": {
            "$ref": "#/components/responses/CountForbidden"
          },
          "500": {
            "$ref": "#/components/responses/CountServerError"
          }
        }
      }
    },
    "/api/count/lookup": {
      "get": {
        "tags": [
          "counting"
        ],
        "summary": "Look up items",
        "operationId": "count_lookup",
        "description": "One product by its scanned code (barcode and alternate codes, with GTIN padding variants, then the article), or a short list by text where every word must match the name, barcode or article. At most 30 items; a text under 2 characters returns none.",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_counter",
          "summary": "Counter login (`org_counter`) made by a session's join link; it works for that one session only."
        },
        "parameters": [
          {
            "name": "code",
            "in": "query",
            "required": false,
            "description": "A scanned code (up to 500 characters); wins over `q`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "description": "Search text (up to 100 characters).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/CatalogItem"
                      },
                      "maxItems": 30
                    }
                  }
                },
                "example": {
                  "items": [
                    {
                      "id": "0b9e8d7c-6a5f-4e3d-9c2b-1a0f9e8d7c6b",
                      "b": "4780012345678",
                      "a": "MW-05",
                      "n": "Mineral water 0.5 l",
                      "u": "pcs"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/CountUnauthorized"
          },
          "403": {
            "$ref": "#/components/responses/CountForbidden"
          },
          "500": {
            "$ref": "#/components/responses/CountServerError"
          }
        }
      }
    },
    "/api/count/me": {
      "get": {
        "tags": [
          "counting"
        ],
        "summary": "Counter screen data",
        "operationId": "count_me",
        "description": "Session, store, organization, settings, zones, the caller's zone, recounts and the running release.",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_counter",
          "summary": "Counter login (`org_counter`) made by a session's join link; it works for that one session only."
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountMe"
                },
                "example": {
                  "user": {
                    "id": "5c6d7e8f-9a0b-4c1d-8e2f-3a4b5c6d7e8f",
                    "name": "Counter 3"
                  },
                  "session": {
                    "id": "6f1c2a7e-3b4d-4e5f-8a9b-0c1d2e3f4a5b",
                    "name": "November count",
                    "status": "open",
                    "itemCount": 1840,
                    "catalogVersion": 2
                  },
                  "store": {
                    "name": "Main store"
                  },
                  "org": {
                    "name": "Example Retail",
                    "accentColor": "#ff3621"
                  },
                  "settings": {
                    "validity": {
                      "mode": "session"
                    },
                    "deviceBinding": "one",
                    "maxUses": null,
                    "autoLogoutHours": 0,
                    "counterChoosesZone": true,
                    "inputs": {
                      "camera": true,
                      "bluetooth": true,
                      "plusOne": true,
                      "search": true
                    },
                    "showOwnTotal": true,
                    "damageReasons": {
                      "enabled": false,
                      "list": [
                        "Broken",
                        "Expired",
                        "Damaged package",
                        "Other"
                      ]
                    },
                    "duplicateGuardMs": 800,
                    "sounds": true,
                    "scanner": {
                      "maxInterKeyMs": 35,
                      "minLength": 4,
                      "suffix": "enter"
                    }
                  },
                  "zones": [
                    {
                      "id": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
                      "name": "Hall A"
                    }
                  ],
                  "zoneId": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
                  "tokenExpiresAt": null,
                  "release": "8e48c6a",
                  "recounts": [
                    {
                      "itemId": "0b9e8d7c-6a5f-4e3d-9c2b-1a0f9e8d7c6b",
                      "epoch": 1,
                      "counted": 0,
                      "open": true
                    }
                  ],
                  "recountTasks": [
                    {
                      "id": "0b9e8d7c-6a5f-4e3d-9c2b-1a0f9e8d7c6b",
                      "b": "4780012345678",
                      "a": "MW-05",
                      "n": "Mineral water 0.5 l",
                      "u": "pcs",
                      "epoch": 1
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "The session is gone.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountError"
                },
                "example": {
                  "code": "session.not_found",
                  "message": "Session not found"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/CountUnauthorized"
          },
          "403": {
            "$ref": "#/components/responses/CountForbidden"
          },
          "500": {
            "$ref": "#/components/responses/CountServerError"
          }
        }
      },
      "post": {
        "tags": [
          "counting"
        ],
        "summary": "Heartbeat",
        "operationId": "count_heartbeat",
        "description": "The phone reports how many entries still wait in its outbox (the admin's Close dialog warns about them) and gets the fresh screen data back.",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_counter",
          "summary": "Counter login (`org_counter`) made by a session's join link; it works for that one session only."
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "pending"
                ],
                "properties": {
                  "pending": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 10000000
                  }
                }
              },
              "example": {
                "pending": 3
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountMe"
                },
                "example": {
                  "user": {
                    "id": "5c6d7e8f-9a0b-4c1d-8e2f-3a4b5c6d7e8f",
                    "name": "Counter 3"
                  },
                  "session": {
                    "id": "6f1c2a7e-3b4d-4e5f-8a9b-0c1d2e3f4a5b",
                    "name": "November count",
                    "status": "open",
                    "itemCount": 1840,
                    "catalogVersion": 2
                  },
                  "store": {
                    "name": "Main store"
                  },
                  "org": {
                    "name": "Example Retail",
                    "accentColor": "#ff3621"
                  },
                  "settings": {
                    "validity": {
                      "mode": "session"
                    },
                    "deviceBinding": "one",
                    "maxUses": null,
                    "autoLogoutHours": 0,
                    "counterChoosesZone": true,
                    "inputs": {
                      "camera": true,
                      "bluetooth": true,
                      "plusOne": true,
                      "search": true
                    },
                    "showOwnTotal": true,
                    "damageReasons": {
                      "enabled": false,
                      "list": [
                        "Broken",
                        "Expired",
                        "Damaged package",
                        "Other"
                      ]
                    },
                    "duplicateGuardMs": 800,
                    "sounds": true,
                    "scanner": {
                      "maxInterKeyMs": 35,
                      "minLength": 4,
                      "suffix": "enter"
                    }
                  },
                  "zones": [
                    {
                      "id": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
                      "name": "Hall A"
                    }
                  ],
                  "zoneId": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
                  "tokenExpiresAt": null,
                  "release": "8e48c6a",
                  "recounts": [
                    {
                      "itemId": "0b9e8d7c-6a5f-4e3d-9c2b-1a0f9e8d7c6b",
                      "epoch": 1,
                      "counted": 0,
                      "open": true
                    }
                  ],
                  "recountTasks": [
                    {
                      "id": "0b9e8d7c-6a5f-4e3d-9c2b-1a0f9e8d7c6b",
                      "b": "4780012345678",
                      "a": "MW-05",
                      "n": "Mineral water 0.5 l",
                      "u": "pcs",
                      "epoch": 1
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "The body is not `{pending}`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountError"
                },
                "example": {
                  "code": "request.invalid",
                  "message": "Invalid heartbeat"
                }
              }
            }
          },
          "404": {
            "description": "The session is gone.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountError"
                },
                "example": {
                  "code": "session.not_found",
                  "message": "Session not found"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/CountUnauthorized"
          },
          "403": {
            "$ref": "#/components/responses/CountForbidden"
          },
          "500": {
            "$ref": "#/components/responses/CountServerError"
          }
        }
      }
    },
    "/api/count/totals": {
      "get": {
        "tags": [
          "counting"
        ],
        "summary": "Own totals",
        "operationId": "count_totals",
        "description": "The caller's own running totals per item in the epoch in force: never other counters' numbers, never the book quantity.",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_counter",
          "summary": "Counter login (`org_counter`) made by a session's join link; it works for that one session only."
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "totals": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/OwnTotal"
                      }
                    }
                  }
                },
                "example": {
                  "totals": [
                    [
                      "0b9e8d7c-6a5f-4e3d-9c2b-1a0f9e8d7c6b",
                      "24",
                      "1",
                      "0",
                      3
                    ]
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/CountUnauthorized"
          },
          "403": {
            "$ref": "#/components/responses/CountForbidden"
          },
          "500": {
            "$ref": "#/components/responses/CountServerError"
          }
        }
      }
    },
    "/api/count/zone": {
      "post": {
        "tags": [
          "counting"
        ],
        "summary": "Choose zone",
        "operationId": "count_zone",
        "description": "The counter picks their zone, or clears it with null; only when the settings let counters choose (`counterChoosesZone`).",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_counter",
          "summary": "Counter login (`org_counter`) made by a session's join link; it works for that one session only."
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "zoneId"
                ],
                "properties": {
                  "zoneId": {
                    "anyOf": [
                      {
                        "type": "string",
                        "format": "uuid"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                }
              },
              "example": {
                "zoneId": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "zoneId": {
                      "anyOf": [
                        {
                          "type": "string",
                          "format": "uuid"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  }
                },
                "example": {
                  "zoneId": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d"
                }
              }
            }
          },
          "400": {
            "description": "The body is not JSON.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountError"
                },
                "example": {
                  "code": "request.invalid_json",
                  "message": "Invalid JSON"
                }
              }
            }
          },
          "403": {
            "description": "Not a counter of an active session (`auth.forbidden`), or the admin assigns zones (`zone.locked`), or the request came from another site's page (`request.cross_site`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountError"
                },
                "example": {
                  "code": "zone.locked",
                  "message": "Zone is assigned by the admin"
                }
              }
            }
          },
          "404": {
            "description": "No such zone in this session.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountError"
                },
                "example": {
                  "code": "zone.not_found",
                  "message": "Zone not found",
                  "field": "zoneId"
                }
              }
            }
          },
          "409": {
            "description": "The session is closed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountError"
                },
                "example": {
                  "code": "session.closed",
                  "message": "Session is closed"
                }
              }
            }
          },
          "422": {
            "description": "`zoneId` is not a UUID or null.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CountError"
                },
                "example": {
                  "code": "request.invalid",
                  "message": "invalid",
                  "field": "zoneId"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/CountUnauthorized"
          },
          "500": {
            "$ref": "#/components/responses/CountServerError"
          }
        }
      }
    },
    "/api/sessions/{id}/events": {
      "get": {
        "tags": [
          "sessions"
        ],
        "summary": "Live entries (SSE)",
        "operationId": "session_events",
        "description": "Server-Sent Events for the live dashboard: `ready` first, then one `entry` event per new or changed count entry, and a `: ping` comment every 25 s. The stream ends when the login stops being valid (removed admin, suspended organization, ended login). At most 5 streams per user: a sixth closes the oldest.",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_admin",
          "summary": "Organization admin (`org_admin`)."
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Inventory session id.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "An endless `text/event-stream`; each `entry` event's `data` is an EntryEvent.",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "x-event-data": {
                    "$ref": "#/components/schemas/EntryEvent"
                  }
                },
                "example": "retry: 3000\nevent: ready\ndata: {}\n\nevent: entry\ndata: {\"type\": \"entry\", \"id\": \"2d4f6a8c-1e3b-4d5f-a7c9-e1b3d5f7a9c2\", \"item_id\": \"0b9e8d7c-6a5f-4e3d-9c2b-1a0f9e8d7c6b\", \"user_id\": \"5c6d7e8f-9a0b-4c1d-8e2f-3a4b5c6d7e8f\"}\n\n: ping\n\n"
              }
            }
          },
          "401": {
            "description": "Not signed in.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "auth",
                    "message": "unauthorized"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Not an admin of an organization (same body as 401).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "auth",
                    "message": "unauthorized"
                  }
                }
              }
            }
          },
          "404": {
            "description": "No such session in the organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "not_found",
                    "message": "session not found"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/sessions/{id}/stats": {
      "get": {
        "tags": [
          "sessions"
        ],
        "summary": "Session statistics",
        "operationId": "session_stats",
        "description": "Totals, differences, zones and counters of the live dashboard, and the 30 latest entries. A malformed id answers 404 `session.not_found`, like an unknown one.",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_admin",
          "summary": "Organization admin (`org_admin`)."
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Inventory session id.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "stats": {
                      "$ref": "#/components/schemas/SessionStats"
                    },
                    "activity": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ActivityRow"
                      },
                      "maxItems": 30
                    }
                  }
                },
                "example": {
                  "stats": {
                    "total": 1840,
                    "counted": 1312,
                    "diffCount": 57,
                    "diffSum": "-125400.00",
                    "uncountedSum": "8420000.00",
                    "damaged": "4",
                    "returned": "1",
                    "unknown": 6,
                    "recount": 2,
                    "byZone": [
                      {
                        "id": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
                        "name": "Hall A",
                        "items": 640,
                        "entries": 702
                      }
                    ],
                    "byCounter": [
                      {
                        "id": "5c6d7e8f-9a0b-4c1d-8e2f-3a4b5c6d7e8f",
                        "name": "Counter 3",
                        "items": 640,
                        "entries": 702,
                        "lastAt": "2026-11-08 04:30:12.512+00"
                      }
                    ]
                  },
                  "activity": [
                    {
                      "id": "2d4f6a8c-1e3b-4d5f-a7c9-e1b3d5f7a9c2",
                      "at": "2026-11-08 04:30:12.512+00",
                      "counter": "Counter 3",
                      "zone": "Hall A",
                      "itemName": "Mineral water 0.5 l",
                      "code": "4780012345678",
                      "good": "12",
                      "damaged": "0",
                      "returned": "0",
                      "method": "camera",
                      "deleted": false
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Not signed in.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "auth.required",
                    "message": "unauthorized"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Not an admin of an organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "auth.forbidden",
                    "message": "forbidden"
                  }
                }
              }
            }
          },
          "404": {
            "description": "No such session in the organization.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "session.not_found",
                    "message": "Session not found"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/sessions/{id}/export": {
      "get": {
        "tags": [
          "sessions"
        ],
        "summary": "Export for import",
        "operationId": "session_export",
        "description": "The session's original file with only the fact column (`qty_good` totals) filled, ready to import back into the accounting system. The name is `<original name> (counter).<ext>`. Downloads share one limit: 30 an hour per admin (export, items export, full report).",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_admin",
          "summary": "Organization admin (`org_admin`)."
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Inventory session id.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "description": "`xlsx` turns a .xls or .ods source into .xlsx; `source` keeps the source format.",
            "schema": {
              "type": "string",
              "enum": [
                "source",
                "xlsx"
              ],
              "default": "source"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The file, as an attachment.",
            "headers": {
              "Content-Disposition": {
                "$ref": "#/components/headers/ContentDisposition"
              }
            },
            "content": {
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/vnd.ms-excel": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "text/csv; charset=utf-8": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/vnd.oasis.opendocument.spreadsheet": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/vnd.ms-excel.sheet.macroEnabled.12": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "409": {
            "description": "The session has no stored source file.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "session.no_file",
                    "message": "The session has no source file"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/AdminUnauthorized"
          },
          "403": {
            "$ref": "#/components/responses/AdminForbidden"
          },
          "404": {
            "$ref": "#/components/responses/SessionNotFound"
          },
          "422": {
            "$ref": "#/components/responses/SheetFailed"
          },
          "429": {
            "$ref": "#/components/responses/DownloadLimited"
          }
        }
      }
    },
    "/api/sessions/{id}/items-export": {
      "get": {
        "tags": [
          "sessions"
        ],
        "summary": "Items table as Excel",
        "operationId": "session_items_export",
        "description": "What one tab of the items table holds, with its search and order, as .xlsx: every row, not the page on the screen. Headers and the file name are in Uzbek by design (a file reads the same whoever downloads it): `<session> — Pozitsiyalar — <tab>.xlsx`.",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_admin",
          "summary": "Organization admin (`org_admin`)."
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Inventory session id.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "f",
            "in": "query",
            "required": false,
            "description": "The tab.",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "diff",
                "uncounted",
                "damaged",
                "recount",
                "unknown"
              ],
              "default": "all"
            }
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "description": "Search text.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "description": "Column: `barcode`, `name`, `book`, `good`, `damaged`, `returned`, `diff`, `diffSum`; on the `unknown` tab `code`, `name`, `good`, `damaged`, `returned`, `counters`. Default: file order.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "dir",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ],
              "default": "asc"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The .xlsx file, as an attachment.",
            "headers": {
              "Content-Disposition": {
                "$ref": "#/components/headers/ContentDisposition"
              }
            },
            "content": {
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/AdminUnauthorized"
          },
          "403": {
            "$ref": "#/components/responses/AdminForbidden"
          },
          "404": {
            "$ref": "#/components/responses/SessionNotFound"
          },
          "422": {
            "$ref": "#/components/responses/SheetFailed"
          },
          "429": {
            "$ref": "#/components/responses/DownloadLimited"
          }
        }
      }
    },
    "/api/sessions/{id}/report": {
      "get": {
        "tags": [
          "sessions"
        ],
        "summary": "Full report",
        "operationId": "session_report",
        "description": "The full report workbook: items, every entry and the unknown codes, named `<session> — hisobot.xlsx` (Uzbek by design).",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_admin",
          "summary": "Organization admin (`org_admin`)."
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Inventory session id.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The .xlsx file, as an attachment.",
            "headers": {
              "Content-Disposition": {
                "$ref": "#/components/headers/ContentDisposition"
              }
            },
            "content": {
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/AdminUnauthorized"
          },
          "403": {
            "$ref": "#/components/responses/AdminForbidden"
          },
          "404": {
            "$ref": "#/components/responses/SessionNotFound"
          },
          "422": {
            "$ref": "#/components/responses/SheetFailed"
          },
          "429": {
            "$ref": "#/components/responses/DownloadLimited"
          }
        }
      }
    },
    "/api/reports/compare": {
      "get": {
        "tags": [
          "reports"
        ],
        "summary": "Compare stores",
        "operationId": "reports_compare",
        "description": "The latest closed session of every active store side by side, as .xlsx (`do'konlar-solishtirish.xlsx`, sheet `Solishtirish`; Uzbek headers by design): items, counted, differences and their value, uncounted value, damaged and returned.",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_admin",
          "summary": "Organization admin (`org_admin`)."
        },
        "responses": {
          "200": {
            "description": "The .xlsx file, as an attachment.",
            "headers": {
              "Content-Disposition": {
                "$ref": "#/components/headers/ContentDisposition"
              }
            },
            "content": {
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/AdminUnauthorized"
          },
          "403": {
            "$ref": "#/components/responses/AdminForbidden"
          }
        }
      }
    },
    "/api/auth/google": {
      "get": {
        "tags": [
          "auth"
        ],
        "summary": "Start Google sign-in",
        "operationId": "google_start",
        "description": "Redirects to Google. The flow state (state, PKCE verifier, nonce, `next`) rides in the short cookie `counter_google_flow` (10 minutes, path `/api/auth/google`), not in the database. With Google sign-in off it redirects to `/login?google=failed`. For admins only: a counter login cannot use Google.",
        "x-auth": {
          "kind": "public",
          "summary": "Public: no login."
        },
        "parameters": [
          {
            "name": "next",
            "in": "query",
            "required": false,
            "description": "A path on this site to land on after sign-in (in the user's own area).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "307": {
            "description": "To Google's consent page.",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          }
        }
      }
    },
    "/api/auth/google/callback": {
      "get": {
        "tags": [
          "auth"
        ],
        "summary": "Google sign-in callback",
        "operationId": "google_callback",
        "description": "Google returns here. On success the login cookie is set and the browser goes to `next` (or the role's home); a new person goes to `/signup/google` to name their organization; an address that was never proven is claimed and goes to `<home>/account?password=removed` (the old password was removed). A failure goes to `/login?google=<reason>`: `failed`, `cancelled`, `unverified`, `refused`, `conflict`, `suspended`, `limited` or `expired`. At most 30 callbacks per 15 minutes per IP.",
        "x-auth": {
          "kind": "public",
          "summary": "Public: no login."
        },
        "parameters": [
          {
            "name": "code",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "state",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "error",
            "in": "query",
            "required": false,
            "description": "Google's error (e.g. access_denied).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "307": {
            "description": "To the next page (see the description).",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              },
              "Set-Cookie": {
                "schema": {
                  "type": "string"
                },
                "description": "`__Host-counter_session` on success."
              }
            }
          }
        }
      }
    },
    "/app/inventories/new/upload/preview": {
      "post": {
        "tags": [
          "uploads"
        ],
        "summary": "Preview a session import",
        "operationId": "upload_preview",
        "description": "Reads an accounting export the way a new session would import it and answers what it found (the import wizard's preview). Nothing is stored. Rate limit: 30 an hour; over it the answer is `ok: false`. The route decides before it reads the body, so a refused upload costs nothing: one upload at a time per person, per organization and per network, a body that falls behind 100 KB/s after its first 15 seconds or takes longer than 60 seconds is dropped, and whoever sent three such bodies in 15 minutes waits.",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_admin",
          "summary": "Organization admin (`org_admin`)."
        },
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "The spreadsheet: xlsx, xls, csv or ods, up to 20 MB."
                  },
                  "templateId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "A template to read it with; empty: the best fitting one."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Always 200 once the form was read: `ok` tells whether the action worked.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "required": [
                        "ok",
                        "data"
                      ],
                      "properties": {
                        "ok": {
                          "const": true
                        },
                        "data": {
                          "$ref": "#/components/schemas/ImportPreview"
                        }
                      }
                    },
                    {
                      "$ref": "#/components/schemas/UploadFailure"
                    }
                  ]
                },
                "example": {
                  "ok": true,
                  "data": {
                    "templateId": null,
                    "templateName": "Automatic",
                    "sheetName": "Sheet1",
                    "headerRow": 1,
                    "headers": [
                      "Barcode",
                      "Article",
                      "Name",
                      "Unit",
                      "Qty",
                      "Price"
                    ],
                    "columns": {
                      "barcode": 0,
                      "article": 1,
                      "name": 2,
                      "unit": 3,
                      "book_qty": 4,
                      "fact_qty": 6,
                      "price": 5
                    },
                    "factAppended": true,
                    "count": 1840,
                    "sample": [
                      {
                        "rowIndex": 2,
                        "barcode": "4780012345678",
                        "article": "MW-05",
                        "name": "Mineral water 0.5 l",
                        "unit": "pcs",
                        "book": "24",
                        "price": "4500"
                      }
                    ],
                    "warnings": [],
                    "warningCount": 0,
                    "excluded": [
                      {
                        "rowIndex": 1843,
                        "reason": "summary",
                        "text": "Total"
                      }
                    ],
                    "excludedCount": 1,
                    "duplicates": 0
                  }
                }
              }
            }
          },
          "400": {
            "description": "The multipart form could not be read.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.unreadable",
                    "message": "The file could not be read"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Not signed in.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "auth.required",
                    "message": "Access denied"
                  }
                }
              }
            }
          },
          "403": {
            "description": "A counter login (`org_counter`) cannot upload (`auth.forbidden`), and an `org_admin` whose email is not verified yet uploads nothing (`upload.verify_first`); nothing from another site's page is read (`request.cross_site`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "auth.forbidden",
                    "message": "Access denied"
                  }
                }
              }
            }
          },
          "408": {
            "description": "The body fell behind its pace (100 KB/s after the first 15 seconds; a small file's deadline is those 15 seconds plus its size at that pace) or was still arriving after 60 seconds: it is dropped, the place freed, and it counts as a slow upload of the person, the organization and the network.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.too_slow",
                    "message": "The file uploaded too slowly and was stopped. Check the connection and try again."
                  }
                }
              }
            }
          },
          "409": {
            "description": "This person, this organization or this network (an IPv4 address, an IPv6 /64) already has an upload in the web process (one at a time each); the body is not read. Another account's upload on the same network answers \"Another file is still uploading from this network\".",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.in_progress",
                    "message": "Another file of your organization is still uploading. Try again when it is done."
                  }
                }
              }
            }
          },
          "413": {
            "description": "No `Content-Length`, or the body is over 20 MB plus 1 MiB for the other fields.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.too_large",
                    "message": "The file is larger than 20 MB"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Three uploads of this person, this organization or this network were dropped as too slow in 15 minutes: it waits until that window ends (`Retry-After`, seconds); the body is not read.",
            "headers": {
              "Retry-After": {
                "description": "Seconds until an upload may take a place again.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.too_slow_wait",
                    "message": "The last files uploaded too slowly. Try again in 15 minutes."
                  }
                }
              }
            }
          },
          "503": {
            "description": "Six uploads are already being read.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.busy",
                    "message": "Spreadsheets are busy, try again"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/app/inventories/new/upload/create": {
      "post": {
        "tags": [
          "uploads"
        ],
        "summary": "Create a session from a file",
        "operationId": "upload_create",
        "description": "Imports the file into a new open session of the store, with its zones. Refused when the organization is over its limits or the file has more than 100 000 items. Rate limit: 30 an hour; over it the answer is `ok: false`. The route decides before it reads the body, so a refused upload costs nothing: one upload at a time per person, per organization and per network, a body that falls behind 100 KB/s after its first 15 seconds or takes longer than 60 seconds is dropped, and whoever sent three such bodies in 15 minutes waits.",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_admin",
          "summary": "Organization admin (`org_admin`)."
        },
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "storeId",
                  "file"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 160,
                    "description": "Session name."
                  },
                  "storeId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "A store of the organization."
                  },
                  "zones": {
                    "type": "string",
                    "description": "Zone names separated by new lines or commas (at most 50)."
                  },
                  "templateId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Empty: the best fitting template."
                  },
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "The spreadsheet: xlsx, xls, csv or ods, up to 20 MB."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Always 200 once the form was read: `ok` tells whether the action worked.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "required": [
                        "ok",
                        "data"
                      ],
                      "properties": {
                        "ok": {
                          "const": true
                        },
                        "data": {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "format": "uuid"
                            }
                          }
                        }
                      }
                    },
                    {
                      "$ref": "#/components/schemas/UploadFailure"
                    }
                  ]
                },
                "example": {
                  "ok": true,
                  "data": {
                    "id": "6f1c2a7e-3b4d-4e5f-8a9b-0c1d2e3f4a5b"
                  }
                }
              }
            }
          },
          "400": {
            "description": "The multipart form could not be read.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.unreadable",
                    "message": "The file could not be read"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Not signed in.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "auth.required",
                    "message": "Access denied"
                  }
                }
              }
            }
          },
          "403": {
            "description": "A counter login (`org_counter`) cannot upload (`auth.forbidden`), and an `org_admin` whose email is not verified yet uploads nothing (`upload.verify_first`); nothing from another site's page is read (`request.cross_site`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "auth.forbidden",
                    "message": "Access denied"
                  }
                }
              }
            }
          },
          "408": {
            "description": "The body fell behind its pace (100 KB/s after the first 15 seconds; a small file's deadline is those 15 seconds plus its size at that pace) or was still arriving after 60 seconds: it is dropped, the place freed, and it counts as a slow upload of the person, the organization and the network.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.too_slow",
                    "message": "The file uploaded too slowly and was stopped. Check the connection and try again."
                  }
                }
              }
            }
          },
          "409": {
            "description": "This person, this organization or this network (an IPv4 address, an IPv6 /64) already has an upload in the web process (one at a time each); the body is not read. Another account's upload on the same network answers \"Another file is still uploading from this network\".",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.in_progress",
                    "message": "Another file of your organization is still uploading. Try again when it is done."
                  }
                }
              }
            }
          },
          "413": {
            "description": "No `Content-Length`, or the body is over 20 MB plus 1 MiB for the other fields.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.too_large",
                    "message": "The file is larger than 20 MB"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Three uploads of this person, this organization or this network were dropped as too slow in 15 minutes: it waits until that window ends (`Retry-After`, seconds); the body is not read.",
            "headers": {
              "Retry-After": {
                "description": "Seconds until an upload may take a place again.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.too_slow_wait",
                    "message": "The last files uploaded too slowly. Try again in 15 minutes."
                  }
                }
              }
            }
          },
          "503": {
            "description": "Six uploads are already being read.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.busy",
                    "message": "Spreadsheets are busy, try again"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/app/inventories/new/upload/sample": {
      "post": {
        "tags": [
          "uploads"
        ],
        "summary": "Analyse a template sample",
        "operationId": "upload_sample",
        "description": "The template builder's first step: sheets, the detected header and a first guess of the column mapping. Rate limit: 30 an hour; over it the answer is `ok: false`. The route decides before it reads the body, so a refused upload costs nothing: one upload at a time per person, per organization and per network, a body that falls behind 100 KB/s after its first 15 seconds or takes longer than 60 seconds is dropped, and whoever sent three such bodies in 15 minutes waits.",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_admin",
          "summary": "Organization admin (`org_admin`), for the organization's templates."
        },
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "The spreadsheet: xlsx, xls, csv or ods, up to 20 MB."
                  },
                  "sheet": {
                    "type": "string",
                    "description": "Sheet name; empty: detect."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Always 200 once the form was read: `ok` tells whether the action worked.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "required": [
                        "ok",
                        "data"
                      ],
                      "properties": {
                        "ok": {
                          "const": true
                        },
                        "data": {
                          "$ref": "#/components/schemas/SampleAnalysis"
                        }
                      }
                    },
                    {
                      "$ref": "#/components/schemas/UploadFailure"
                    }
                  ]
                },
                "example": {
                  "ok": true,
                  "data": {
                    "fileName": "stock.xlsx",
                    "sheetNames": [
                      "Sheet1"
                    ],
                    "sheetName": "Sheet1",
                    "headerRow": 1,
                    "headers": [
                      "Barcode",
                      "Name",
                      "Qty"
                    ],
                    "columns": {
                      "barcode": 0,
                      "name": 1,
                      "book_qty": 2
                    },
                    "mapping": {
                      "barcode": "Barcode",
                      "name": "Name",
                      "book_qty": "Qty"
                    },
                    "previewRows": [
                      [
                        "4780012345678",
                        "Mineral water 0.5 l",
                        "24"
                      ]
                    ]
                  }
                }
              }
            }
          },
          "400": {
            "description": "The multipart form could not be read.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.unreadable",
                    "message": "The file could not be read"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Not signed in.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "auth.required",
                    "message": "Access denied"
                  }
                }
              }
            }
          },
          "403": {
            "description": "A counter login (`org_counter`) cannot upload (`auth.forbidden`), and an `org_admin` whose email is not verified yet uploads nothing (`upload.verify_first`); nothing from another site's page is read (`request.cross_site`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "auth.forbidden",
                    "message": "Access denied"
                  }
                }
              }
            }
          },
          "408": {
            "description": "The body fell behind its pace (100 KB/s after the first 15 seconds; a small file's deadline is those 15 seconds plus its size at that pace) or was still arriving after 60 seconds: it is dropped, the place freed, and it counts as a slow upload of the person, the organization and the network.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.too_slow",
                    "message": "The file uploaded too slowly and was stopped. Check the connection and try again."
                  }
                }
              }
            }
          },
          "409": {
            "description": "This person, this organization or this network (an IPv4 address, an IPv6 /64) already has an upload in the web process (one at a time each); the body is not read. Another account's upload on the same network answers \"Another file is still uploading from this network\".",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.in_progress",
                    "message": "Another file of your organization is still uploading. Try again when it is done."
                  }
                }
              }
            }
          },
          "413": {
            "description": "No `Content-Length`, or the body is over 20 MB plus 1 MiB for the other fields.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.too_large",
                    "message": "The file is larger than 20 MB"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Three uploads of this person, this organization or this network were dropped as too slow in 15 minutes: it waits until that window ends (`Retry-After`, seconds); the body is not read.",
            "headers": {
              "Retry-After": {
                "description": "Seconds until an upload may take a place again.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.too_slow_wait",
                    "message": "The last files uploaded too slowly. Try again in 15 minutes."
                  }
                }
              }
            }
          },
          "503": {
            "description": "Six uploads are already being read.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.busy",
                    "message": "Spreadsheets are busy, try again"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/app/inventories/new/upload/export-preview": {
      "post": {
        "tags": [
          "uploads"
        ],
        "summary": "Preview a template export",
        "operationId": "upload_export_preview",
        "description": "Parses the sample with the builder's mapping and exports it with made-up counts, to show where the counts will land. Rate limit: 30 an hour; over it the answer is `ok: false`. The route decides before it reads the body, so a refused upload costs nothing: one upload at a time per person, per organization and per network, a body that falls behind 100 KB/s after its first 15 seconds or takes longer than 60 seconds is dropped, and whoever sent three such bodies in 15 minutes waits.",
        "security": [
          {
            "sessionCookie": []
          }
        ],
        "x-auth": {
          "kind": "org_admin",
          "summary": "Organization admin (`org_admin`), for the organization's templates."
        },
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file",
                  "config"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "The spreadsheet: xlsx, xls, csv or ods, up to 20 MB."
                  },
                  "config": {
                    "type": "string",
                    "contentMediaType": "application/json",
                    "description": "JSON: `{\"sheetName\"?, \"mapping\": {field: header}, \"decimalSeparator\": \",\"|\".\"|\"auto\", \"uncounted\": \"blank\"|\"zero\"}`; fields are `barcode`, `article`, `name`, `unit`, `book_qty`, `fact_qty`, `price`, at least one of the first three."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Always 200 once the form was read: `ok` tells whether the action worked.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "required": [
                        "ok",
                        "data"
                      ],
                      "properties": {
                        "ok": {
                          "const": true
                        },
                        "data": {
                          "$ref": "#/components/schemas/ExportPreview"
                        }
                      }
                    },
                    {
                      "$ref": "#/components/schemas/UploadFailure"
                    }
                  ]
                },
                "example": {
                  "ok": true,
                  "data": {
                    "headers": [
                      "Barcode",
                      "Name",
                      "Qty",
                      "Fact"
                    ],
                    "targetColumn": 3,
                    "rows": [
                      {
                        "cells": [
                          "4780012345678",
                          "Mineral water 0.5 l",
                          "24",
                          ""
                        ],
                        "before": "",
                        "after": "7"
                      }
                    ],
                    "parsedCount": 1,
                    "warnings": []
                  }
                }
              }
            }
          },
          "400": {
            "description": "The multipart form could not be read.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.unreadable",
                    "message": "The file could not be read"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Not signed in.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "auth.required",
                    "message": "Access denied"
                  }
                }
              }
            }
          },
          "403": {
            "description": "A counter login (`org_counter`) cannot upload (`auth.forbidden`), and an `org_admin` whose email is not verified yet uploads nothing (`upload.verify_first`); nothing from another site's page is read (`request.cross_site`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "auth.forbidden",
                    "message": "Access denied"
                  }
                }
              }
            }
          },
          "408": {
            "description": "The body fell behind its pace (100 KB/s after the first 15 seconds; a small file's deadline is those 15 seconds plus its size at that pace) or was still arriving after 60 seconds: it is dropped, the place freed, and it counts as a slow upload of the person, the organization and the network.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.too_slow",
                    "message": "The file uploaded too slowly and was stopped. Check the connection and try again."
                  }
                }
              }
            }
          },
          "409": {
            "description": "This person, this organization or this network (an IPv4 address, an IPv6 /64) already has an upload in the web process (one at a time each); the body is not read. Another account's upload on the same network answers \"Another file is still uploading from this network\".",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.in_progress",
                    "message": "Another file of your organization is still uploading. Try again when it is done."
                  }
                }
              }
            }
          },
          "413": {
            "description": "No `Content-Length`, or the body is over 20 MB plus 1 MiB for the other fields.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.too_large",
                    "message": "The file is larger than 20 MB"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Three uploads of this person, this organization or this network were dropped as too slow in 15 minutes: it waits until that window ends (`Retry-After`, seconds); the body is not read.",
            "headers": {
              "Retry-After": {
                "description": "Seconds until an upload may take a place again.",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.too_slow_wait",
                    "message": "The last files uploaded too slowly. Try again in 15 minutes."
                  }
                }
              }
            }
          },
          "503": {
            "description": "Six uploads are already being read.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NestedError"
                },
                "example": {
                  "error": {
                    "code": "upload.busy",
                    "message": "Spreadsheets are busy, try again"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/healthz": {
      "get": {
        "tags": [
          "system"
        ],
        "summary": "Health",
        "operationId": "healthz",
        "description": "Liveness and database check for monitoring.",
        "x-auth": {
          "kind": "public",
          "summary": "Public: no login."
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                },
                "example": {
                  "status": "ok",
                  "db": true,
                  "release": "8e48c6a"
                }
              }
            }
          },
          "503": {
            "description": "The database does not answer.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                },
                "example": {
                  "status": "degraded",
                  "db": false,
                  "release": "8e48c6a"
                }
              }
            }
          }
        }
      }
    },
    "/sw-assets": {
      "get": {
        "tags": [
          "system"
        ],
        "summary": "Service worker assets",
        "operationId": "sw_assets",
        "description": "Every script and style of the running build: the service worker caches them at install, so one visit is enough to work offline.",
        "x-auth": {
          "kind": "public",
          "summary": "Public: no login."
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "version": {
                      "type": "string",
                      "description": "Build id."
                    },
                    "assets": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                },
                "example": {
                  "version": "Xf3k2LmP9qR",
                  "assets": [
                    "/_next/static/chunks/main-1a2b3c.js",
                    "/_next/static/css/app-4d5e6f.css"
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "sessionCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "__Host-counter_session",
        "description": "httpOnly, Secure, SameSite=Lax login cookie that no other host can set: 30 days for admins, 14 for counters (a counter's login also ends with its join link, the session's auto-logout idle time or a revoked link)."
      }
    },
    "headers": {
      "ContentDisposition": {
        "description": "`attachment; filename=\"<ASCII name>\"; filename*=UTF-8''<name>`",
        "schema": {
          "type": "string"
        }
      }
    },
    "schemas": {
      "CountError": {
        "type": "object",
        "description": "Error body of the counter API (`/api/count/*`).",
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "string",
            "description": "Stable machine code, e.g. `session.closed`."
          },
          "message": {
            "type": "string",
            "description": "English text for logs; the phone shows its own."
          },
          "field": {
            "type": "string",
            "description": "The invalid input (validation errors)."
          }
        }
      },
      "NestedError": {
        "type": "object",
        "description": "Error body of the admin file endpoints, live session data and uploads.",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string",
                "description": "In the user's language where the user sees it."
              }
            }
          }
        }
      },
      "CatalogItem": {
        "type": "object",
        "description": "A product of the session's file, in short keys. Never the book quantity or the price.",
        "required": [
          "id",
          "b",
          "a",
          "n",
          "u"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "b": {
            "type": "string",
            "description": "Barcode (the first one of the cell)."
          },
          "a": {
            "type": "string",
            "description": "Article."
          },
          "n": {
            "type": "string",
            "description": "Name."
          },
          "u": {
            "type": "string",
            "description": "Unit."
          },
          "c": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Further codes; left out when none."
          }
        },
        "example": {
          "id": "0b9e8d7c-6a5f-4e3d-9c2b-1a0f9e8d7c6b",
          "b": "4780012345678",
          "a": "MW-05",
          "n": "Mineral water 0.5 l",
          "u": "pcs",
          "c": [
            "04780012345678"
          ]
        }
      },
      "Catalog": {
        "type": "object",
        "required": [
          "version",
          "items"
        ],
        "properties": {
          "version": {
            "type": "string",
            "description": "The ETag of this catalog, quotes included: `\"<session id>.<catalog version>\"`."
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CatalogItem"
            },
            "description": "In the file's row order."
          }
        }
      },
      "EntryInput": {
        "type": "object",
        "description": "One count as the phone stores and sends it. Either `itemId` or `code` is required.",
        "required": [
          "id",
          "itemId",
          "qtyGood",
          "qtyDamaged",
          "qtyReturned",
          "inputMethod",
          "clientCreatedAt"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Made by the phone: a retry with the same id is stored once."
          },
          "itemId": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ],
            "description": "The catalog item; null for a code the catalog does not know."
          },
          "code": {
            "type": "string",
            "maxLength": 200,
            "default": "",
            "description": "The scanned or typed code."
          },
          "unknownName": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 200
              },
              {
                "type": "null"
              }
            ],
            "description": "Name for an unknown code."
          },
          "zoneId": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "qtyGood": {
            "$ref": "#/components/schemas/Quantity"
          },
          "qtyDamaged": {
            "$ref": "#/components/schemas/Quantity"
          },
          "qtyReturned": {
            "$ref": "#/components/schemas/Quantity"
          },
          "damageReason": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 60
              },
              {
                "type": "null"
              }
            ]
          },
          "inputMethod": {
            "type": "string",
            "enum": [
              "camera",
              "bluetooth",
              "search",
              "voice",
              "plus_one",
              "manual"
            ]
          },
          "rawScan": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 500
              },
              {
                "type": "null"
              }
            ]
          },
          "recountEpoch": {
            "type": "integer",
            "minimum": 0,
            "maximum": 1000000,
            "default": 0,
            "description": "The recount the entry answers (from `/api/count/me`); 0 before any recount."
          },
          "clientCreatedAt": {
            "type": "string",
            "format": "date-time",
            "description": "With a UTC offset."
          }
        },
        "example": {
          "id": "2d4f6a8c-1e3b-4d5f-a7c9-e1b3d5f7a9c2",
          "itemId": "0b9e8d7c-6a5f-4e3d-9c2b-1a0f9e8d7c6b",
          "code": "4780012345678",
          "zoneId": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
          "qtyGood": "12",
          "qtyDamaged": "0",
          "qtyReturned": "0",
          "inputMethod": "camera",
          "rawScan": "4780012345678",
          "recountEpoch": 0,
          "clientCreatedAt": "2026-11-08T09:30:12.512+05:00"
        }
      },
      "Quantity": {
        "description": "A non-negative quantity: up to 6 whole and 3 fraction digits, `.` or `,` as the separator. Never blank: send `\"0\"` for none (a blank, `.` or `,` rejects the whole entry with reason `qty`).",
        "oneOf": [
          {
            "type": "string",
            "pattern": "^(\\d{1,6}([.,]\\d{0,3})?|[.,]\\d{1,3})$"
          },
          {
            "type": "number",
            "minimum": 0
          }
        ],
        "example": "12.5"
      },
      "EntriesResult": {
        "type": "object",
        "description": "Every entry of the batch lands in exactly one list.",
        "required": [
          "accepted",
          "late",
          "rejected"
        ],
        "properties": {
          "accepted": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Stored (also: stored before, a retry)."
          },
          "late": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "description": "The session is closed: waiting for an admin."
          },
          "rejected": {
            "type": "array",
            "description": "Never stored as sent; the phone stops resending them.",
            "items": {
              "type": "object",
              "required": [
                "id",
                "reason"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "description": "The entry's id as sent (up to 64 characters)."
                },
                "reason": {
                  "type": "string",
                  "enum": [
                    "invalid",
                    "qty",
                    "total_cap",
                    "late_full",
                    "full"
                  ],
                  "description": "`invalid`: bad shape; `qty`: bad or all-zero quantity for an unknown code; `total_cap`: the item's total would pass 9999999.999; `late_full`: 20 000 late entries already wait in this session, or 1 000 of this worker's; `full`: no room left on the disk, the session holds 10 000 + 20 per imported item entries (waiting and accepted late ones included), and an organization 1 GiB of them, or the service's storage is full."
                }
              }
            }
          }
        }
      },
      "OwnEntry": {
        "type": "object",
        "description": "One of the caller's own entries (the History tab).",
        "required": [
          "id",
          "itemId",
          "code",
          "name",
          "qtyGood",
          "qtyDamaged",
          "qtyReturned",
          "damageReason",
          "zoneId",
          "inputMethod",
          "createdAt",
          "deleted"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "itemId": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "code": {
            "type": "string",
            "description": "Barcode, else article; the unknown code for an unknown item."
          },
          "name": {
            "type": "string"
          },
          "qtyGood": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d+)?$",
            "description": "Decimal as a string."
          },
          "qtyDamaged": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d+)?$",
            "description": "Decimal as a string."
          },
          "qtyReturned": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d+)?$",
            "description": "Decimal as a string."
          },
          "damageReason": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "zoneId": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "inputMethod": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "The phone's time of the entry."
          },
          "deleted": {
            "type": "boolean",
            "description": "Soft-deleted (a correction)."
          },
          "recountEpoch": {
            "type": "integer"
          }
        }
      },
      "OwnTotal": {
        "type": "array",
        "description": "`[itemId, good, damaged, returned, entries]`: the caller's own totals of one item in the epoch in force.",
        "prefixItems": [
          {
            "type": "string",
            "format": "uuid"
          },
          {
            "type": "string",
            "pattern": "^\\d+(\\.\\d+)?$",
            "description": "Decimal as a string."
          },
          {
            "type": "string",
            "pattern": "^\\d+(\\.\\d+)?$",
            "description": "Decimal as a string."
          },
          {
            "type": "string",
            "pattern": "^\\d+(\\.\\d+)?$",
            "description": "Decimal as a string."
          },
          {
            "type": "integer"
          }
        ],
        "minItems": 5,
        "maxItems": 5,
        "example": [
          "0b9e8d7c-6a5f-4e3d-9c2b-1a0f9e8d7c6b",
          "24",
          "1",
          "0",
          3
        ]
      },
      "Settings": {
        "type": "object",
        "description": "Counting settings in force: code defaults, then the organization's, then the session's.",
        "properties": {
          "validity": {
            "description": "How long a join link works.",
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "mode": {
                    "const": "session"
                  }
                },
                "required": [
                  "mode"
                ]
              },
              {
                "type": "object",
                "properties": {
                  "mode": {
                    "const": "hours"
                  },
                  "hours": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 720
                  }
                },
                "required": [
                  "mode",
                  "hours"
                ]
              },
              {
                "type": "object",
                "properties": {
                  "mode": {
                    "const": "days"
                  },
                  "days": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 365
                  }
                },
                "required": [
                  "mode",
                  "days"
                ]
              },
              {
                "type": "object",
                "properties": {
                  "mode": {
                    "const": "until"
                  },
                  "until": {
                    "type": "string",
                    "format": "date-time"
                  }
                },
                "required": [
                  "mode",
                  "until"
                ]
              }
            ]
          },
          "deviceBinding": {
            "type": "string",
            "enum": [
              "one",
              "multiple"
            ]
          },
          "maxUses": {
            "anyOf": [
              {
                "type": "integer",
                "minimum": 1,
                "maximum": 10000
              },
              {
                "type": "null"
              }
            ]
          },
          "autoLogoutHours": {
            "type": "integer",
            "enum": [
              0,
              1,
              8,
              24
            ],
            "description": "0: never."
          },
          "counterChoosesZone": {
            "type": "boolean"
          },
          "inputs": {
            "type": "object",
            "properties": {
              "camera": {
                "type": "boolean"
              },
              "bluetooth": {
                "type": "boolean"
              },
              "plusOne": {
                "type": "boolean"
              },
              "search": {
                "type": "boolean"
              }
            }
          },
          "showOwnTotal": {
            "type": "boolean"
          },
          "damageReasons": {
            "type": "object",
            "properties": {
              "enabled": {
                "type": "boolean"
              },
              "list": {
                "type": "array",
                "maxItems": 30,
                "items": {
                  "type": "string",
                  "maxLength": 60
                }
              }
            }
          },
          "duplicateGuardMs": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000
          },
          "sounds": {
            "type": "boolean"
          },
          "scanner": {
            "type": "object",
            "properties": {
              "maxInterKeyMs": {
                "type": "integer",
                "minimum": 5,
                "maximum": 200
              },
              "minLength": {
                "type": "integer",
                "minimum": 1,
                "maximum": 64
              },
              "suffix": {
                "type": "string",
                "enum": [
                  "enter",
                  "tab",
                  "timeout"
                ]
              }
            }
          }
        },
        "example": {
          "validity": {
            "mode": "session"
          },
          "deviceBinding": "one",
          "maxUses": null,
          "autoLogoutHours": 0,
          "counterChoosesZone": true,
          "inputs": {
            "camera": true,
            "bluetooth": true,
            "plusOne": true,
            "search": true
          },
          "showOwnTotal": true,
          "damageReasons": {
            "enabled": false,
            "list": [
              "Broken",
              "Expired",
              "Damaged package",
              "Other"
            ]
          },
          "duplicateGuardMs": 800,
          "sounds": true,
          "scanner": {
            "maxInterKeyMs": 35,
            "minLength": 4,
            "suffix": "enter"
          }
        }
      },
      "CountMe": {
        "type": "object",
        "description": "Everything the counter screen needs; never book quantities, prices or other people's data.",
        "required": [
          "user",
          "session",
          "store",
          "org",
          "settings",
          "zones",
          "zoneId",
          "tokenExpiresAt",
          "release",
          "recounts",
          "recountTasks"
        ],
        "properties": {
          "user": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": "string"
              }
            }
          },
          "session": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": "string"
              },
              "status": {
                "type": "string",
                "enum": [
                  "draft",
                  "open",
                  "locked",
                  "closed"
                ]
              },
              "itemCount": {
                "type": "integer"
              },
              "catalogVersion": {
                "type": "integer",
                "description": "Goes up when an admin attaches an unknown code to an item of the session (a new alternate code); a recount does not change it."
              }
            }
          },
          "store": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              }
            }
          },
          "org": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "accentColor": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            }
          },
          "settings": {
            "$ref": "#/components/schemas/Settings"
          },
          "zones": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "name": {
                  "type": "string"
                }
              }
            }
          },
          "zoneId": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ],
            "description": "The caller's zone."
          },
          "tokenExpiresAt": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ],
            "description": "End of the join link."
          },
          "release": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "description": "Short commit of the running server (reload hint)."
          },
          "recounts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RecountMark"
            }
          },
          "recountTasks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RecountTask"
            },
            "description": "Items sent back to this counter."
          }
        },
        "example": {
          "user": {
            "id": "5c6d7e8f-9a0b-4c1d-8e2f-3a4b5c6d7e8f",
            "name": "Counter 3"
          },
          "session": {
            "id": "6f1c2a7e-3b4d-4e5f-8a9b-0c1d2e3f4a5b",
            "name": "November count",
            "status": "open",
            "itemCount": 1840,
            "catalogVersion": 2
          },
          "store": {
            "name": "Main store"
          },
          "org": {
            "name": "Example Retail",
            "accentColor": "#ff3621"
          },
          "settings": {
            "validity": {
              "mode": "session"
            },
            "deviceBinding": "one",
            "maxUses": null,
            "autoLogoutHours": 0,
            "counterChoosesZone": true,
            "inputs": {
              "camera": true,
              "bluetooth": true,
              "plusOne": true,
              "search": true
            },
            "showOwnTotal": true,
            "damageReasons": {
              "enabled": false,
              "list": [
                "Broken",
                "Expired",
                "Damaged package",
                "Other"
              ]
            },
            "duplicateGuardMs": 800,
            "sounds": true,
            "scanner": {
              "maxInterKeyMs": 35,
              "minLength": 4,
              "suffix": "enter"
            }
          },
          "zones": [
            {
              "id": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
              "name": "Hall A"
            }
          ],
          "zoneId": "9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d",
          "tokenExpiresAt": null,
          "release": "8e48c6a",
          "recounts": [
            {
              "itemId": "0b9e8d7c-6a5f-4e3d-9c2b-1a0f9e8d7c6b",
              "epoch": 1,
              "counted": 0,
              "open": true
            }
          ],
          "recountTasks": [
            {
              "id": "0b9e8d7c-6a5f-4e3d-9c2b-1a0f9e8d7c6b",
              "b": "4780012345678",
              "a": "MW-05",
              "n": "Mineral water 0.5 l",
              "u": "pcs",
              "epoch": 1
            }
          ]
        }
      },
      "RecountMark": {
        "type": "object",
        "description": "`epoch`: the newest recount asked for; `counted`: the epoch in force (older entries are out of the total); `open`: the recount still waits for a new entry.",
        "required": [
          "itemId",
          "epoch",
          "counted",
          "open"
        ],
        "properties": {
          "itemId": {
            "type": "string",
            "format": "uuid"
          },
          "epoch": {
            "type": "integer"
          },
          "counted": {
            "type": "integer"
          },
          "open": {
            "type": "boolean"
          }
        }
      },
      "RecountTask": {
        "description": "A product the admin sent back to this counter.",
        "allOf": [
          {
            "$ref": "#/components/schemas/CatalogItem"
          },
          {
            "type": "object",
            "required": [
              "epoch"
            ],
            "properties": {
              "epoch": {
                "type": "integer"
              }
            }
          }
        ]
      },
      "SessionStats": {
        "type": "object",
        "properties": {
          "total": {
            "type": "integer",
            "description": "Items in the session."
          },
          "counted": {
            "type": "integer"
          },
          "diffCount": {
            "type": "integer",
            "description": "Counted items whose good quantity differs from the book."
          },
          "diffSum": {
            "type": "string",
            "pattern": "^-?\\d+(\\.\\d+)?$",
            "description": "Value of the differences (book price), may be negative."
          },
          "uncountedSum": {
            "type": "string",
            "pattern": "^-?\\d+(\\.\\d+)?$",
            "description": "Book value of the items nobody counted yet."
          },
          "damaged": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d+)?$",
            "description": "Decimal as a string."
          },
          "returned": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d+)?$",
            "description": "Decimal as a string."
          },
          "unknown": {
            "type": "integer",
            "description": "Distinct codes the catalog does not know."
          },
          "recount": {
            "type": "integer",
            "description": "Items waiting for a recount."
          },
          "byZone": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "anyOf": [
                    {
                      "type": "string",
                      "format": "uuid"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "name": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "items": {
                  "type": "integer"
                },
                "entries": {
                  "type": "integer"
                }
              }
            }
          },
          "byCounter": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "name": {
                  "type": "string"
                },
                "items": {
                  "type": "integer"
                },
                "entries": {
                  "type": "integer"
                },
                "lastAt": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ],
                  "description": "Timestamp text such as `2026-11-08 04:30:12.512+00` (a space instead of `T`, a short offset)."
                }
              }
            }
          }
        }
      },
      "ActivityRow": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "at": {
            "type": "string",
            "description": "Timestamp text such as `2026-11-08 04:30:12.512+00` (a space instead of `T`, a short offset)."
          },
          "counter": {
            "type": "string",
            "description": "The counter's name."
          },
          "zone": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "itemName": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "code": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "good": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d+)?$",
            "description": "Decimal as a string."
          },
          "damaged": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d+)?$",
            "description": "Decimal as a string."
          },
          "returned": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d+)?$",
            "description": "Decimal as a string."
          },
          "method": {
            "type": "string",
            "description": "Input method."
          },
          "deleted": {
            "type": "boolean"
          }
        }
      },
      "EntryEvent": {
        "type": "object",
        "description": "`data` of an `entry` event: one new (`entry`) or changed (`entry_update`, e.g. deleted) entry.",
        "required": [
          "type",
          "id",
          "item_id",
          "user_id"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "entry",
              "entry_update"
            ]
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "item_id": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "user_id": {
            "type": "string",
            "format": "uuid"
          }
        },
        "example": {
          "type": "entry",
          "id": "2d4f6a8c-1e3b-4d5f-a7c9-e1b3d5f7a9c2",
          "item_id": "0b9e8d7c-6a5f-4e3d-9c2b-1a0f9e8d7c6b",
          "user_id": "5c6d7e8f-9a0b-4c1d-8e2f-3a4b5c6d7e8f"
        }
      },
      "Health": {
        "type": "object",
        "required": [
          "status",
          "db",
          "release"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ok",
              "degraded"
            ]
          },
          "db": {
            "type": "boolean",
            "description": "The database answers."
          },
          "release": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "description": "Short commit of the running release."
          }
        }
      },
      "UploadFailure": {
        "type": "object",
        "description": "A refused upload: the message is in the user's language, `field` names the form input at fault.",
        "required": [
          "ok",
          "error"
        ],
        "properties": {
          "ok": {
            "const": false
          },
          "error": {
            "type": "string"
          },
          "field": {
            "type": "string"
          }
        },
        "example": {
          "ok": false,
          "error": "Required",
          "field": "file"
        }
      },
      "ParseWarning": {
        "type": "object",
        "required": [
          "code"
        ],
        "properties": {
          "code": {
            "type": "string",
            "enum": [
              "invalid_qty",
              "invalid_price",
              "qty_range",
              "price_range",
              "ambiguous_marks",
              "scientific_barcode",
              "invalid_barcode",
              "mapped_column_missing",
              "no_rows"
            ]
          },
          "row": {
            "type": "integer",
            "description": "1-based sheet row."
          },
          "text": {
            "type": "string"
          }
        }
      },
      "ExcludedRow": {
        "type": "object",
        "required": [
          "rowIndex",
          "reason",
          "text"
        ],
        "properties": {
          "rowIndex": {
            "type": "integer"
          },
          "reason": {
            "type": "string",
            "enum": [
              "summary",
              "group",
              "numbering",
              "no_id"
            ]
          },
          "text": {
            "type": "string"
          }
        }
      },
      "ImportPreview": {
        "type": "object",
        "description": "How the file will be read: the template, the header, a sample and what will be left out.",
        "properties": {
          "templateId": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ],
            "description": "Null: no stored template fits, the default synonyms read it."
          },
          "templateName": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "sheetName": {
            "type": "string"
          },
          "headerRow": {
            "type": "integer",
            "description": "1-based row of the last header row."
          },
          "headers": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "columns": {
            "type": "object",
            "additionalProperties": {
              "type": "integer"
            },
            "description": "0-based column per field: barcode, article, name, unit, book_qty, fact_qty, price."
          },
          "factAppended": {
            "type": "boolean",
            "description": "The file has no fact column: the export adds one."
          },
          "count": {
            "type": "integer",
            "description": "Items that will be imported."
          },
          "sample": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "rowIndex": {
                  "type": "integer"
                },
                "barcode": {
                  "type": "string"
                },
                "article": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "unit": {
                  "type": "string"
                },
                "book": {
                  "type": "string"
                },
                "price": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ParseWarning"
            },
            "maxItems": 20
          },
          "warningCount": {
            "type": "integer"
          },
          "excluded": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ExcludedRow"
            },
            "maxItems": 20
          },
          "excludedCount": {
            "type": "integer"
          },
          "duplicates": {
            "type": "integer"
          }
        }
      },
      "SampleAnalysis": {
        "type": "object",
        "description": "What a sample file holds, for the template builder.",
        "properties": {
          "fileName": {
            "type": "string"
          },
          "sheetNames": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sheetName": {
            "type": "string"
          },
          "headerRow": {
            "type": "integer"
          },
          "headers": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "columns": {
            "type": "object",
            "additionalProperties": {
              "type": "integer"
            }
          },
          "mapping": {
            "type": "object",
            "description": "Field → header key the builder pre-selects (`barcode`, `article`, `name`, `unit`, `book_qty`, `fact_qty`, `price`).",
            "additionalProperties": {
              "type": "string"
            }
          },
          "previewRows": {
            "type": "array",
            "items": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      },
      "ExportPreview": {
        "type": "object",
        "description": "The sample exported with made-up counts: the fact column before and after.",
        "properties": {
          "headers": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "targetColumn": {
            "type": "integer",
            "description": "0-based column the counts go to."
          },
          "rows": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "cells": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "before": {
                  "type": "string"
                },
                "after": {
                  "type": "string"
                }
              }
            }
          },
          "parsedCount": {
            "type": "integer"
          },
          "warnings": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ParseWarning"
            }
          }
        }
      }
    },
    "responses": {
      "CountUnauthorized": {
        "description": "Not signed in, or the login has ended.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/CountError"
            },
            "example": {
              "code": "auth.required",
              "message": "unauthorized"
            }
          }
        }
      },
      "CountForbidden": {
        "description": "Signed in, but not as a counter of an active session; or a write came from another site's page, a sibling `*.databek.com` host included (`request.cross_site`).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/CountError"
            },
            "example": {
              "code": "auth.forbidden",
              "message": "forbidden"
            }
          }
        }
      },
      "CountServerError": {
        "description": "Unexpected error; the id in the message is in the server log.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/CountError"
            },
            "example": {
              "code": "server.error",
              "message": "Unexpected error (1a2b3c4d)"
            }
          }
        }
      },
      "AdminUnauthorized": {
        "description": "Not signed in.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/NestedError"
            },
            "example": {
              "error": {
                "code": "auth.required",
                "message": "unauthorized"
              }
            }
          }
        }
      },
      "AdminForbidden": {
        "description": "Not an admin of an organization.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/NestedError"
            },
            "example": {
              "error": {
                "code": "auth.forbidden",
                "message": "forbidden"
              }
            }
          }
        }
      },
      "SessionNotFound": {
        "description": "No such session in the organization.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/NestedError"
            },
            "example": {
              "error": {
                "code": "session.not_found",
                "message": "Session not found"
              }
            }
          }
        }
      },
      "SheetFailed": {
        "description": "The spreadsheet worker could not do the job (busy, file too complex, unreadable).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/NestedError"
            },
            "example": {
              "error": {
                "code": "sheet.failed",
                "message": "The file is too complex to read"
              }
            }
          }
        }
      },
      "DownloadLimited": {
        "description": "Over 30 downloads in an hour.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/NestedError"
            },
            "example": {
              "error": {
                "code": "rate_limited",
                "message": "Too many requests, try again later"
              }
            }
          }
        }
      }
    }
  }
}
