> ## 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.

# Manage facilities

> Create and maintain the physical production locations attached to a sub-supplier — the facilities that supply-chain mappings, certificates, and style assignments reference.

<Info>
  **When to use this.** A facility is a physical production location (factory, mill, warehouse, etc.) owned or operated by one of your sub-suppliers. You create facilities under a sub-supplier, assign production process types to them (e.g. Ginning Mill, Knitting Mill), and then reference them in supply-chain mappings and compliance certificates. Use these endpoints to build and maintain that location library.
</Info>

## The workflow

Facilities live under sub-suppliers. The usual path is to locate or create the relevant sub-supplier first, create facilities with their production process types, and then reference them from supply-chain mappings or style-level assignments.

<Steps>
  <Step title="Identify the sub-supplier">
    Facilities always belong to a sub-supplier. Retrieve the sub-supplier's GUID from `GET /api/sub-suppliers` — you'll need it as the `subSupplierId` path parameter.
  </Step>

  <Step title="Create facilities">
    `POST /api/sub-suppliers/{subSupplierId}/facilities` with facility name, address, country code, and at least one `processTypeId`. The endpoint accepts an array so multiple facilities can be created in a single all-or-nothing transaction.
  </Step>

  <Step title="List and search facilities">
    `GET /api/facilities` (cross-org view) or `GET /api/sub-suppliers/{subSupplierId}/facilities` to filter by country, process type, MID, or free-text search.
  </Step>

  <Step title="Archive or soft-delete">
    `PATCH /api/facilities/{id}` with `[{ "op": "replace", "path": "/state", "value": "archived" }]` to retire a facility without losing its history, or `DELETE /api/facilities/{id}` to soft-delete it (sets `deletedAt`; never returns in list queries).
  </Step>
</Steps>

```mermaid theme={"dark"}
sequenceDiagram
  participant C as Client
  participant API as Delogue API
  C->>API: GET /api/sub-suppliers (find subSupplierId)
  API-->>C: sub-supplier list
  C->>API: POST /api/sub-suppliers/{subSupplierId}/facilities
  API-->>C: facilities_created + facility id(s)
  C->>API: GET /api/facilities?CountryCodes=CN&State=active
  API-->>C: paginated facility list
  C->>API: PATCH /api/facilities/{id} (archive)
  API-->>C: facility_updated (state: archived)
```

## Walkthrough

Create a facility for a sub-supplier and assign process types. The body is an array — one or many facilities are created in a single all-or-nothing transaction.

<CodeGroup>
  ```bash cURL theme={"dark"}
  curl -X POST "https://service.my.delogue.com/api/sub-suppliers/{subSupplierId}/facilities" \
    -H "Accept: application/json" \
    -H "X-Auth-Token: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '[
    {
      "name": "Weihai Sunrise Garments Co., Ltd",
      "address": "No. 12 Torch Road, Huancui District",
      "zipCode": "264200",
      "city": "Weihai",
      "stateOrRegion": "Shandong",
      "countryCode": "CN",
      "latitude": null,
      "longitude": null,
      "mid": "91370600MA3ABCD123",
      "relationType": null,
      "processTypeIds": [
        21,
        22
      ]
    }
  ]'
  ```

  ```js JavaScript theme={"dark"}
  const res = await fetch("https://service.my.delogue.com/api/sub-suppliers/{subSupplierId}/facilities", {
    method: "POST",
    headers: {
      "Accept": "application/json",
      "X-Auth-Token": "Bearer YOUR_API_KEY",
      "Content-Type": "application/json",
    },
    body: JSON.stringify([
    {
      "name": "Weihai Sunrise Garments Co., Ltd",
      "address": "No. 12 Torch Road, Huancui District",
      "zipCode": "264200",
      "city": "Weihai",
      "stateOrRegion": "Shandong",
      "countryCode": "CN",
      "latitude": null,
      "longitude": null,
      "mid": "91370600MA3ABCD123",
      "relationType": null,
      "processTypeIds": [
        21,
        22
      ]
    }
  ]),
  });
  const { data } = await res.json();
  ```
</CodeGroup>

