openapi: 3.1.0
info:
  title: DeimOS Buyer API
  version: "1.0.0"
  description: >
    Per-buyer catalog, stock, prices, and orders. A key sees only its assortment
    and price list. Money is integer minor units. Unknown SKU or GTIN is 400.
    There is no order.received webhook. The POST response is the receipt.
servers:
  - url: https://{host}/v1
    variables:
      host:
        default: deimosb2b.com
security:
  - buyerKey: []
paths:
  /products:
    get:
      operationId: listProducts
      summary: Page of products in this assortment
      parameters:
        - $ref: "#/components/parameters/Cursor"
      responses:
        "200":
          description: Products in SKU order. next_cursor is null on the last page.
          content:
            application/json:
              schema:
                type: object
                required: [products, next_cursor]
                properties:
                  products:
                    type: array
                    items: { $ref: "#/components/schemas/Product" }
                  next_cursor:
                    type: [string, "null"]
        "400": { $ref: "#/components/responses/Error" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/Limited" }
  /products/{sku}:
    get:
      operationId: getProduct
      summary: One product in this assortment
      parameters:
        - $ref: "#/components/parameters/Sku"
      responses:
        "200":
          description: Product. Match is case-insensitive.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Product" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/Missing" }
        "429": { $ref: "#/components/responses/Limited" }
  /stock:
    get:
      operationId: listStock
      summary: Stock according to the channel stock policy
      parameters:
        - in: query
          name: sku
          required: false
          schema: { type: string }
          description: Omit to list the assortment. A SKU outside it is 404.
      responses:
        "200":
          description: >
            qty and hide_zero return a count. available and threshold return
            stock null and a boolean. Threshold treats quantity above 5 as available.
          content:
            application/json:
              schema:
                type: object
                required: [stock]
                properties:
                  stock:
                    type: array
                    items: { $ref: "#/components/schemas/StockRow" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/Missing" }
        "429": { $ref: "#/components/responses/Limited" }
  /prices:
    get:
      operationId: listPrices
      summary: Net prices from the channel price list
      parameters:
        - in: query
          name: sku
          required: false
          schema: { type: string }
      responses:
        "200":
          description: Rows with a net price. The buyer cannot send a price.
          content:
            application/json:
              schema:
                type: object
                required: [prices]
                properties:
                  prices:
                    type: array
                    items: { $ref: "#/components/schemas/PriceRow" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/Missing" }
        "429": { $ref: "#/components/responses/Limited" }
  /orders:
    post:
      operationId: createOrder
      summary: Place an order for this channel
      parameters:
        - $ref: "#/components/parameters/IdempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/OrderCreate" }
      responses:
        "201":
          description: Order created with status received. Prices are stamped by the server.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Order" }
        "200":
          description: Replay of the same Idempotency-Key and body.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Order" }
        "400":
          description: >
            Missing or overlong Idempotency-Key, a body over 100 KB, invalid JSON,
            a line the assortment does not contain, or a line above available stock
            that its backorder policy cannot cover. A missing Idempotency-Key
            is 400 even when the bearer token is absent.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "409":
          description: external_id already exists for a different Idempotency-Key or body.
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429": { $ref: "#/components/responses/Limited" }
  /orders/{id}:
    get:
      operationId: getOrder
      summary: Read an order that belongs to this channel
      parameters:
        - in: path
          name: id
          required: true
          schema: { type: string, format: uuid }
      responses:
        "200":
          description: Order
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Order" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404":
          description: Not this channel
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Error" }
        "429": { $ref: "#/components/responses/Limited" }
components:
  securitySchemes:
    buyerKey:
      type: http
      scheme: bearer
      description: >
        Channel secret. Prefix dei_. Stored as a hash. Revoked, suspended buyer,
        or suspended tenant is 401. IP ceiling is 300 requests a minute.
        The key also has its own rate_limit_rpm.
  parameters:
    Cursor:
      in: query
      name: cursor
      required: false
      schema: { type: string, maxLength: 200 }
      description: Opaque cursor from next_cursor. A bad cursor is 400 before auth.
    Sku:
      in: path
      name: sku
      required: true
      schema: { type: string }
    IdempotencyKey:
      in: header
      name: Idempotency-Key
      required: true
      schema: { type: string, minLength: 1, maxLength: 256 }
  responses:
    Error:
      description: Request cannot be applied
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    Unauthorized:
      description: Missing, bad, or revoked key
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    Missing:
      description: Not in this assortment
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    Limited:
      description: Too many requests
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
  schemas:
    Error:
      type: object
      required: [error]
      properties:
        error: { type: string }
    HonestStock:
      type: object
      description: >
        Honest stock fields. available_qty is on hand minus open reservations and the safety buffer.
        Counts are null when the channel stock policy hides quantities.
      required: [available_qty, reserved_qty, honest_status, backorder_allowed, backorder_max_qty, incoming_qty, next_eta, lead_time_days, stock_synced_at, is_stale]
      properties:
        available_qty: { type: [integer, "null"], minimum: 0 }
        reserved_qty: { type: [integer, "null"], minimum: 0 }
        honest_status:
          type: string
          enum: [in_stock, low_stock, backorder, out_of_stock]
        backorder_allowed: { type: boolean }
        backorder_max_qty:
          type: [integer, "null"]
          description: Units that can still be ordered beyond available_qty. Null means no cap or a hidden count.
        incoming_qty: { type: [integer, "null"], minimum: 0 }
        next_eta: { type: [string, "null"], format: date }
        lead_time_days: { type: [integer, "null"], minimum: 0 }
        stock_synced_at: { type: [string, "null"], format: date-time }
        is_stale: { type: boolean }
    Product:
      allOf:
        - { $ref: "#/components/schemas/HonestStock" }
        - $ref: "#/components/schemas/ProductBase"
    ProductBase:
      type: object
      required: [sku, gtin, title, description, brand, categories, currency, net_minor, moq, stock, available, images, pack_qty, attrs]
      properties:
        sku: { type: string }
        gtin: { type: string }
        title: { type: string }
        description: { type: string }
        brand: { type: string }
        categories:
          type: array
          items: { type: string }
        currency: { type: string }
        net_minor:
          type: [integer, "null"]
          description: Net price in minor units. Null when the price list has no row.
        moq: { type: integer, minimum: 0 }
        stock:
          type: [integer, "null"]
        available: { type: boolean }
        images:
          type: array
          items: { type: string }
        pack_qty: { type: integer, minimum: 1 }
        attrs:
          type: object
          additionalProperties:
            type: [string, number, boolean, "null"]
    StockRow:
      allOf:
        - { $ref: "#/components/schemas/HonestStock" }
        - type: object
          required: [sku, stock, available]
          properties:
            sku: { type: string }
            stock: { type: [integer, "null"] }
            available: { type: boolean }
    PriceRow:
      type: object
      required: [sku, currency, net_minor, moq]
      properties:
        sku: { type: string }
        currency: { type: string }
        net_minor: { type: integer }
        moq: { type: integer, minimum: 0 }
        tiers:
          type: array
          items:
            type: object
            required: [min_qty, net_minor]
            properties:
              min_qty: { type: integer, minimum: 2 }
              net_minor: { type: integer }
    OrderCreate:
      type: object
      required: [external_id, lines]
      properties:
        external_id: { type: string, minLength: 1, maxLength: 80 }
        notes: { type: string, maxLength: 2000 }
        ship_to: { $ref: "#/components/schemas/ShipTo" }
        fulfillment_mode:
          type: string
          enum: [split, wait_all, cap_available]
          default: split
          description: >
            What to do with lines above available stock. split ships what is available now and backorders the rest.
            wait_all holds the order until every line can ship. cap_available reduces lines to available stock.
            A line above the backorder cap or on a blocked SKU is 400.
        lines:
          type: array
          minItems: 1
          maxItems: 200
          items: { $ref: "#/components/schemas/OrderLineInput" }
    OrderLineInput:
      type: object
      required: [qty]
      properties:
        sku: { type: string }
        gtin: { type: string }
        qty: { type: integer, minimum: 1 }
        buyer_ref: { type: string, maxLength: 80 }
      description: sku or gtin is required. The server ignores any price on the line.
    ShipTo:
      type: object
      properties:
        name: { type: string, maxLength: 200 }
        line1: { type: string, maxLength: 200 }
        city: { type: string, maxLength: 200 }
        postal: { type: string, maxLength: 200 }
        country: { type: string, maxLength: 200 }
    Order:
      type: object
      required: [id, external_id, status, currency, notes, reject_reason, ship_to, total_minor, lines]
      properties:
        id: { type: string, format: uuid }
        external_id: { type: string }
        status:
          type: string
          enum: [received, accepted, rejected, fulfilled, cancelled]
        currency: { type: string }
        notes: { type: string }
        reject_reason: { type: string }
        ship_to: { $ref: "#/components/schemas/ShipTo" }
        total_minor: { type: integer }
        fulfillment_mode:
          type: string
          enum: [immediate, split, wait_all]
        has_backorder: { type: boolean }
        lines:
          type: array
          items: { $ref: "#/components/schemas/OrderLine" }
    OrderLine:
      type: object
      required: [sku, gtin, title, qty, net_minor, buyer_ref]
      properties:
        sku: { type: string }
        gtin: { type: string }
        title: { type: string }
        qty: { type: integer }
        net_minor: { type: integer }
        buyer_ref: { type: string }
        qty_immediate: { type: integer, minimum: 0 }
        qty_backordered: { type: integer, minimum: 0 }
        qty_allocated: { type: integer, minimum: 0 }
        backorder_status:
          type: string
          enum: [none, awaiting_stock, partially_allocated, ready_to_fulfill, fulfilled, canceled]
        expected_eta: { type: [string, "null"], format: date }
