openapi: 3.1.0
info:
  title: Supplied partner API
  version: "1.0"
  description: >
    Connected Storefronts: send your customers' orders to Supplied, read your catalog and stock, and
    get signed webhooks. This file is the reference; the developer portal (docs/supplied/api) is built from it
    and from the examples recorded by the API's own end-to-end test, so every request and response shown there
    was produced by the running API.
servers:
  - url: https://{host}/functions/v1/supplied-partner-api/v1
    variables:
      host: { default: api.supplied.example, description: "Given to you by Supplied." }
security:
  - apiKey: []
tags:
  - { name: Catalog, description: "What you can order, at your prices, and what is in stock." }
  - { name: Orders, description: "Place, read and cancel orders. Idempotent on your own order number." }
  - { name: Test mode, description: "Move test orders along without a warehouse (test keys only)." }
  - { name: Webhooks, description: "Be told when something changes. Signed, retried, and verified before anything is sent." }
  - { name: Events, description: "The replay log behind the webhooks. Catch up after any gap." }
components:
  securitySchemes:
    apiKey: { type: http, scheme: bearer, description: "Your key: sk_live_… for real orders, sk_test_… for testing. 48 hex characters after the prefix." }
  parameters:
    OrderId: { name: id, in: path, required: true, schema: { type: string }, description: "Our id (SUP-… for live orders, TEST-… for test orders) or your own external_id.", example: GLOW-1042 }
    EndpointId: { name: id, in: path, required: true, schema: { type: string, format: uuid }, description: The webhook endpoint's id. }
  schemas:
    Error:
      type: object
      required: [error]
      properties:
        error:
          type: object
          required: [code, message]
          properties:
            code: { type: string, description: "A stable machine-readable code. Branch on this, never on the message.", examples: [unknown_sku] }
            message: { type: string, description: "A sentence for a person. Its wording can change." }
            param: { type: string, description: "The field at fault, when one is, e.g. lines[0].sku.", examples: ["lines[0].sku"] }
    Address:
      type: object
      required: [name, line1, city, state, postal_code, country]
      properties:
        name: { type: string, maxLength: 100, description: "Who the parcel is for." }
        company: { type: [string, "null"], maxLength: 250 }
        line1: { type: string, maxLength: 250 }
        line2: { type: [string, "null"], maxLength: 250 }
        city: { type: string, maxLength: 100 }
        state: { type: string, maxLength: 50 }
        postal_code: { type: string, maxLength: 20 }
        country: { type: string, pattern: "^[A-Za-z]{2}$", description: Two letters, e.g. US. }
        phone: { type: [string, "null"], maxLength: 40, description: "The carrier gets it. We never ask for your customer's email, and we never contact them." }
    Product:
      type: object
      properties:
        object: { const: product }
        sku: { type: string }
        name: { type: string }
        description: { type: [string, "null"] }
        unit_price_cents: { type: integer, description: "Your drop-ship price for one unit, in cents (1800 = $18.00)." }
        currency: { const: USD }
        min_quantity: { type: integer, description: "The least you can order of this product on one line." }
        price_tiers: { type: array, description: "Lower prices from a quantity per line.", items: { type: object, properties: { min_quantity: { type: integer }, unit_price_cents: { type: integer } } } }
        available: { type: [integer, "null"], description: "What the warehouse can sell now (0 when sold out, never negative). Shared with every channel Supplied sells through, so treat it as live. null: the warehouse has not reported this product yet." }
        inventory_as_of: { type: [string, "null"], format: date-time, description: "When the warehouse last reported this stock." }
        image_url: { type: [string, "null"], format: uri, description: "A photo of the product: a stable, public https URL you may copy. A changed photo is a new URL, and product.updated tells you. Your own label's picture once Supplied has made it, otherwise a plain photo of the container with a blank label (never Supplied's branding). null: no photo yet. Left out while Supplied hasn't turned photos on for your account's API." }
        strength: { type: array, description: "The product's strength as Supplied holds it, left out while Supplied has not filled it in. One row per ingredient, in label order (a blend has several): amount (a number above 0), unit (mg, mcg, g, mL, IU, mg/mL, mcg/mL or IU/mL) and ingredient (the ingredient's name, always present for a blend). An empty list means no strength applies (for example a capsule product sold by pack count).", items: { type: object, properties: { amount: { type: number }, unit: { type: string }, ingredient: { type: string } }, required: [amount, unit] } }
        strength_display: { type: [string, "null"], description: "The strength as text, in row order: \"10 mg\", \"10 mg / 10 mg\". null when strength is an empty list. Present whenever strength is." }
    Inventory:
      type: object
      properties:
        object: { const: inventory }
        sku: { type: string }
        available: { type: [integer, "null"], description: "What the warehouse can sell now. null: not reported yet." }
        as_of: { type: [string, "null"], format: date-time }
    OrderInput:
      type: object
      required: [external_id, ship_to, lines]
      properties:
        external_id: { type: string, minLength: 1, maxLength: 100, description: "Your order number. Unique in your account, and how a retry is recognised: the same external_id with the same content returns the existing order." }
        ship_to: { $ref: "#/components/schemas/Address" }
        lines:
          type: array
          minItems: 1
          maxItems: 200
          description: One line per SKU. Prices come from your catalog; you do not send them.
          items: { type: object, required: [sku, quantity], properties: { sku: { type: string }, quantity: { type: integer, minimum: 1, maximum: 1000000, description: "A whole number, at least the product's min_quantity." } } }
        notes: { type: [string, "null"], maxLength: 1000, description: "Kept on the order for Supplied." }
        shipping_method: { type: [string, "null"], maxLength: 100, description: "Kept on the order. When your account has a freight price for this method (a key such as standard, fedex-2day or next-day), the order is billed that freight and the warehouse ships with the matching service; otherwise your account's usual shipping applies." }
    Order:
      type: object
      properties:
        object: { const: order }
        id: { type: string, description: "Our order number: SUP-… (live) or TEST-… (test)." }
        external_id: { type: string, description: "Your order number." }
        livemode: { type: boolean, description: "false for an order placed with a test key." }
        status:
          enum: [received, held, processing, partially_shipped, shipped, delivered, cancel_requested, cancelled]
          description: See the order lifecycle.
        hold_reasons:
          type: array
          description: Why a held order is waiting. Empty otherwise.
          items:
            type: object
            properties:
              code: { enum: [stock, credit, manual_review, warehouse_setup] }
              message: { type: string }
              lines: { type: array, description: "For stock: the short lines, with what is available and what you ordered." }
        ship_to: { $ref: "#/components/schemas/Address" }
        lines:
          type: array
          items:
            type: object
            properties:
              sku: { type: string }
              name: { type: string }
              quantity: { type: integer }
              shipped_quantity: { type: integer, description: "How much of this line has shipped." }
              unit_price_cents: { type: integer }
              total_cents: { type: integer }
        subtotal_cents: { type: integer, description: "The products only." }
        shipping_cents: { type: integer, description: "Shipping on this order. A flat price per order when your account has one (set when the order is placed, never changed afterwards). Otherwise the warehouse's cost, known once the order ships: 0 until then (always 0 on an order paid before it ships, which pays no shipping without a flat price). It is on the invoice." }
        total_cents: { type: integer, description: "subtotal_cents + shipping_cents: what the order is invoiced at (with a flat price, from the moment it is placed). A cancelled order is not invoiced." }
        currency: { const: USD }
        shipping_method: { type: [string, "null"] }
        notes: { type: [string, "null"] }
        shipments:
          type: array
          description: One entry per package, with the tracking number as soon as the warehouse has it.
          items:
            type: object
            properties:
              tracking_number: { type: string }
              carrier: { type: [string, "null"] }
              lines: { type: array, items: { type: object, properties: { sku: { type: string }, quantity: { type: integer } } } }
        shipped_at: { type: [string, "null"], format: date-time }
        delivered_at: { type: [string, "null"], format: date-time }
        cancelled_at: { type: [string, "null"], format: date-time }
        created_at: { type: string, format: date-time }
        updated_at: { type: string, format: date-time, description: "When the order last changed: placed, held, released, shipped, delivered, cancel requested or cancelled." }
    EventType:
      enum: [order.created, order.held, order.released, order.partially_shipped, order.shipped, order.delivered, order.cancelled,
             inventory.updated, product.added, product.updated, product.removed, price.updated]
    Event:
      type: object
      properties:
        object: { const: event }
        id: { type: string, description: "Unique. Drop a delivery whose id you have already processed.", examples: [evt_8812] }
        sequence: { type: integer, description: "Your own counter. Only goes up, and can skip numbers. Use it to catch up with GET /events." }
        type: { oneOf: [{ $ref: "#/components/schemas/EventType" }, { const: ping }] }
        created_at: { type: string, format: date-time }
        livemode: { type: boolean }
        resource:
          type: object
          description: What changed. Versions only go up for a record, so ignore an event whose version you already hold.
          properties: { type: { enum: [order, inventory, product, endpoint] }, id: { type: string }, version: { type: integer } }
        data: { type: object, description: "The record's full state at that moment, never a change." }
    Endpoint:
      type: object
      properties:
        object: { const: webhook_endpoint }
        id: { type: string, format: uuid }
        url: { type: string, format: uri }
        events: { type: array, items: { type: string }, description: 'The event types you subscribed to, or ["*"] for all.' }
        description: { type: string }
        livemode: { type: boolean, description: "An endpoint made with a test key gets test-mode order events." }
        status: { enum: [pending_verification, active, paused, disabled] }
        secret: { type: string, description: "whsec_… Only in the answer to POST /webhook_endpoints. Store it: it is never shown again." }
        created_at: { type: string, format: date-time }
        verified_at: { type: string, format: date-time }
        disabled_at: { type: string, format: date-time }
        disabled_reason: { type: string }
        health:
          type: object
          description: How deliveries are going.
          properties:
            last_success_at: { type: string, format: date-time }
            last_failure_at: { type: string, format: date-time }
            last_error: { type: string }
            failing_since: { type: string, format: date-time }
            consecutive_failures: { type: integer }
            pending: { type: integer, description: "Events waiting to be sent." }
            oldest_pending_at: { type: string, format: date-time }
    Attempt:
      type: object
      properties:
        object: { const: delivery_attempt }
        kind: { enum: [event, verification], description: "Only in the list of attempts (not in the answer to a test send)." }
        event_id: { type: [string, "null"] }
        event_type: { type: [string, "null"] }
        attempted_at: { type: string, format: date-time }
        ok: { type: boolean }
        status_code: { type: [integer, "null"], description: "What your server answered." }
        duration_ms: { type: integer }
        error: { type: [string, "null"] }
  responses:
    Error: { description: An error, content: { application/json: { schema: { $ref: "#/components/schemas/Error" } } } }
paths:
  /products:
    get:
      operationId: listProducts
      tags: [Catalog]
      summary: List your catalog
      description: >
        Your catalog: every product you can order, at your prices, with live stock. Professional products
        (PUO and 503A) are not listed, because they cannot be ordered through the API.
        Read it once at start-up and keep it fresh with the `product.*`, `price.updated` and `inventory.updated` events.
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { object: { const: list }, data: { type: array, items: { $ref: "#/components/schemas/Product" } } } } } } }
        default: { $ref: "#/components/responses/Error" }
  /inventory:
    get:
      operationId: listInventory
      tags: [Catalog]
      summary: Read stock
      description: >
        Just the stock: `sku`, `available` and `as_of`, for all your SKUs or the ones you name.
        Subscribe to `inventory.updated` to stay current, and read this every 15 minutes as a safety net.
      parameters: [{ name: skus, in: query, schema: { type: string }, description: Comma-separated SKUs. Leave out for all., example: "PL-BPC-GLOW,PL-GHK-GLOW" }]
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { object: { const: list }, data: { type: array, items: { $ref: "#/components/schemas/Inventory" } } } } } } }
        default: { $ref: "#/components/responses/Error" }
  /orders:
    post:
      operationId: createOrder
      tags: [Orders]
      summary: Place an order
      description: >
        Sends one customer order to Supplied. We pick, pack and ship it in your name.

        **Idempotent on `external_id`:** if a request times out, send it again. The same `external_id` with the same
        content returns the existing order with `200` and never creates a second one; with different content it is `409 external_id_conflict`.
        A new order answers `201`.

        If a line is short of stock the order is `held` (see `hold_reasons`) and goes out by itself when stock arrives.
        Your account must be invoiced on net terms: orders are invoiced when they ship, with shipping at your account's flat price per order, or at the warehouse's cost when it has none.
      x-errors: [invalid_request, unknown_sku, below_minimum, not_in_step, professional_product, external_id_conflict, account_not_on_terms, account_suspended, partner_disabled]
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/OrderInput" } } } }
      responses:
        "201": { description: Created, content: { application/json: { schema: { $ref: "#/components/schemas/Order" } } } }
        "200": { description: The same order was already placed, content: { application/json: { schema: { $ref: "#/components/schemas/Order" } } } }
        default: { $ref: "#/components/responses/Error" }
    get:
      operationId: listOrders
      tags: [Orders]
      summary: List orders
      description: >
        Your orders that changed since a time, **oldest change first**, so you can walk forward through your changes. `updated_since` must be an ISO 8601 time, and `limit` is clamped to 1 to 100.
        Page with `starting_after=<the last id you got>` while `has_more` is true.
      x-errors: [invalid_request]
      parameters:
        - { name: updated_since, in: query, schema: { type: string, format: date-time }, description: Only orders changed at or after this time., example: "2026-11-01T00:00:00Z" }
        - { name: starting_after, in: query, schema: { type: string }, description: "The id of the last order of the previous page." }
        - { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 50 }, description: How many to return. }
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { object: { const: list }, has_more: { type: boolean }, data: { type: array, items: { $ref: "#/components/schemas/Order" } } } } } } }
        default: { $ref: "#/components/responses/Error" }
  /orders/{id}:
    get:
      operationId: getOrder
      tags: [Orders]
      summary: Read an order
      description: One order, by our `id` or by your own `external_id`. A test key sees only test orders and a live key only live orders.
      x-errors: [order_not_found]
      parameters: [{ $ref: "#/components/parameters/OrderId" }]
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Order" } } } }
        default: { $ref: "#/components/responses/Error" }
  /orders/{id}/cancel:
    post:
      operationId: cancelOrder
      tags: [Orders]
      summary: Cancel an order
      description: >
        While the order is **held** it is cancelled at once. If it is at the warehouse but not started, the cancel is sent there:
        the order shows `cancel_requested`, then `cancelled`. Once picking has started it is `409 order_in_fulfillment`: contact Supplied.
        Cancelling twice returns the order unchanged.
      x-errors: [order_not_found, order_in_fulfillment]
      parameters: [{ $ref: "#/components/parameters/OrderId" }]
      requestBody: { content: { application/json: { schema: { type: object, properties: { reason: { type: string, maxLength: 500, description: "Kept on the order." } } } } } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Order" } } } }
        default: { $ref: "#/components/responses/Error" }
  /test_helpers/orders/{id}/ship:
    post:
      operationId: testShipOrder
      tags: [Test mode]
      summary: Ship a test order
      description: >
        Test keys only. Moves a test order to `shipped` with a tracking number, and sends the same webhooks a real shipment would.
        The body is optional.
      x-errors: [test_mode_only, order_not_found, invalid_state]
      parameters: [{ $ref: "#/components/parameters/OrderId" }]
      requestBody: { content: { application/json: { schema: { type: object, properties: { tracking_number: { type: string }, carrier: { type: string } } } } } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Order" } } } }
        default: { $ref: "#/components/responses/Error" }
  /test_helpers/orders/{id}/deliver:
    post:
      operationId: testDeliverOrder
      tags: [Test mode]
      summary: Deliver a test order
      description: Test keys only. Moves a shipped test order to `delivered`, and sends the `order.delivered` webhook.
      x-errors: [test_mode_only, order_not_found, invalid_state]
      parameters: [{ $ref: "#/components/parameters/OrderId" }]
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Order" } } } }
        default: { $ref: "#/components/responses/Error" }
  /webhook_endpoints:
    post:
      operationId: createWebhookEndpoint
      tags: [Webhooks]
      summary: Subscribe an address
      description: >
        Subscribes an HTTPS address to your events. Before anything is sent we POST a challenge to it and it must answer within 10 seconds
        (see Webhooks). The answer includes the endpoint's **`secret`**: it is shown here only, so store it.
        You can have up to 5 endpoints per mode.
      x-errors: [invalid_url, invalid_request, too_many_endpoints]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [url]
              properties:
                url: { type: string, format: uri, description: "An https:// address on your server." }
                events: { type: array, items: { type: string }, default: ["*"], description: 'The event types you want, or ["*"] for all.' }
                description: { type: string, maxLength: 200 }
      responses:
        "201": { description: Created, content: { application/json: { schema: { $ref: "#/components/schemas/Endpoint" } } } }
        default: { $ref: "#/components/responses/Error" }
    get:
      operationId: listWebhookEndpoints
      tags: [Webhooks]
      summary: List endpoints
      description: Your webhook endpoints for this key's mode. The secret is never included.
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { object: { const: list }, data: { type: array, items: { $ref: "#/components/schemas/Endpoint" } } } } } } }
        default: { $ref: "#/components/responses/Error" }
  /webhook_endpoints/{id}:
    get:
      operationId: getWebhookEndpoint
      tags: [Webhooks]
      summary: Read an endpoint
      description: "One endpoint with its **health**: last success and failure, the last error, failures in a row, and how many events are waiting."
      x-errors: [endpoint_not_found]
      parameters: [{ $ref: "#/components/parameters/EndpointId" }]
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Endpoint" } } } }
        default: { $ref: "#/components/responses/Error" }
    patch:
      operationId: updateWebhookEndpoint
      tags: [Webhooks]
      summary: Change, pause or resume an endpoint
      description: >
        Change `url`, `events` or `description`, or set `status` to `paused` or `active`. Changing the `url` means verifying again.
        An endpoint Supplied turned off: contact Supplied to turn it back on.
      x-errors: [endpoint_not_found, endpoint_disabled_by_supplied, not_verified, invalid_url, invalid_request]
      parameters: [{ $ref: "#/components/parameters/EndpointId" }]
      requestBody:
        content:
          application/json:
            schema: { type: object, properties: { url: { type: string }, events: { type: array, items: { type: string } }, description: { type: string }, status: { enum: [active, paused] } } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Endpoint" } } } }
        default: { $ref: "#/components/responses/Error" }
    delete:
      operationId: deleteWebhookEndpoint
      tags: [Webhooks]
      summary: Unsubscribe
      description: "Deletes the endpoint: nothing more is sent to it."
      x-errors: [endpoint_not_found]
      parameters: [{ $ref: "#/components/parameters/EndpointId" }]
      responses:
        "200": { description: Deleted, content: { application/json: { schema: { type: object, properties: { id: { type: string }, object: { const: webhook_endpoint }, deleted: { const: true } } } } } }
        default: { $ref: "#/components/responses/Error" }
  /webhook_endpoints/{id}/verify:
    post:
      operationId: verifyWebhookEndpoint
      tags: [Webhooks]
      summary: Verify an endpoint again
      description: Sends the verification challenge again. The endpoint is `active` once your server answers it correctly. An endpoint that is already active is returned as it is, with no new challenge.
      x-errors: [endpoint_not_found]
      parameters: [{ $ref: "#/components/parameters/EndpointId" }]
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Endpoint" } } } }
        default: { $ref: "#/components/responses/Error" }
  /webhook_endpoints/{id}/test:
    post:
      operationId: testWebhookEndpoint
      tags: [Webhooks]
      summary: Send a test event
      description: >
        Sends a `ping` now, signed like any real event, and answers with the result: your server's status code, the time taken and any error.
        Your server's response body is not returned (it is in your own logs).
      x-errors: [endpoint_not_found, not_verified, invalid_state]
      parameters: [{ $ref: "#/components/parameters/EndpointId" }]
      responses:
        "200": { description: The attempt, content: { application/json: { schema: { $ref: "#/components/schemas/Attempt" } } } }
        default: { $ref: "#/components/responses/Error" }
  /webhook_endpoints/{id}/attempts:
    get:
      operationId: listDeliveryAttempts
      tags: [Webhooks]
      summary: List delivery attempts
      description: "Every attempt to reach this endpoint, newest first: use it to find out why deliveries are failing."
      x-errors: [endpoint_not_found]
      parameters:
        - { $ref: "#/components/parameters/EndpointId" }
        - { name: limit, in: query, schema: { type: integer, maximum: 100 }, description: How many to return. }
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { object: { const: list }, data: { type: array, items: { $ref: "#/components/schemas/Attempt" } } } } } } }
        default: { $ref: "#/components/responses/Error" }
  /events:
    get:
      operationId: listEvents
      tags: [Events]
      summary: Read the event log
      description: >
        Your events in order, kept for 30 days (longer while one is still waiting to be delivered). Store the last `sequence` you processed and, after any gap (an outage, a deploy, a missed webhook),
        read from there. This is how you rebuild anything, with or without webhooks.
      x-errors: [invalid_request]
      parameters:
        - { name: after, in: query, schema: { type: integer, default: 0 }, description: Only events with a higher sequence. }
        - { name: limit, in: query, schema: { type: integer, maximum: 500, default: 100 }, description: How many to return. }
        - { name: types, in: query, schema: { type: string }, description: Comma-separated event types to keep., example: "order.created,order.shipped" }
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { object: { const: list }, has_more: { type: boolean }, oldest_sequence: { type: [integer, "null"] }, data: { type: array, items: { $ref: "#/components/schemas/Event" } } } } } } }
        default: { $ref: "#/components/responses/Error" }
webhooks:
  event:
    post:
      operationId: receiveEvent
      tags: [Webhooks]
      summary: A delivery to your server
      description: >
        One event, signed: `Supplied-Signature: t=…,v1=HMAC-SHA256(secret, "<t>.<raw body>")`. Save the event, then answer any 2xx within 10 seconds (queue anything slow).
      requestBody: { content: { application/json: { schema: { $ref: "#/components/schemas/Event" } } } }
      responses:
        "200": { description: "Answer any 2xx within 10 seconds" }
