openapi: 3.1.0
info:
  title: RepairSpots Open API
  version: 1.0.0
  description: |
    Read and write your own shop's repairs, customers and inventory from your
    integrations and AI assistants.

    **AI assistants.** Read `GET /guide` (the rules for reading and changing
    the data) and `GET /reference` (the shop's statuses, repair types, other
    types and technicians) first, instead of working them out from the data.

    **Authentication.** Create a key in the app (Settings → API keys); an owner
    or store admin of the shop approves it with their admin PIN. Send it on
    every request as `Authorization: Bearer rsk_live_...`. A key belongs
    to one shop and only ever acts on that shop. Each key has scopes
    (`repairs:read`, `repairs:write`, `customers:read`, `customers:write`,
    `inventory:read`, `inventory:write`); a route needing a scope the key
    lacks answers `403 insufficient_scope`.

    **Plans.** The Open API is included on every paid plan. Free shops and
    shops on a trial (of any plan) have none: `403 plan_not_included`, with
    `details.reason` `free` or `trial`. Starter (legacy Manager) has 100
    requests in total, once, and 1 key per shop; Essential (legacy Basic,
    Deluxe) 1 key and Pro (legacy Premium, Special) 5 keys per shop, both with
    the daily fair use limit below. On Starter, API calls, AI assistant (MCP)
    calls and webhook events each take one of the 100 (`GET /shop` and calls
    answered 429 or 5xx don't), counted responses carry `X-Usage-Limit` and
    `X-Usage-Remaining`, and once they're used up every route but `GET /shop`
    answers `403 usage_limit_reached`. A shop holding more keys than its plan
    allows (after a downgrade) gets `403 key_limit_exceeded` on every route
    but `GET /shop` until a shop admin revokes the extra keys. A suspended
    shop gets `403 shop_suspended`. `GET /shop` always answers, so you can
    show the shop's plan, its usage and an upgrade button.

    **Rate limits.** Each key has its own allowance of reads, writes and bulk
    calls per minute and requests per rolling 24 hours, the same on every
    paid plan. The requests per 24 hours are the fair use limit for Essential
    and Pro; RepairSpots can change it. Every response carries
    `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` (seconds
    until full) and `X-RateLimit-Bucket`. Over the limit you get
    `429 rate_limited` with `Retry-After` (seconds).

    **Paging.** Lists return `{ items, nextCursor, hasMore }`. Pass
    `nextCursor` back as `cursor` until `hasMore` is false. Without
    `changed_since`, lists are newest first and leave out archived records.
    With `changed_since`, they return records changed at or after that time,
    oldest change first, archived included: store the `updatedAt` of the last
    record you saw and pass it next time to sync changes. `GET /repair-types`
    is the exception: a shop has a handful, so it returns them all as
    `{ items }`, unpaged.

    **Filters.** Each list documents the filters it takes, and they combine
    (all must match). A list refuses any other query parameter with
    `422 validation` (`details.field` names it, `details.allowed` lists the
    accepted ones), so a typo never returns the whole list. Pass a parameter
    once; filters that take several values take them comma separated. A
    cursor only continues the list with the same filters.

    **Writes.** Writes follow the same rules and send the same customer
    notifications as the app, and appear in the record's history in the app
    under the key's name. POSTs accept an `Idempotency-Key` header so a retry
    doesn't create a second record. A repair needs one of the shop's repair
    types (`repairTypeId`, from `GET /repair-types`).

    **Guardrails.** On top of the rate limits, each shop can make a limited
    number of new repairs, new customers, stock changes and bulk calls per
    hour and per day through the API (rolling windows, set by the plan; a
    shop in its first 30 days gets a fraction of them). Only successful
    changes count. Over a limit you get `429 quota_exceeded` with
    `Retry-After` and `details.resetsAt`. The same create within a few
    minutes (a customer with the same phone, or without one the same email;
    a repair for the same customer and device) answers `200` with the record
    that already exists and a `Duplicate-Of` header, instead of making a
    second one. The exact same GET (path and query) repeated many times in a
    minute answers `429 repeated_request`: reuse the response you have. A key
    that suddenly goes far above its usual volume, or keeps hitting these
    limits, is paused (`403 key_paused`, `details.reason` `unusual_activity`
    or `repeated_limits`); the shop is emailed, and an owner or store admin
    approves resuming it in the app with their admin PIN. RepairSpots can
    pause all API changes for a while: writes then answer
    `503 writes_paused` and reads keep working.

    **Errors.** Every error has the same shape:
    `{ "error": { "code": "...", "message": "...", "details": { ... } } }`.
    Codes are listed on the `Error` schema.

    Every call, including refused ones, is recorded in the shop's API activity
    log (Settings → API keys → Activity) for 90 days.
servers:
  # The web hosts proxy /api/* to the API (the same way the apps reach /api/v3).
  - url: https://web.spotspos.com/api/open/v1
    description: Production
security:
  - apiKey: []
tags:
  - name: Shop
  - name: Repairs
  - name: Customers
  - name: Inventory

paths:
  /shop:
    get:
      tags: [ Shop ]
      operationId: getShop
      summary: The key's shop, its plan, whether it has API access, and its usage
      description: |
        Needs no scope and doesn't count toward Starter's 100 requests. Answers
        even when the shop has no paid plan, is on a trial or suspended, holds
        more keys than its plan allows, or has used up Starter's requests:
        `reason` says which, and `actionRequired` is `revoke_keys` when a shop
        admin must revoke keys before the API works again.
      responses:
        "200":
          description: The shop
          headers:
            X-RateLimit-Limit: { $ref: "#/components/headers/RateLimitLimit" }
            X-RateLimit-Remaining: { $ref: "#/components/headers/RateLimitRemaining" }
            X-RateLimit-Reset: { $ref: "#/components/headers/RateLimitReset" }
            X-RateLimit-Bucket: { $ref: "#/components/headers/RateLimitBucket" }
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Shop" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/RateLimited" }

  /me:
    get:
      tags: [ Shop ]
      operationId: getMe
      summary: The key making the request
      description: Lets an integration check its key works.
      responses:
        "200":
          description: The key
          content:
            application/json:
              schema:
                type: object
                required: [ key, shop ]
                properties:
                  key:
                    type: object
                    properties:
                      _id: { type: string }
                      name: { type: string }
                      prefix: { type: string, example: rsk_live_1a2b3c4d }
                      scopes: { type: array, items: { $ref: "#/components/schemas/Scope" } }
                      expiresAt: { type: string, format: date-time }
                      status: { type: string, enum: [ active, rotating ] }
                  shop: { type: string, description: The shop id }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "429": { $ref: "#/components/responses/RateLimited" }

  /reference:
    get:
      tags: [ Shop ]
      operationId: getReference
      summary: The shop's statuses, types and technicians, with what they mean
      description: |
        For AI assistants: call it once at the start of a conversation instead of
        paging through repairs to work out which statuses exist. Needs no scope
        of its own; each section is returned only when the key can read it:
        `repairStatuses`, `deviceTypes` and `technicians` with `repairs:read`,
        `repairTypes` with `repairs:read` or `repairs:write`, `itemTypes` with
        `inventory:read`. Built at most once an hour per shop (`generatedAt`),
        and not limited by `repeated_request`: for the repair types as they
        are right now, use `GET /repair-types`.
      responses:
        "200":
          description: The reference
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Reference" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "429": { $ref: "#/components/responses/RateLimited" }

  /guide:
    get:
      tags: [ Shop ]
      operationId: getGuide
      summary: The guide for AI assistants (markdown)
      description: |
        How to read and change this shop's data correctly: the statuses and what
        changing them tells the customer, what each field means, the filters that
        answer common questions in one call, and what the API can't do yet. Its
        version is the `Guide-Version` header and the `ETag`, and matches
        `guideVersion` in `GET /reference`; send `If-None-Match` to get
        `304 Not Modified` when it hasn't changed. Needs no scope, and not
        limited by `repeated_request`.
      responses:
        "200":
          description: The guide
          headers:
            Guide-Version:
              description: The guide's version
              schema: { type: string, example: 95efefc00b9a }
            ETag:
              description: The version, quoted
              schema: { type: string }
          content:
            text/markdown:
              schema: { type: string }
        "304":
          description: Unchanged since the version in `If-None-Match`
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "429": { $ref: "#/components/responses/RateLimited" }

  /repair-types:
    get:
      tags: [ Repairs ]
      operationId: listRepairTypes
      summary: List the shop's repair types
      description: |
        Scope: repairs:read or repairs:write (either is enough, so a key that
        only creates repairs can look up the id it must send).

        The shop's repair types (Phone, Tablet, Computer, ...), as set up in
        the app. `POST /repairs` needs one of these ids as `repairTypeId`, and
        the repair's `deviceType` is the type's name. They come in the app's
        order: the shop's most used first, then A to Z. Not paged: a shop has
        a handful, so every type is in `items`. Takes no query parameters
        (any is a `422 validation`). Cache the list rather than reading it
        before every create; the same read repeated in a minute gets
        `429 repeated_request`.
      responses:
        "200":
          description: Every repair type of the shop
          headers:
            X-RateLimit-Limit: { $ref: "#/components/headers/RateLimitLimit" }
            X-RateLimit-Remaining: { $ref: "#/components/headers/RateLimitRemaining" }
            X-RateLimit-Reset: { $ref: "#/components/headers/RateLimitReset" }
            X-RateLimit-Bucket: { $ref: "#/components/headers/RateLimitBucket" }
          content:
            application/json:
              schema: { $ref: "#/components/schemas/RepairTypeList" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "422": { $ref: "#/components/responses/Validation" }
        "429": { $ref: "#/components/responses/RateLimited" }

  /repairs:
    get:
      tags: [ Repairs ]
      operationId: listRepairs
      summary: List the shop's repairs
      description: "Scope: repairs:read."
      parameters:
        - { $ref: "#/components/parameters/limit" }
        - { $ref: "#/components/parameters/cursor" }
        - { $ref: "#/components/parameters/changedSince" }
        - name: closed
          in: query
          description: Only closed (true) or only open (false) repairs.
          schema: { type: boolean }
        - name: status
          in: query
          description: "Repairs in this status, matched exactly in any case. Several,
            comma separated: `Pending,Awaiting Parts`."
          schema: { type: string }
        - name: customer_id
          in: query
          description: The customer's repairs (`customer.id`).
          schema: { type: string }
        - name: technician_id
          in: query
          description: The repairs assigned to this technician (`technicianId`).
          schema: { type: string }
        - name: paid
          in: query
          description: Only paid (true) or only unpaid (false) repairs.
          schema: { type: boolean }
        - name: high_priority
          in: query
          description: Only high priority (true) or only normal (false) repairs.
          schema: { type: boolean }
        - name: search
          in: query
          description: "Up to 100 characters. Every word must appear in the repair number
            (`RS912` or `912`, matched exactly), the customer's name, the device
            or the IMEI. Any case."
          schema: { type: string, maxLength: 100 }
        - name: created_from
          in: query
          description: Repairs created (`createdAt`) at or after this time.
          schema: { type: string, format: date-time }
        - name: created_to
          in: query
          description: Repairs created (`createdAt`) at or before this time.
          schema: { type: string, format: date-time }
      responses:
        "200":
          description: A page of repairs
          headers:
            X-RateLimit-Limit: { $ref: "#/components/headers/RateLimitLimit" }
            X-RateLimit-Remaining: { $ref: "#/components/headers/RateLimitRemaining" }
            X-RateLimit-Reset: { $ref: "#/components/headers/RateLimitReset" }
            X-RateLimit-Bucket: { $ref: "#/components/headers/RateLimitBucket" }
          content:
            application/json:
              schema: { $ref: "#/components/schemas/RepairPage" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "422": { $ref: "#/components/responses/Validation" }
        "429": { $ref: "#/components/responses/RateLimited" }

    post:
      tags: [ Repairs ]
      operationId: createRepair
      summary: Create a repair
      description: |
        Scope: repairs:write. Same rules and side effects as creating a repair in
        the app: the next repair number, the customer's "repair created" text and
        email, and the shop's repair.created webhook. The repair's history shows
        the key's name as its author. It starts as `Pending`.

        **Repair type.** Every repair needs one of the shop's repair types:
        send `repairTypeId`, from `GET /repair-types`. The repair's
        `deviceType` is set to the type's name, as the app does.
        Integrations from before `repairTypeId` can send `deviceType` alone
        instead: the shop's repair type with that name (case and outer spaces
        aside; the first in `GET /repair-types` order if two share it) is
        used. With neither, with a `deviceType` that names none of the shop's
        types, or with an id that isn't one of them, the answer is
        `422 validation` with `details.field: "repairTypeId"`. With both,
        `repairTypeId` decides and `deviceType` is ignored. When the customer
        belongs to a labor group for that repair type, the repair gets that
        labor group, as in the app.

        **Lock code.** `lockCode` is the device's passcode or password, for the
        technician. It's saved exactly as sent and shows on the repair in the
        app, but it's never returned by the API, never sent in webhooks, and
        stored as `[redacted]` in the API activity log. Unlock patterns can't
        be sent.

        **Pricing.** `estimatePrice` and `laborPrice` each add a line to the
        repair, built exactly as the app builds them: the estimate is named
        "<device> <issue>" and the labor line "Labor Cost". Each is taxed by
        the shop's default tax group when the shop taxes estimates or labor;
        with a GST (tax-inclusive) group the tax is already inside the price.
        The repair's `price` is the total the customer pays: the lines, their
        tax and the labor. Inventory parts aren't supported in v1, and no stock
        changes.
      parameters:
        - { $ref: "#/components/parameters/idempotencyKey" }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/RepairCreate" }
      responses:
        "200":
          description: "The same repair (same customer and device) was created within the
            last few minutes: the existing one, nothing new made"
          headers:
            Duplicate-Of: { $ref: "#/components/headers/DuplicateOf" }
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Repair" }
        "201":
          description: The new repair
          headers:
            X-RateLimit-Limit: { $ref: "#/components/headers/RateLimitLimit" }
            X-RateLimit-Remaining: { $ref: "#/components/headers/RateLimitRemaining" }
            X-RateLimit-Reset: { $ref: "#/components/headers/RateLimitReset" }
            X-RateLimit-Bucket: { $ref: "#/components/headers/RateLimitBucket" }
            Idempotency-Replayed: { $ref: "#/components/headers/IdempotencyReplayed" }
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Repair" }
        "400": { $ref: "#/components/responses/BadBody" }
        "413": { $ref: "#/components/responses/BadBody" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "409": { $ref: "#/components/responses/Conflict" }
        "422": { $ref: "#/components/responses/Validation" }
        "429": { $ref: "#/components/responses/RateLimited" }
        "503": { $ref: "#/components/responses/WritesPaused" }

  /repairs/{id}:
    get:
      tags: [ Repairs ]
      operationId: getRepair
      summary: One repair
      description: "Scope: repairs:read. Find it by `id`, or by the repair number the
        shop sees (`RS912` or `912`)."
      parameters:
        - name: id
          in: path
          required: true
          description: "The repair's `id`, or its number: `RS912`, `912`."
          schema: { type: string }
      responses:
        "200":
          description: The repair
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Repair" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }
        "429": { $ref: "#/components/responses/RateLimited" }

  /repairs/{id}/status:
    patch:
      tags: [ Repairs ]
      operationId: updateRepairStatus
      summary: Change a repair's status
      description: |
        Scope: repairs:write. Same as changing the status in the app: the customer
        gets the status text and email (unless `notify` is false), the shop's
        repair.status_updated webhook fires, and the repair's history shows the
        key's name as who changed it.

        `status` is one of the app's 12 statuses, in any casing; it's stored
        exactly as the app stores it (`waiting on customer` becomes
        `Waiting on customer`). Anything else answers `422 validation` with
        `details.allowed` listing them. `In Progress`, `Awaiting Parts`,
        `Waiting on customer` and `Non Repairable` send their own customer
        message, the others a general one, and `Tech Damage` none. A status
        doesn't close the repair (`closed`) or mark it paid (`paid`): `Paid`
        is only a status.
      parameters:
        - { $ref: "#/components/parameters/id" }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/StatusChange" }
      responses:
        "200":
          description: The updated repair
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Repair" }
        "400": { $ref: "#/components/responses/BadBody" }
        "413": { $ref: "#/components/responses/BadBody" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }
        "422": { $ref: "#/components/responses/Validation" }
        "429": { $ref: "#/components/responses/RateLimited" }
        "503": { $ref: "#/components/responses/WritesPaused" }

  /customers:
    get:
      tags: [ Customers ]
      operationId: listCustomers
      summary: List the shop's customers
      description: "Scope: customers:read."
      parameters:
        - { $ref: "#/components/parameters/limit" }
        - { $ref: "#/components/parameters/cursor" }
        - { $ref: "#/components/parameters/changedSince" }
        - name: search
          in: query
          description: "Up to 100 characters. Every word must appear in the first or last
            name, the email or the phone, in any case. Phones match by their
            digits, whatever the formatting: `5550101234` finds `(555)
            010-1234`."
          schema: { type: string, maxLength: 100 }
      responses:
        "200":
          description: A page of customers
          headers:
            X-RateLimit-Limit: { $ref: "#/components/headers/RateLimitLimit" }
            X-RateLimit-Remaining: { $ref: "#/components/headers/RateLimitRemaining" }
            X-RateLimit-Reset: { $ref: "#/components/headers/RateLimitReset" }
            X-RateLimit-Bucket: { $ref: "#/components/headers/RateLimitBucket" }
          content:
            application/json:
              schema: { $ref: "#/components/schemas/CustomerPage" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "422": { $ref: "#/components/responses/Validation" }
        "429": { $ref: "#/components/responses/RateLimited" }

    post:
      tags: [ Customers ]
      operationId: createCustomer
      summary: Create a customer
      description: |
        Scope: customers:write. The plan's customer cap applies (403 plan_limit),
        and a customer of the shop with the same phone number is refused with
        409 conflict and details.existingCustomerId.
      parameters:
        - { $ref: "#/components/parameters/idempotencyKey" }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/CustomerCreate" }
      responses:
        "200":
          description: "The same customer (same phone, or without one the same email) was
            created within the last few minutes: the existing one, nothing new
            made"
          headers:
            Duplicate-Of: { $ref: "#/components/headers/DuplicateOf" }
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Customer" }
        "201":
          description: The new customer
          headers:
            X-RateLimit-Limit: { $ref: "#/components/headers/RateLimitLimit" }
            X-RateLimit-Remaining: { $ref: "#/components/headers/RateLimitRemaining" }
            X-RateLimit-Reset: { $ref: "#/components/headers/RateLimitReset" }
            X-RateLimit-Bucket: { $ref: "#/components/headers/RateLimitBucket" }
            Idempotency-Replayed: { $ref: "#/components/headers/IdempotencyReplayed" }
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Customer" }
        "400": { $ref: "#/components/responses/BadBody" }
        "413": { $ref: "#/components/responses/BadBody" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "409": { $ref: "#/components/responses/Conflict" }
        "422": { $ref: "#/components/responses/Validation" }
        "429": { $ref: "#/components/responses/RateLimited" }
        "503": { $ref: "#/components/responses/WritesPaused" }

  /customers/{id}:
    get:
      tags: [ Customers ]
      operationId: getCustomer
      summary: One customer
      description: "Scope: customers:read."
      parameters:
        - { $ref: "#/components/parameters/id" }
      responses:
        "200":
          description: The customer
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Customer" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }
        "429": { $ref: "#/components/responses/RateLimited" }

  /inventory/items:
    get:
      tags: [ Inventory ]
      operationId: listInventoryItems
      summary: List the shop's parts and accessories
      description: "Scope: inventory:read. Devices (serialized units) aren't included
        in v1."
      parameters:
        - { $ref: "#/components/parameters/limit" }
        - { $ref: "#/components/parameters/cursor" }
        - { $ref: "#/components/parameters/changedSince" }
        - name: search
          in: query
          description: Up to 100 characters. Every word must appear in the name, SKU or
            barcode, in any case.
          schema: { type: string, maxLength: 100 }
        - name: type
          in: query
          description: "Items of this type (the shop's own categories, e.g. `Part`),
            matched exactly in any case. Several, comma separated."
          schema: { type: string }
        - name: low_stock
          in: query
          description: "true: items whose stock is at or under their `lowStockThreshold`,
            as the app's low stock list counts them. false: every other item,
            including items without a threshold."
          schema: { type: boolean }
      responses:
        "200":
          description: A page of items
          headers:
            X-RateLimit-Limit: { $ref: "#/components/headers/RateLimitLimit" }
            X-RateLimit-Remaining: { $ref: "#/components/headers/RateLimitRemaining" }
            X-RateLimit-Reset: { $ref: "#/components/headers/RateLimitReset" }
            X-RateLimit-Bucket: { $ref: "#/components/headers/RateLimitBucket" }
          content:
            application/json:
              schema: { $ref: "#/components/schemas/ItemPage" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "422": { $ref: "#/components/responses/Validation" }
        "429": { $ref: "#/components/responses/RateLimited" }

  /inventory/items/{id}:
    patch:
      tags: [ Inventory ]
      operationId: updateInventoryItemStock
      summary: Set or adjust an item's stock
      description: |
        Scope: inventory:write. Send `stock` to set it to a number, or `adjust` to
        add or remove units; not both. Writes the item's stock history like the
        app. Serialized items (stock tracked per unit) are refused.
      parameters:
        - { $ref: "#/components/parameters/id" }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/StockChange" }
      responses:
        "200":
          description: The updated item
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Item" }
        "400": { $ref: "#/components/responses/BadBody" }
        "413": { $ref: "#/components/responses/BadBody" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/NotFound" }
        "422": { $ref: "#/components/responses/Validation" }
        "429": { $ref: "#/components/responses/RateLimited" }
        "503": { $ref: "#/components/responses/WritesPaused" }

  /inventory/items/bulk:
    post:
      tags: [ Inventory ]
      operationId: bulkUpdateInventoryStock
      summary: Set or adjust the stock of up to 100 items
      description: |
        Scope: inventory:write. Counts as a bulk call for rate limits. Every item
        is checked first; if any is invalid, the response is 422 with
        details.items listing them, and no stock changes.
      parameters:
        - { $ref: "#/components/parameters/idempotencyKey" }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/BulkStockChange" }
      responses:
        "200":
          description: The updated items
          headers:
            X-RateLimit-Limit: { $ref: "#/components/headers/RateLimitLimit" }
            X-RateLimit-Remaining: { $ref: "#/components/headers/RateLimitRemaining" }
            X-RateLimit-Reset: { $ref: "#/components/headers/RateLimitReset" }
            X-RateLimit-Bucket: { $ref: "#/components/headers/RateLimitBucket" }
            Idempotency-Replayed: { $ref: "#/components/headers/IdempotencyReplayed" }
          content:
            application/json:
              schema:
                type: object
                required: [ items ]
                properties:
                  items: { type: array, items: { $ref: "#/components/schemas/Item" } }
        "400": { $ref: "#/components/responses/BadBody" }
        "413": { $ref: "#/components/responses/BadBody" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "409": { $ref: "#/components/responses/Conflict" }
        "422": { $ref: "#/components/responses/Validation" }
        "429": { $ref: "#/components/responses/RateLimited" }
        "503": { $ref: "#/components/responses/WritesPaused" }

components:
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: "An Open API key: rsk_live_..."

  parameters:
    id:
      name: id
      in: path
      required: true
      schema: { type: string }
    idempotencyKey:
      name: Idempotency-Key
      in: header
      description: |
        Optional, up to 255 characters. Retrying with the same key within 24 hours
        returns the first response (with Idempotency-Replayed: true) instead of
        creating a second record. The same key with a different body is refused
        (422); while the first request is still running, 409 conflict.
      schema: { type: string, maxLength: 255 }
    limit:
      name: limit
      in: query
      description: Page size.
      schema: { type: integer, minimum: 1, maximum: 100, default: 50 }
    cursor:
      name: cursor
      in: query
      description: The `nextCursor` of the previous page. Bound to this list and its
        filters.
      schema: { type: string }
    changedSince:
      name: changed_since
      in: query
      description: Only records changed at or after this time, oldest change first,
        archived included.
      schema: { type: string, format: date-time }

  headers:
    RateLimitLimit:
      {
        schema: { type: integer },
        description: The allowance of the bucket closest to empty
      }
    RateLimitRemaining: { schema: { type: integer }, description: Requests left in that bucket }
    RateLimitReset:
      {
        schema: { type: integer },
        description: Seconds until that bucket is full again
      }
    RateLimitBucket:
      description: Which allowance the other three headers describe
      schema:
        {
          type: string,
          enum: [ reads-per-minute, writes-per-minute, bulk-per-minute, requests-per-day ]
        }
    IdempotencyReplayed:
      description: "true when this is the stored response of an earlier request with
        the same Idempotency-Key"
      schema: { type: string, enum: [ "true" ] }
    DuplicateOf:
      description: "The id of the record that already exists: the same create arrived
        within a few minutes, so nothing new was made"
      schema: { type: string }
    UsageLimit:
      description: "Starter only: the shop's requests in total (100). On every counted
        response."
      schema: { type: integer }
    UsageRemaining:
      description: "Starter only: how many of them are left."
      schema: { type: integer }

  responses:
    Unauthorized:
      description: "Missing, invalid, expired or revoked key (invalid_key,
        key_expired, key_revoked)"
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    Forbidden:
      description: "Not allowed (insufficient_scope, plan_not_included,
        shop_suspended, key_paused, api_access_disabled), or a plan limit is
        reached: plan_limit, usage_limit_reached (Starter's 100 requests are
        used up; details.used, details.limit, details.upgradeUrl) or
        key_limit_exceeded (more keys than the plan allows; details.keys,
        details.limit, details.action revoke_keys). plan_not_included has
        details.reason: free or trial (or plan, for a plan that leaves the API
        out). key_paused has details.reason: unusual_activity or repeated_limits
        when the guardrails paused the key (an owner or store admin resumes it
        in the app with their admin PIN)."
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    NotFound:
      description: "No such record in this shop (not_found)"
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    Validation:
      description: "A parameter or body field isn't valid, or a list got a query
        parameter it doesn't take (validation); details.field names it,
        details.allowed lists a list's parameters, and details.items lists bulk
        items that can't be changed"
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    BadBody:
      description: "The body isn't valid JSON (400), or is over 100 KB (413): validation"
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    Conflict:
      description: "Already exists, or the same Idempotency-Key is still in progress
        (conflict). details.existingCustomerId names a customer with the same
        phone."
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    RateLimited:
      description: "Over the rate limit (rate_limited; details.reason is
        failed_attempts when too many invalid keys came from your address), over
        a shop quota (quota_exceeded: details.quota, max, retryAfter, resetsAt,
        newShop; or details.requested when one call asks for more than the whole
        allowance), or the same GET repeated too often (repeated_request)."
      headers:
        Retry-After: { schema: { type: integer }, description: Seconds to wait }
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    WritesPaused:
      description: "RepairSpots has paused all API changes for now (writes_paused;
        details.reason). Reads keep working."
      headers:
        Retry-After: { schema: { type: integer }, description: Seconds to wait }
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }

  schemas:
    Scope:
      type: string
      enum:
        [
          "repairs:read",
          "repairs:write",
          "customers:read",
          "customers:write",
          "inventory:read",
          "inventory:write"
        ]

    Error:
      type: object
      required: [ error ]
      properties:
        error:
          type: object
          required: [ code, message ]
          properties:
            code:
              type: string
              enum:
                - invalid_key
                - key_expired
                - key_revoked
                - key_paused
                - api_access_disabled
                - plan_not_included
                - shop_suspended
                - insufficient_scope
                - rate_limited
                - rate_limit_unavailable
                - not_found
                - validation
                - conflict
                - plan_limit
                - quota_exceeded
                - repeated_request
                - writes_paused
                - internal
            message: { type: string }
            details:
              type: object
              description: "Depends on the code: e.g. scope, upgradeUrl and plan, limit and
                retryAfter, field; quota, max, retryAfter, resetsAt and newShop
                (quota_exceeded); reason (key_paused, writes_paused)."
              additionalProperties: true

    Shop:
      type: object
      required:
        [
          id,
          name,
          status,
          plan,
          apiAccess,
          reason,
          upgradeUrl,
          keys,
          usage,
          actionRequired
        ]
      properties:
        id: { type: string }
        name: { type: [ string, "null" ] }
        status: { type: string, enum: [ active, suspended ] }
        plan:
          type: object
          properties:
            name: { type: string, description: The plan's name, or Free }
            legacy: { type: boolean, description: True for plans from before the current catalog }
        apiAccess: { type: boolean }
        reason:
          type: [ string, "null" ]
          enum: [ free, plan, trial, suspended, key_limit, usage_limit, null ]
          description: "Why apiAccess is false: no paid plan (free, or plan for a plan
            that leaves the API out), a trial, suspended, more keys than the
            plan allows, or Starter's 100 requests used up"
        upgradeUrl: { type: string, format: uri }
        keys:
          type: object
          description: The shop's keys against its plan's limit
          properties:
            used:
              {
                type: integer,
                description: "Keys that count: not revoked, expired or rotated away"
              }
            limit:
              {
                type: [ integer, "null" ],
                description: "Keys the plan allows (Starter and Essential 1, Pro 5); 0 without a
                  paid plan"
              }
            employeeLimit:
              {
                type: [ integer, "null" ],
                description: How many of them may be employees' own keys
              }
            overLimit:
              {
                type: boolean,
                description: "More keys than the plan allows (after a downgrade): every route
                  but GET /shop answers key_limit_exceeded"
              }
            toRevoke:
              {
                type: integer,
                description: "How many keys a shop admin must revoke before the API works again
                  (0 within the limit)"
              }
        usage:
          description: "Starter: its 100 requests. Essential and Pro: this key's last 24
            hours against the fair use limit. null without a paid plan."
          oneOf:
            - type: "null"
            - type: object
              required: [ kind, used, limit, remaining ]
              properties:
                kind: { type: string, enum: [ total ] }
                used: { type: integer }
                limit: { type: integer, example: 100 }
                remaining: { type: integer }
            - type: object
              required: [ kind, limit, keys ]
              properties:
                kind: { type: string, enum: [ daily ] }
                limit: { type: integer, example: 10000 }
                keys:
                  type: array
                  items:
                    type: object
                    properties:
                      id: { type: string }
                      prefix: { type: [ string, "null" ] }
                      used: { type: [ integer, "null" ] }
                      remaining: { type: [ integer, "null" ] }
        actionRequired:
          type: [ string, "null" ]
          enum: [ revoke_keys, null ]
          description: "revoke_keys: a shop admin must revoke the extra keys in Settings →
            API keys before the API works again"

    Reference:
      type: object
      required: [ shop, guideVersion, generatedAt ]
      properties:
        shop:
          type: object
          properties:
            id: { type: string }
            name: { type: [ string, "null" ] }
            timezone:
              {
                type: [ string, "null" ],
                description: "The shop's timezone (IANA, e.g. America/Chicago). Show dates in
                  it."
              }
            language: { type: string, description: "The shop's language, e.g. en or es" }
            currency:
              {
                type: [ string, "null" ],
                description: "The shop's currency, e.g. USD. Every amount is in it."
              }
        guideVersion:
          {
            type: string,
            description: "The current version of `GET /guide` (its Guide-Version)"
          }
        generatedAt:
          {
            type: string,
            format: date-time,
            description: When this data was built. It's rebuilt at most once an hour.
          }
        repairStatuses:
          type: object
          description: With `repairs:read`.
          properties:
            statuses:
              type: array
              description: The 12 statuses, in the app's order
              items:
                type: object
                properties:
                  value: { type: string, description: Exactly as stored }
                  stage: { type: string, enum: [ open, waiting, ready, done, cancelled ] }
                  customerMessage:
                    type: string
                    enum: [ own, general, none ]
                    description: "What changing to this status sends the customer, unless `notify`
                      is false: its own text and email, the general one, or
                      none"
                  internal:
                    {
                      type: boolean,
                      description: "Never told to the customer (`Tech Damage`: the shop damaged the
                        device)"
                    }
                  count:
                    {
                      type: integer,
                      description: "The shop's repairs in this status, older spellings included and
                        archived ones left out"
                    }
                  open: { type: integer, description: Of those, the ones not closed }
            otherValues:
              type: array
              description: Other values the shop's repairs hold, from older apps, most used
                first
              items:
                type: object
                properties:
                  value:
                    {
                      type: string,
                      description: Exactly as stored; add it to a `status` filter to include these
                        repairs
                    }
                  count: { type: integer }
                  open: { type: integer }
                  mapsTo:
                    {
                      type: [ string, "null" ],
                      description: "The status it means today, or null. `Closed Repair` means closed
                        in the app (`closed: true`)."
                    }
        deviceTypes:
          type: array
          description: With `repairs:read`. The device types of the shop's repairs, most
            used first.
          items:
            type: object
            properties:
              type: { type: string }
              count: { type: integer }
        repairTypes:
          type: array
          description: "With `repairs:read` or `repairs:write`. The shop's repair types
            (`repairTypeId` on `POST /repairs`), as `GET /repair-types` lists
            them. Up to an hour old (`generatedAt`)."
          items: { $ref: "#/components/schemas/RepairType" }
        technicians:
          type: array
          description: With `repairs:read`. The staff a repair can be assigned to
            (`technicianId`), fired staff left out.
          items:
            type: object
            properties:
              id: { type: string }
              name: { type: [ string, "null" ] }
        itemTypes:
          type: array
          description: With `inventory:read`. The types of the shop's inventory items,
            most used first.
          items:
            type: object
            properties:
              type: { type: string }
              count: { type: integer }

    Repair:
      type: object
      properties:
        id: { type: string }
        number:
          {
            type: [ string, "null" ],
            description: "The repair number staff see, written RS912. `GET /repairs/RS912`
              finds it."
          }
        status:
          type: [ string, "null" ]
          description: "One of the 12 statuses (see `PATCH /repairs/{id}/status` and `GET
            /reference`). Older repairs can hold an older value, listed in `GET
            /reference`."
        statusUpdatedAt:
          {
            type: [ string, "null" ],
            format: date-time,
            description: "When the status last changed. Closing the repair and changing its
              priority set it too."
          }
        createdAt:
          {
            type: [ string, "null" ],
            format: date-time,
            description: When the repair was created
          }
        device:
          {
            type: [ string, "null" ],
            description: "The device, as entered (e.g. iPhone 13)"
          }
        deviceType:
          {
            type: [ string, "null" ],
            description: "The kind of device (e.g. Phone, Tablet): the name of the repair's
              repair type. `GET /reference` lists the ones in use."
          }
        imei:
          {
            type: [ string, "null" ],
            description: The device's IMEI or serial number,
            as entered
          }
        issue:
          {
            type: [ string, "null" ],
            description: "What's being repaired (e.g. Screen)"
          }
        repairTypeId:
          {
            type: [ string, "null" ],
            description: "The shop's repair type (`GET /repair-types`). Null on older
              repairs created without one."
          }
        price:
          type: [ number, "null" ]
          description: "What the customer pays: the repair's lines with their tax (already
            inside the price for a GST tax group) and the labor."
        paid:
          {
            type: boolean,
            description: "Paid in full. Separate from the status: the `Paid` status doesn't
              set it."
          }
        closed:
          {
            type: boolean,
            description: "Closed in the app. Separate from the status: no status closes a
              repair."
          }
        highPriority:
          {
            type: boolean,
            description: The shop's urgent flag. Closing the repair clears it.
          }
        archived:
          {
            type: boolean,
            description: "Deleted in the app. Lists leave archived repairs out unless
              `changed_since` is used."
          }
        warranty:
          {
            type: [ string, "null" ],
            description: "The shop's warranty text, set when the repair was marked repaired;
              `n/a` means none."
          }
        customer:
          type: object
          description: "A copy taken when the repair was created: it isn't updated when
            the customer is. `GET /customers/{id}` has the current details."
          properties:
            id: { type: [ string, "null" ] }
            name: { type: [ string, "null" ] }
            phone: { type: [ string, "null" ] }
            email: { type: [ string, "null" ], description: Null when the customer had no email }
        technicianId:
          {
            type: [ string, "null" ],
            description: "The assigned technician. `GET /reference` lists their names."
          }
        updatedAt:
          {
            type: [ string, "null" ],
            format: date-time,
            description: When anything on the repair last changed
          }

    Customer:
      type: object
      properties:
        id: { type: string }
        firstName: { type: [ string, "null" ] }
        lastName: { type: [ string, "null" ] }
        phone:
          {
            type: [ string, "null" ],
            description: As entered; searches match its digits whatever the formatting
          }
        email:
          {
            type: [ string, "null" ],
            description: "Null when the customer has no email (the app keeps a placeholder)"
          }
        city: { type: [ string, "null" ] }
        b2b: { type: boolean, description: A business customer }
        discount:
          {
            type: [ number, "null" ],
            description: "Percent off this customer's sales: 10 means 10%."
          }
        credit:
          {
            type: [ number, "null" ],
            description: "The customer's store credit balance, in the shop's currency. It's
              used up when redeemed at checkout."
          }
        points: { type: [ number, "null" ], description: Not used. }
        notes:
          {
            type: [ string, "null" ],
            description: "The shop's notes about the customer"
          }
        createdAt: { type: [ string, "null" ], format: date-time }
        updatedAt: { type: [ string, "null" ], format: date-time }

    Item:
      type: object
      properties:
        id: { type: string }
        name:
          {
            type: [ string, "null" ],
            description: "The product's name (e.g. iPhone 13 Screen)"
          }
        description: { type: [ string, "null" ] }
        sku: { type: [ string, "null" ] }
        barcode: { type: [ string, "null" ] }
        type:
          {
            type: [ string, "null" ],
            description: "The shop's category, e.g. Part or Accessory. `GET /reference`
              lists the ones in use. Devices aren't in v1."
          }
        price:
          {
            type: [ number, "null" ],
            description: "The selling price, in the shop's currency"
          }
        stock: { type: [ number, "null" ], description: The number on hand }
        lowStockThreshold:
          {
            type: [ number, "null" ],
            description: "The item is low on stock when `stock` is at or under this
              (`low_stock=true`). Null when not set."
          }
        taxable: { type: boolean, description: Taxed when sold }
        serialized:
          {
            type: boolean,
            description: "Tracked unit by unit: its stock can't be set or adjusted through
              the API."
          }
        archived: { type: boolean, description: Deleted in the app }
        createdAt: { type: [ string, "null" ], format: date-time }
        updatedAt: { type: [ string, "null" ], format: date-time }

    RepairCreate:
      type: object
      description: "Send `repairTypeId`, or `deviceType` alone (integrations from
        before `repairTypeId`): with neither, the answer is `422` with
        `details.field: \"repairTypeId\"`."
      required: [ customerId, device, issue ]
      anyOf:
        - required: [ repairTypeId ]
        - required: [ deviceType ]
      properties:
        customerId: { type: string, description: One of the shop's customers }
        repairTypeId:
          type: string
          description: "One of the shop's repair types (`GET /repair-types`). Required
            unless `deviceType` names one. The repair's `deviceType` is set to
            its name."
        deviceType:
          type: string
          maxLength: 64
          example: Phone
          description: |
            For integrations from before `repairTypeId`: the name of one of the
            shop's repair types, case and outer spaces aside. Sent alone, it
            picks that type (the first in `GET /repair-types` order if two share
            the name); a name that matches none answers `422` with
            `details.field: "repairTypeId"`. Sent with `repairTypeId`, it's
            ignored: `repairTypeId` decides. Either way the repair's
            `deviceType` is the type's own name.
        device: { type: string, maxLength: 200, example: iPhone 13 }
        issue: { type: string, maxLength: 200, example: Cracked screen }
        lockCode:
          type: string
          maxLength: 64
          writeOnly: true
          example: "0123"
          description: |
            The device's passcode or password, for the technician. Text, so a
            leading zero is kept; saved exactly as sent (not trimmed). Never
            returned, never in webhooks, and redacted in the API activity log.
        imei: { type: string, maxLength: 64 }
        estimatePrice:
          type: number
          minimum: 0
          example: 120
          description: |
            Adds the estimate line "<device> <issue>" (type Part), taxed by the
            shop's default tax group when the shop taxes estimates. 0 still adds
            the line. Replaces `price`, which now answers 422.
        laborPrice:
          type: number
          minimum: 0
          example: 40
          description: Adds the "Labor Cost" line (type Labor), taxed when the shop taxes
            labor. Its total is part of the repair's `price`.
        notes: { type: string, maxLength: 2000 }
        highPriority: { type: boolean }
        technicianId: { type: string, description: Someone on the shop's staff }
      additionalProperties: false

    StatusChange:
      type: object
      required: [ status ]
      properties:
        status:
          type: string
          description: One of the app's 12 statuses, in any casing.
          enum:
            [
              Pending,
              In Progress,
              Awaiting Parts,
              Waiting on customer,
              Repaired,
              Shipped,
              Delivered,
              Picked up,
              Tech Damage,
              Paid,
              Canceled,
              Non Repairable
            ]
          example: Repaired
        notify:
          type: boolean
          default: true
          description: false skips the customer's text and email for this change (the
            webhook still fires)

    CustomerCreate:
      type: object
      required: [ firstName ]
      properties:
        firstName: { type: string, maxLength: 100 }
        lastName: { type: string, maxLength: 100 }
        phone: { type: string, maxLength: 40 }
        email: { type: string, format: email, maxLength: 200 }
        city: { type: string, maxLength: 100 }
        notes: { type: string, maxLength: 2000 }
        b2b: { type: boolean }

    StockChange:
      type: object
      description: Exactly one of stock or adjust.
      properties:
        stock: { type: number, minimum: 0, description: Set the stock to this number }
        adjust:
          {
            type: number,
            description: "Add (positive) or remove (negative) units; not 0"
          }
        reason:
          {
            type: string,
            maxLength: 200,
            description: Kept in the item's stock history
          }

    BulkStockChange:
      type: object
      required: [ items ]
      properties:
        items:
          type: array
          minItems: 1
          maxItems: 100
          items:
            type: object
            required: [ id ]
            description: Exactly one of stock or adjust.
            properties:
              id: { type: string }
              stock: { type: number, minimum: 0 }
              adjust: { type: number }

    RepairType:
      type: object
      properties:
        id: { type: string, description: "What `POST /repairs` takes as `repairTypeId`" }
        name:
          {
            type: [ string, "null" ],
            description: "The type's name (e.g. Phone): a repair of this type has it as its
              `deviceType`"
          }
    RepairTypeList:
      type: object
      required: [ items ]
      properties:
        items:
          {
            type: array,
            items: { $ref: "#/components/schemas/RepairType" },
            description: "Every repair type of the shop, in the app's order"
          }

    RepairPage:
      type: object
      required: [ items, nextCursor, hasMore ]
      properties:
        items: { type: array, items: { $ref: "#/components/schemas/Repair" } }
        nextCursor: { type: [ string, "null" ] }
        hasMore: { type: boolean }
    CustomerPage:
      type: object
      required: [ items, nextCursor, hasMore ]
      properties:
        items: { type: array, items: { $ref: "#/components/schemas/Customer" } }
        nextCursor: { type: [ string, "null" ] }
        hasMore: { type: boolean }
    ItemPage:
      type: object
      required: [ items, nextCursor, hasMore ]
      properties:
        items: { type: array, items: { $ref: "#/components/schemas/Item" } }
        nextCursor: { type: [ string, "null" ] }
        hasMore: { type: boolean }
