# Services

> The delivery services configured for your account, and how to pick one when you create an order.

Source: https://api-doc.4nortes.app/services

A service is a delivery product configured for your account - the same options you pick from when creating an order in your panel. Each order belongs to exactly one service.

<a id="service-types"></a>

## Your services

Services are set up per merchant by 4N NextDay, so the list, the codes and the names are specific to your account. Each service has:

| Field  | Type    | Description                                                       |
| ------ | ------- | ----------------------------------------------------------------- |
| `id`   | integer | Unique service identifier - this is what you send as `service_id` |
| `code` | string  | Short code chosen for your account (for example `ECOM-STGO`)      |
| `name` | string  | Display name, as shown in your panel                              |
| `type` | string  | `b2b`, `b2c` or `field` (see below)                               |

### Service types

| Type    | Meaning                                                                                                                                 |
| ------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `b2b`   | Deliveries to businesses - stores, warehouses, offices                                                                                  |
| `b2c`   | Deliveries to consumers - home delivery                                                                                                 |
| `field` | Cargo created by drivers on the road from blank labels. Auto-provisioned; **not for integration orders** and never chosen automatically |

> **Note:**
>
> Only **active** services are returned by the API. If a service you used to send disappears from the list, it was deactivated - orders with that `service_id` are rejected until you switch to another one.

<a id="service-selection"></a>

## Choose a service

When syncing an order, include the `service_id` - just like selecting a service in your panel:

```json
{
  "destination_address": "Calle Secundaria 456",
  "destination_locality": "Providencia",
  "weight": 2.5,
  "service_id": 27
}
```

What happens with `service_id`:

| You send                                            | Result                                                                                                                                                       |
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| The id of one of your active services               | The order is created with that service                                                                                                                       |
| Nothing                                             | Your account's default active service is used (never a `field` one). `422` with `There are no active services available for this merchant.` if you have none |
| The id of a service that isn't yours or is inactive | `422` with `The specified service is not available for this merchant.`                                                                                       |
| An id that doesn't exist at all                     | `422` validation error on `service_id`: `The selected service does not exist.`                                                                               |

### Fetch the list of services

Get your active services programmatically. This endpoint requires a merchant token:

```bash
curl https://api.4nortes.app/api/v1/services \
  -H "Authorization: Bearer {token}" \
  -H "Accept: application/json"
```

```js
const response = await fetch('https://api.4nortes.app/api/v1/services', {
  headers: {
    'Authorization': `Bearer ${token}`,
    'Accept': 'application/json',
  },
})
const { data: services } = await response.json()
```

### Response

```json
{
  "success": true,
  "message": "Services retrieved successfully",
  "data": [
    {
      "id": 31,
      "code": "B2B-RM",
      "name": "Distribución B2B Región Metropolitana",
      "type": "b2b"
    },
    {
      "id": 27,
      "code": "ECOM-STGO",
      "name": "E-commerce Santiago",
      "type": "b2c"
    }
  ],
  "timestamp": "2025-02-03T10:00:00.000000Z"
}
```

> **Note:**
>
> Need a new service, or a service for another destination area? Contact your 4N NextDay account representative - services, coverage and pricing are configured on our side.
