# Suppliers

A supplier is a brand or distributor that sells on Beauty Router. These endpoints work for one salon location, the
company of the logged-in user, and they take the user token.

## List suppliers

`GET /v1/company/suppliers` returns the suppliers this salon location has ordered from.

```bash
curl https://api.beautyrouter.com/v1/company/suppliers \
  -H "Authorization: Bearer $USER_TOKEN"
```

```json
{
  "data": [
    {
      "id": "sup-1Ry6tUi3Op",
      "name": "Amberlin",
      "logo": "https://images.beautyrouter.com/sup-1Ry6tUi3Op/logo.png",
      "largeLogo": "https://images.beautyrouter.com/sup-1Ry6tUi3Op/logo-large.png",
      "rating": 94,
      "status": "active",
      "description": "Professional hair care made in Colorado, for salons that repair and protect color-treated hair.",
      "inShop": true,
      "unreadMessages": 2,
      "productIds": ["prod-4Fz9QbX2kL", "prod-6Gh2jKl8Zx", "prod-9Cv5bNm3Ws"]
    }
  ]
}
```

| Field            | Description                                                                                 |
| ---------------- | ------------------------------------------------------------------------------------------- |
| `id`             | The supplier ID, such as `sup-1Ry6tUi3Op`.                                                  |
| `name`           | The supplier name.                                                                          |
| `logo`           | The URL of the supplier's logo, or `null`.                                                  |
| `largeLogo`      | The URL of a larger logo, or `null`.                                                        |
| `rating`         | The rating from 0 to 100, or `null`. A supplier gets a rating after 25 fulfilled orders.    |
| `status`         | The state of the link between this salon location and the supplier. See the statuses below. |
| `description`    | The supplier's description, or `null`.                                                      |
| `inShop`         | Whether the supplier shows in the marketplace.                                              |
| `unreadMessages` | How many messages from this supplier the salon has not read.                                |
| `productIds`     | The products this supplier sells in the marketplace.                                        |

### Supplier statuses

| Status                 | Meaning                                                                                  |
| ---------------------- | ---------------------------------------------------------------------------------------- |
| `active`               | The salon location can order from the supplier.                                          |
| `archived_by_client`   | The salon archived the supplier. See [Archive and restore](#archive-and-restore).        |
| `archived_by_supplier` | The supplier archived the salon location. The salon cannot order from it any more.       |
| `blocked`              | Beauty Router blocked the supplier.                                                      |

## Supplier details

Add `supplierIds` to get specific suppliers, whether or not the salon location has ordered from them. Send up to 50 IDs,
separated with commas. Each row has the same fields. There is no separate endpoint for one supplier, so send one ID.

```bash
curl "https://api.beautyrouter.com/v1/company/suppliers?supplierIds=sup-1Ry6tUi3Op" \
  -H "Authorization: Bearer $USER_TOKEN"
```

The list has no prices. Prices come from [offers](/create-orders/#get-offers).

To show the same profile without building a screen, call `showSupplier(element, supplierId)`. See
[Embedded marketplace](/embedded-marketplace/#functions).

## Archive and restore

The salon can archive a supplier to hide it from its everyday lists, and restore it later.

- `POST /v1/company/suppliers/{supplierId}/archive` sets the status to `archived_by_client`.
- `POST /v1/company/suppliers/{supplierId}/restore` removes that status.

```bash
curl -X POST https://api.beautyrouter.com/v1/company/suppliers/sup-8Wq2eRt5Yu/archive \
  -H "Authorization: Bearer $USER_TOKEN"
```

Each call returns the supplier. A supplier the salon location has no link to fails with `not_found`. A user logged in
with [`canOrder: false`](/authentication/#users-who-cannot-order) gets `user_cannot_order`.

The salon can still order from a supplier it archived.

## Delivery estimates

`GET /v1/company/delivery-estimates` estimates how long delivery takes from each supplier to this salon location. Use
it to plan reorders. Send up to 50 IDs in `supplierIds`, separated with commas.

```bash
curl "https://api.beautyrouter.com/v1/company/delivery-estimates?supplierIds=sup-1Ry6tUi3Op,sup-8Wq2eRt5Yu" \
  -H "Authorization: Bearer $USER_TOKEN"
```

```json
{
  "data": [
    { "supplierId": "sup-1Ry6tUi3Op", "deliveryBusinessDays": 4 },
    { "supplierId": "sup-8Wq2eRt5Yu", "deliveryBusinessDays": 6 }
  ]
}
```

`deliveryBusinessDays` is the preparation time plus the time in transit, in business days. Beauty Router calculates it
on each request, from the supplier's address and the company's delivery address. It is an estimate, not a promise. The
response never includes either address.