```json theme={"dark"}
{
  "status": "success",
  "code": "facilities_created",
  "data": [
    {
      "id": "B338A54E-DBB7-4D71-969E-CF518AED01C8",
      "organizationId": 22188,
      "subSupplierId": "E1B6FD77-A9E6-4868-88EC-9AEFD23DC188",
      "name": "Weihai Sunrise Garments Co., Ltd",
      "address": "No. 12 Torch Road, Huancui District",
      "zipCode": "264200",
      "city": "Weihai",
      "stateOrRegion": "Shandong",
      "countryId": 45,
      "countryCode": "CN",
      "countryName": "China",
      "latitude": null,
      "longitude": null,
      "mid": "91370600MA3ABCD123",
      "relationType": null,
      "relationTypeName": null,
      "state": "active",
      "processes": [
        {
          "id": 201,
          "processTypeId": 21,
          "processTypeName": "Ginning Mill"
        },
        {
          "id": 202,
          "processTypeId": 22,
          "processTypeName": "Knitting Mill"
        }
      ],
      "certificateCount": 0,
      "createdAt": "2026-06-25T01:31:44.470Z"
    }
  ]
}
```

The response wraps the created facilities in the standard envelope. Hold onto each `id` — supply-chain mappings and certificate associations reference facilities by it.

## Field reference

| Field            | What it means at Delogue                                                                             |
| ---------------- | ---------------------------------------------------------------------------------------------------- |
| `address`        | Street address of the facility. Required.                                                            |
| `city`           | City where the facility is located. Required.                                                        |
| `countryCode`    | ISO 3166-1 alpha-2 country code, e.g. CN or PT. Required.                                            |
| `latitude`       | Geographic latitude in decimal degrees. Optional.                                                    |
| `longitude`      | Geographic longitude in decimal degrees. Optional.                                                   |
| `mid`            | Manufacturer Identification Number (MID). Optional.                                                  |
| `name`           | Display name of the facility. Required.                                                              |
| `processTypeIds` | IDs of the process types (FacilityProcessType) to assign to this facility. At least one is required. |
| `relationType`   | Supply chain relation type: distributor, itemSupplier, sourcingAgency, or styleSupplier. Optional.   |
| `stateOrRegion`  | State, province, or region within the country. Optional; null if not applicable.                     |
| `zipCode`        | Postal or ZIP code of the facility. Required.                                                        |

<Note>
  `PUT /api/facilities/{id}` is a full replace and requires all mandatory fields on every call. Use `PATCH /api/facilities/{id}` (RFC 6902 JSON Patch) for partial updates — only the fields you send change, the rest keep their current values.
</Note>

## Roles & permissions

Managing facilities requires the **`suppliers`** permission on either a **designer (brand)** account or a **supplier portal account**:

* **Brand users** (`CompanyAdmin`, `CompanyUser`) can create and manage facilities for any sub-supplier within their organisation.
* **Supplier portal users** (`SupplierAdmin`, `SupplierUser`) can manage facilities for their own sub-suppliers. Facility information is automatically shared with connected brand customers for supply-chain visibility.

Deleting a facility permanently removes it from supply-chain mappings — prefer archiving (`state: archived`) to preserve historical records.

## When things go wrong

Errors use the standard envelope (`status: "error"`, a `code`, and `error.details[]`). See [Errors & responses](/concepts/errors) for the full list of codes and how to resolve them.

Common cases for Facilities:

| Situation                                                | HTTP | `code`                                  |
| -------------------------------------------------------- | ---- | --------------------------------------- |
| `subSupplierId` does not exist or belongs to another org | 404  | `resource_error.sub_supplier_not_found` |
| `facilityId` does not exist or belongs to another org    | 404  | `resource_error.facility_not_found`     |
| `countryCode` is not a valid ISO 3166-1 alpha-2 code     | 400  | `validation_error.*`                    |
| `processTypeIds` is empty on create                      | 400  | `validation_error.required_field`       |
| Attempting to read a deleted facility                    | 404  | `resource_error.facility_not_found`     |

## What to call next

<CardGroup cols={2}>
  <Card title="Size ranges" href="/guides/size-ranges">
    Define the size ranges that styles and items reference — another supply-chain building block.
  </Card>

  <Card title="Style categories" href="/guides/style-categories">
    Organise styles into categories alongside their facility assignments.
  </Card>

  <Card title="Seasons" href="/guides/seasons">
    Create the seasons that styles are filed under — the top-level product structure.
  </Card>

  <Card title="Style supplier facilities" href="/guides/style-supplier-facilities">
    Link a style to the specific supplier facilities it is produced at.
  </Card>

  <Card title="API reference" href="/api-reference/facilities/list-facilities">
    Full parameter and response details for all Facilities endpoints.
  </Card>
</CardGroup>
