---
title: "Attach variants to a supplier"
method: POST
path: "/api/v1/inventory/suppliers/{supplier_id}/variants"
tags: ["suppliers"]
---

# Attach variants to a supplier

`POST /api/v1/inventory/suppliers/{supplier_id}/variants`

## Request

- Base URL: `https://api.app.tightly.io`
- URL: `https://api.app.tightly.io/api/v1/inventory/suppliers/{supplier_id}/variants`
- Auth: HTTP bearer

Attaches variants to a supplier and answers 201 with the variant-supplier rows that now exist for the ids named: `unit_cost`, `currency`, `min_order_quantity`, `batch_size`, `lead_time`, where the lead time came from, and whether this supplier is that variant's default.

Name the variants one of two ways. `variant_ids` is an explicit list. `filter_args` and `search` select them the way the variants table does, with `exceptions` naming the ids to leave out; that arm attaches by query and answers an empty `variant_suppliers` list, so read the variants back afterwards rather than trusting the response to enumerate them.

A variant that already has a default supplier keeps it; one that does not takes this supplier as its default. A pair that already exists is left exactly as it is rather than reset, so re-sending the same ids costs nothing and changes nothing.

An unknown supplier is refused 404.

Scope: `suppliers:write`, which includes `suppliers:read`.

## Path parameters

- `supplier_id` string, required

## Headers

- `Tightly-Version` string
- `Idempotency-Key` string

## Request body

- AddVariantsToSupplierRequest
  - `exceptions` string[], nullable
  - `filter_args` ProductsFilterArg[], nullable
    - `key` string, required
    - `operation` string, required
    - `value` unknown
  - `search` string, nullable
  - `variant_ids` string[]

## Response `201`

The variant-supplier rows for the ids named. Empty when the variants were selected by `filter_args` or `search`.

- AddVariantsToSupplierResponse
  - `data` union
    - AddVariantsToSupplierPayload
      - `variant_suppliers` VariantSupplierBasic[], required
        - `batch_size` integer, nullable
        - `currency` string, nullable
        - `is_default` boolean, nullable
        - `lead_time` integer, nullable
        - `lead_time_source` string, nullable
        - `min_order_quantity` integer, nullable
        - `supplier_id` string, required
        - `unit_cost` number, nullable
        - `variant_id` string, required
    - object, nullable
  - `message` ApiMessage
    - `desc` string
    - `service` string
    - `severity` 'SUCCESS' | 'INFO' | 'ERROR' | 'WARNING'

## Other responses

- `400`: A filter key, operation or value is not one the variants table takes.
- `401`: No usable key: malformed, unknown, revoked, expired or stopped. One refusal covers all five, telling a caller which is which maps the surface for them. A request with no Authorization header at all is refused 400 before any key is looked for.
- `403`: The key may not reach this operation. `scope_missing` when the key does not hold Suppliers; `ip_not_allowed` when the caller's address is outside the key's allowlist. There is no `organization_mismatch` on this resource: no supplier or contact route names an organisation in its path, so there is nothing for a key to disagree with.
- `404`: No supplier of this organisation has that id.
- `429`: The key has spent its allowance for this minute. 600 reads and 120 writes a minute, counted per key, refused calls included. `Retry-After` says how long to wait.
- `503`: The database is briefly out of reach, which is what a failover or a full connection pool looks like from outside. Wait the seconds `Retry-After` names and send the request again. A read is safe to repeat. A write is not, because the connection was lost in the middle of it, so read the object back before sending it a second time. Branch on the status rather than on `code`, which is `POSTGRES_UNAVAILABLE` from one of the two seams that raise this and `SERVICE_UNAVAILABLE` from the other.

---

[API](https://skmtc.dev/tightly/apis/tightly-api.md) · [All operations](https://skmtc.dev/tightly/apis/tightly-api/llms.txt) · [OpenAPI document](https://skmtc.dev/tightly/apis/tightly-api/revisions/199f7eb35afb?raw)
