# Products API

> Products and their prices. Every route, its parameters and fields.

Products and their prices. 7 routes; send a bearer token with each (see [Authentication](/api/authentication.md)).

| Route | What it does |
| --- | --- |
| `GET /v1/products` | List products |
| `POST /v1/products` | Create a product (admins) |
| `GET /v1/products/{id}` | Get a product with its price history |
| `PATCH /v1/products/{id}` | Update a product (admins) |
| `DELETE /v1/products/{id}` | Delete a product (admins, soft delete) |
| `POST /v1/products/{id}/prices` | Change a product's price from a date (admins) |
| `POST /v1/products/{id}/restore` | Restore a deleted product (admins) |

## List products

`GET https://staging-api.naruskacrm.com/v1/products`

`q` matches the name or the code; `active=true` leaves out inactive products.

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `limit` | query | integer |  | 1–200, default `50` |
| `cursor` | query | string |  | next_cursor of the previous page. 1–400 characters |
| `active` | query | `true`, `false` |  |  |
| `q` | query | string |  | Name or code, accent- and case-insensitive. 1–200 characters |
| `sort` | query | `name`, `-name`, `code`, `-code`, `default_vat_rate`, `-default_vat_rate`, `created_at`, `-created_at`, `updated_at`, `-updated_at` |  | Sort by name, code, default_vat_rate, created_at, updated_at; prefix "-" for descending. |
| `updated_since` | query | string (date-time) |  |  |
| `include_deleted` | query | `true`, `false` |  |  |

### Response 200

| Field | Type | Always present | Notes |
| --- | --- | --- | --- |
| `data` | array of [Product](/api/reference/objects.md#product) | yes |  |
| `next_cursor` | string or null | yes |  |

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Create a product (admins)

`POST https://staging-api.naruskacrm.com/v1/products`

`prices` start on `valid_from` (default today), one per currency, excluding VAT.

### Request body

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `name` | string | yes | 1–200 characters |
| `code` | string or null |  | 1–100 characters |
| `description` | string or null |  | at most 2000 characters |
| `unit` | string or null |  | at most 50 characters |
| `default_vat_rate` | number | yes | 0–100 |
| `is_active` | boolean |  |  |
| `source_system` | string or null |  | 1–100 characters |
| `source_id` | string or null |  | 1–500 characters |
| `prices` | array of object |  | at most 20 items |
| `prices[].currency` | string | yes |  |
| `prices[].unit_price` | number | yes | 0–1000000000000000 |
| `prices[].valid_from` | string (date) |  |  |

### Response 201

Returns: [Product](/api/reference/objects.md#product).

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Get a product with its price history

`GET https://staging-api.naruskacrm.com/v1/products/{id}`

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |

### Response 200

Returns: [Product](/api/reference/objects.md#product).

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Update a product (admins)

`PATCH https://staging-api.naruskacrm.com/v1/products/{id}`

Change prices with POST /v1/products/{id}/prices. Quotes keep the values they copied.

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |

### Request body

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `name` | string |  | 1–200 characters |
| `code` | string or null |  | 1–100 characters |
| `description` | string or null |  | at most 2000 characters |
| `unit` | string or null |  | at most 50 characters |
| `default_vat_rate` | number |  | 0–100 |
| `is_active` | boolean |  |  |
| `source_system` | string or null |  | 1–100 characters |
| `source_id` | string or null |  | 1–500 characters |

### Response 200

Returns: [Product](/api/reference/objects.md#product).

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Delete a product (admins, soft delete)

`DELETE https://staging-api.naruskacrm.com/v1/products/{id}`

Lines already on quotes keep their values. Prefer is_active = false to keep it in the history.

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |

### Response 204

Done.
No body.

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Change a product's price from a date (admins)

`POST https://staging-api.naruskacrm.com/v1/products/{id}/prices`

Ends the current price of the currency at `valid_from` and starts this one, in one call. A price that already starts on or after that date is refused: change that one instead.

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |

### Request body

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `currency` | string | yes |  |
| `unit_price` | number | yes | 0–1000000000000000 |
| `valid_from` | string (date) | yes |  |

### Response 201

Returns: [Product](/api/reference/objects.md#product).

Errors are problem details with a stable `code`: see [Errors](/errors.md).

## Restore a deleted product (admins)

`POST https://staging-api.naruskacrm.com/v1/products/{id}/restore`

### Parameters

| Parameter | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `id` | path | string (uuid) | yes |  |

### Response 200

Returns: [Product](/api/reference/objects.md#product).

Errors are problem details with a stable `code`: see [Errors](/errors.md).

