> ## Documentation Index
> Fetch the complete documentation index at: https://integration.delogue.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Assign supplier facilities to styles

> Record which supplier facility handles each facility type on a style — the per-style supply-chain selections that connect a style to the factories, mills, and workshops producing it.

<Info>
  **When to use this.** A style's supplier facilities are its supply-chain selections: for each
  facility type your organisation tracks (Sewing, Fabric Mill, Wet Processing, …) you record the
  one supplier facility that handles it for that style. Use these endpoints to read and maintain
  those selections — the link between a style and the physical locations producing it.
</Info>

## The workflow

Each selection maps a **facility type** to a **supplier facility** on a single style. Facility
types are defined per organisation; supplier facilities are the physical locations that hang off
your sub-suppliers. A supplier facility can only be selected under a facility type it actually
carries, so identify the facility first, then attach it to the style, then read the result back.

<Steps>
  <Step title="Find the supplier facility">
    `GET /api/facilities` lists the supplier facilities available to your organisation. Note the
    `id` of the facility you want and the facility type it carries — you attach it under that type.
  </Step>

  <Step title="Assign facilities to the style (full replace)">
    `PUT /api/styles/{styleId}/supplier-facilities` replaces the style's whole selection set in one
    transaction. The body is an array of `{ facilityTypeId, supplierFacilityId }` items; an item with
    `state: "deleted"` drops that facility-type selection instead of keeping it. To set selections
    across many styles at once, use `POST /api/style-supplier-facilities` with `styleId` on each item.
  </Step>

  <Step title="Read the selections">
    `GET /api/styles/{styleId}/supplier-facilities` returns one row per facility type the style has a
    selection for, with the resolved facility. For an organisation-wide view, filter
    `GET /api/style-supplier-facilities` by `styleId`, `facilityTypeId`, or `supplierFacilityId`.
  </Step>
</Steps>

```mermaid theme={"dark"}
sequenceDiagram
  participant D as Designer
  participant API as Delogue API
  D->>API: GET /api/facilities
  API-->>D: available supplier facilities
  D->>API: PUT /api/styles/{styleId}/supplier-facilities  (facilityTypeId + supplierFacilityId)
  API-->>D: the style's new selection set
  D->>API: GET /api/styles/{styleId}/supplier-facilities
  API-->>D: one row per selected facility type
```

## Walkthrough

Replace a style's supplier-facility selections. `PUT /api/styles/{styleId}/supplier-facilities` is a
full replace of the set: the array you send becomes the style's complete selection list, and any
facility type you omit is cleared. Include an item with `state: "deleted"` to drop one type while
keeping the rest — a read-modify-write client can post the `GET` body straight back.

<CodeGroup>
  ```bash cURL theme={"dark"}
  curl -X POST "https://service.my.delogue.com/api/style-supplier-facilities" \
    -H "Accept: application/json" \
    -H "X-Auth-Token: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '[
    {
      "styleId": 40318,
      "facilityTypeId": 12,
      "supplierFacilityId": 8801
    },
    {
      "styleId": 40319,
      "facilityTypeId": 12,
      "supplierFacilityId": 8801
    }
  ]'
  ```

  ```js JavaScript theme={"dark"}
  const res = await fetch("https://service.my.delogue.com/api/style-supplier-facilities", {
    method: "POST",
    headers: {
      "Accept": "application/json",
      "X-Auth-Token": "Bearer YOUR_API_KEY",
      "Content-Type": "application/json",
    },
    body: JSON.stringify([
    {
      "styleId": 40318,
      "facilityTypeId": 12,
      "supplierFacilityId": 8801
    },
    {
      "styleId": 40319,
      "facilityTypeId": 12,
      "supplierFacilityId": 8801
    }
  ]),
  });
  const { data } = await res.json();
  ```
</CodeGroup>

```json theme={"dark"}
{
  "status": "success",
  "code": "style_supplier_facilities_created",
  "data": [
    {
      "styleId": 40318,
      "facilityType": {
        "id": 12,
        "name": "Sewing"
      },
      "facility": {
        "id": 8801,
        "name": "Meridian Garment Works",
        "address": "12 Rua das Flores",
        "zipCodeOrCity": "Porto",
        "country": "Portugal",
        "state": "active"
      }
    },
    {
      "styleId": 40319,
      "facilityType": {
        "id": 12,
        "name": "Sewing"
      },
      "facility": {
        "id": 8801,
        "name": "Meridian Garment Works",
        "address": "12 Rua das Flores",
        "zipCodeOrCity": "Porto",
        "country": "Portugal",
        "state": "active"
      }
    }
  ]
}
```

The response wraps the resulting selections in the standard envelope. Each row resolves the selected
facility's name, address, and country, so you can render the supply chain without a second lookup.

## Field reference

The fields that matter most when reading or writing a style's supplier-facility selections:

| Field                | What it means at Delogue                                                                                                                                      |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `facilityTypeId`     | Unique identifier of the facility type to select a facility for. Required and must be greater than 0.                                                         |
| `styleId`            | Unique identifier of the style to add the selection to. Required and must be greater than 0.                                                                  |
| `supplierFacilityId` | Unique identifier of the supplier facility to map to the facility type. Required and must be greater than 0; the facility must carry the given facility type. |

## Roles & permissions

Writing supplier-facility selections requires the **`styles`** permission on a **designer (brand)**
account — typically `CompanyAdmin` or `CompanyUser` — and is authorised as a style update. Reading is
supplier-collaborative: a supplier organisation the style is assigned to can read the style's
selections, but only the style's own designer organisation can change them. A supplier principal that
attempts a write receives a **403**, as does any caller referencing a style in another organisation; a
style that exists nowhere returns **404**.

## When things go wrong

Errors use the standard envelope (`status: "error"`, a `code`, and `error.details[]`). Bulk writes are
all-or-nothing — a single bad row rolls the whole request back, and per-item failures carry an
`[i].field` path (e.g. `[2].supplierFacilityId`). A supplier facility that does not carry the requested
facility type is rejected with **422 `unprocessable_error.facility_does_not_carry_type`**. See
[Errors & responses](/concepts/errors) for the full list of codes and how to resolve them.

## What to call next

<CardGroup cols={2}>
  <Card title="Styles" href="/guides/styles">
    Create and maintain the styles these selections hang off.
  </Card>

  <Card title="Facilities" href="/guides/facilities">
    Create and maintain the supplier facilities you select here.
  </Card>

  <Card title="Sub-suppliers" href="/guides/sub-suppliers">
    Facilities belong to sub-suppliers — map your supply chain first.
  </Card>

  <Card title="List facilities" href="/api-reference/facilities/list-facilities">
    Find selectable supplier facilities: `GET /api/facilities`.
  </Card>
</CardGroup>
