# Channel API (TSHIRTORDER-1668)

Create, read, update and delete channels. A channel holds the settings for invoicing, the ecom page, integrations and prepaid.
Prepaid has its own document: [prepaid-api.md](prepaid-api.md).

| Method | URL | Purpose |
|---|---|---|
| `GET` | `/api/v1/channels/` | List channels |
| `POST` | `/api/v1/channels/` | Create a channel |
| `GET` | `/api/v1/channels/{id}` | Channel detail |
| `POST` | `/api/v1/channels/{id}` | Update a channel (partial: only the keys you send) |
| `DELETE` | `/api/v1/channels/{id}` | Soft delete a channel |

| | |
|---|---|
| **Auth** | `Authorization: Bearer <access token>` (32 chars, `[0-9a-z]`) |
| **Content-Type** | `application/json`, or `multipart/form-data` when uploading images |
| **Controller** | `ChannelController` → `ChannelService` |

> Request data is the merge of JSON body, form body and query string
> (`ApiService::getRequestData()`). On a duplicate key the query string wins, then the form body.

## Authentication and access

- Missing / malformed / unknown / expired token → `401 {"message": "Invalid token authorization"}`.
- A token flagged `lockForOnlyIntegration` is **rejected** by these endpoints (they are not integration endpoints).
- `ROLE_CHANNEL` (guest accounts):
  - `GET /channels/` only returns the channels the account is linked to.
  - `GET /channels/{id}` on any other channel returns `403 {"message": "Not allowed"}`.
  - Create, update and delete always return `403`.
  - A removed link (`dateDeleted` set) does not count.
- Other roles have full access.
- ⚠️ Except for guest accounts, responses contain integration secrets in plain text (see [Sensitive fields](#sensitive-fields)).

---

## List channels

`GET /api/v1/channels/`

### Query parameters

| Param | Type | Notes |
|---|---|---|
| `limit` | int | Default `100`, no maximum |
| `offset` | int | Default `0` |
| `q` | string | Case-insensitive search in `channelName`, `channelShortName`, `synId`, `name`, `slug` |
| `channelName` | string | Case-insensitive search in `channelName`, `channelShortName` |
| `id` | int | Exact id |
| `ids` | int[] | Only these ids, e.g. `?ids[]=14&ids[]=88`. Ignored for guest accounts, which always get their own channels |
| `active`, `showOnDropdown`, `kickbackInvoiceActive`, `shopifySyncOrder`, `shopifySyncProduct`, `wooSyncStockActive` | string | `true` matches enabled channels. **Any other value** matches disabled channels |
| `wooSyncStockIntervalIn` | int[] | `wooSyncStockInterval` is one of these values |
| `availableForKickbackInvoice` | any | Non-empty: `kickbackInvoicePeriodInterval` and `kickbackInvoiceNrOfMonth` are both above 0 |
| `shopify_run_clone_command` | any | Present: `shopifyAccessToken` and `shopifyUrl` are both set |

Sorted by `id`, newest first. `sort_by` is not implemented.

### 200 OK

A plain array of [channel objects](#channel-object). There is no `total` field, so page until a page returns fewer rows than `limit`.

---

## Create a channel

`POST /api/v1/channels/`

### Required

| Field | Type | Notes |
|---|---|---|
| `channelName` | string | NotNull |
| `channelShortName` | string | NotNull, unique |
| `name` | string | NotNull |

### Example

```http
POST /api/v1/channels/
Authorization: Bearer 0123456789abcdef0123456789abcdef
Content-Type: application/json

{
  "channelName": "ACME Shop",
  "channelShortName": "ACME",
  "name": "ACME AB",
  "type": "PDO",
  "active": true,
  "orderStatusId": 22,
  "address": "Storgatan 1",
  "postNr": "111 22",
  "city": "Stockholm",
  "country": "SE",
  "invoiceOncePerMonth": false,
  "invoiceIndividual": true
}
```

### 200 OK

The new [channel object](#channel-object). `countNr` is generated by the server.

---

## Channel detail

`GET /api/v1/channels/{id}`

Returns one [channel object](#channel-object), or `404 {"message": "Channel not found"}` when the channel does not exist or is deleted.

---

## Update a channel

`POST /api/v1/channels/{id}`

Same fields as create, all optional. Keys you do not send keep their value, except for the lists described in [List fields](#list-fields). The channel is validated as a whole, so the [validation rules](#errors) must hold after the update even for fields you did not send.

```http
POST /api/v1/channels/101
Authorization: Bearer 0123456789abcdef0123456789abcdef
Content-Type: application/json

{ "active": false, "defaultShippingFee": 79 }
```

Returns the updated [channel object](#channel-object).

---

## Delete a channel

`DELETE /api/v1/channels/{id}`

Soft delete: sets `dateDeleted`. The channel disappears from list and detail. Its orders, products and other data are not touched.

```json
{ "message": "Channel was deleted" }
```

Returns `404 {"message": "Channel not found"}` when the channel does not exist or is already deleted.

---

## Writable fields

### General

| Field | Type | Notes |
|---|---|---|
| `channelName`, `channelShortName`, `name` | string | See [required fields](#required) |
| `type` | string | `PDO`, `SPEC`, `ECOM` or null |
| `active` | bool | Defaults to `false` |
| `address`, `postNr`, `city`, `country` | string | |
| `synId` | string | WooCommerce / WordPress link |
| `color` | string | |
| `orderStatusId` | int | `StatusList` of type `order_status`. Fills `orderStatus` automatically |
| `defaultPaymentTypeId` | int | `StatusList` of type `order_payment_type`. Fills `defaultPaymentType` automatically |
| `deliveryTypeId` | int | `StatusList` of type `order_delivery_type`. Fills `deliveryType` automatically |
| `defaultVarReference`, `defaultShippingFee`, `defaultPostnordLabelValue` | | Order defaults |
| `bulkOrderDefaultCustomerId`, `locationId` | int | |
| `pdfFooterText`, `offertText`, `textBlock` | string | |
| `importType`, `importPrice` | string, bool | Order import |
| `defaultProductProcentagePod`, `defaultProductProcentageStock` | number | |
| `codeMoms25`, `codeMoms12`, `codeMoms6` | string | Accounting codes |

### Behaviour switches (bool)

`switchOrderNrOrderCountNr`, `useChannelAsSenderProfile`, `hideOrderPdf`, `showOnDropdown`, `poddyList`, `defaultCheckboxAutoSendEmailAfterCreatePostnordLabel`

### Invoicing and kickback

| Field | Type | Notes |
|---|---|---|
| `invoiceOncePerMonth`, `invoiceIndividual` | bool | Only one may be on. A channel where `invoiceOncePerMonth` was never set counts as **on** |
| `kickbackInvoiceActive`, `kickbackInvoiceSeparateByBrand` | bool | |
| `kickbackInvoicePeriodInterval`, `kickbackInvoiceNrOfMonth` | int | |

### Guest accounts (`ROLE_CHANNEL`) (bool)

`guestLoginAddOrder`, `guestLoginAddProduct`, `guestLoginShowKickback`, `guestLoginShowPrepaid`, `guestLoginProduction`, `guestKickbackInvoice`

### Ecom page

| Field | Type | Notes |
|---|---|---|
| `showOnEcom` | bool | When `true`, `slug` is required |
| `slug` | string | Unique |
| `ecomTemplate` | string | `standard`, `niclas`, `nakata` |
| `ecomColor`, `ecomColorBackground`, `ecomColorBackgroundText`, `ecomColorForText`, `ecomColorBoxes`, `ecomFooterBackgroundColor`, `ecomHeaderBackgroundColor`, `ecomMenuTextColor` | string | |
| `ecomMenuFontSize`, `ecomFontFamily`, `ecomFooterText`, `ecomShippingText`, `ecomGTM` | string | |
| `ecomShowLogoOnTopLeft`, `bannerShowFullWidth` | bool | |
| `bannerLink`, `bannerLink2`, `bannerLink3` | string | |
| `shippingFeeEcomIncTax` | number | Writable, but not returned in the response |

### Integrations

| Field | Type |
|---|---|
| `shopifyApiKey`, `shopifySecretKey`, `shopifyAccessToken`, `shopifyUrl` | string |
| `shopifySyncOrder`, `shopifySyncProduct` | bool |
| `sveaAllowImport` | bool |
| `sveaAccessToken`, `sveaMerchantId`, `sveaMerchantSecret` | string |
| `postnordUseSubAccount` | bool |
| `postnordApiKey`, `postnordCustomerNumber` | string |
| `wooSyncStockActive` | bool |
| `wooSyncStockInterval` | int: `1` night only, `2` night + afternoon, `3` night + noon + afternoon |

### Prepaid

`prepaidActive`, `prepaidWatcherLevel`, `prepaidDateString`. See [prepaid-api.md](prepaid-api.md). `prepaidSum` and `prepaidCurrentSum` are ignored here.

### Images

Send a file with `multipart/form-data`, or a string with an existing path.

| Field in the request | Saved as |
|---|---|
| `logo` (file) or `logoImage` (string path) | `logo` |
| `ecomLogo`, `ecomFavicon`, `banner`, `bannerMobile`, `banner2`, `banner3` | Same name |

### List fields

Each list is only touched when its key is sent. When it is sent, **it replaces the whole list**: rows you leave out are removed, so an empty list removes all rows.

| Field | Item | Notes |
|---|---|---|
| `productCategoryIds` | int | Unknown ids are skipped |
| `wikiPageIds` | int | Only pages with `showOnEcom` are linked |
| `ecomShippingTypes` | `{ id, name, shippingFeeIncTax, typeId }` | Omit `id` to create. `typeId` is a `StatusList` of type `channel_ecom_shipping_type`. The string `"[]"` also removes all (for multipart) |
| `bannerSets` | `{ id, name, position, type, status, block1Image…block4Image, block1Link…block4Link }` | Omit `id` to create. An image is a file or a string path, and an empty string removes it. The string `"[]"` also removes all |
| `linkIcons`, `linkNames`, `links`, `linkIds` | Four parallel arrays with the same keys | Returned as `ecomLinks`. All four keys must exist per row (use an empty `linkIds` value to create). A row with an empty `links` value is skipped, and so removed |

---

## Channel object

All endpoints return the same object: every writable field above (except `shippingFeeEcomIncTax`, `linkIcons`, `linkNames`, `links`, `linkIds`, `productCategoryIds`), plus:

| Field | Type | Notes |
|---|---|---|
| `id`, `countNr` | int | |
| `orderStatus`, `defaultPaymentType`, `deliveryType` | string | Name of the matching `...Id` |
| `kickbackInvoiceNextDateForCreate` | datetime \| null | Next kickback invoice date. `null` when `kickbackInvoiceNrOfMonth` is 0 or empty |
| `prepaidDate`, `prepaidSum`, `prepaidCurrentSum`, `prepaidLow`, `prepaidLogs` | | See [prepaid-api.md](prepaid-api.md) |
| `ecomLinks` | array | `{ id, name, link, icon }` |
| `channelUsers` | array | `ROLE_CHANNEL` users of this channel: `{ id, username, email, firstname, lastname, brandId, brandName, brandLogo }` |
| `productCategories` | array | `{ id, name }` |

Dates are ISO 8601 with offset, for example `2026-07-03T02:30:00+02:00`. Images are returned as paths.

### Shortened example

```json
{
  "id": 101,
  "countNr": 101,
  "channelName": "ACME Shop",
  "channelShortName": "ACME",
  "name": "ACME AB",
  "type": "PDO",
  "active": true,
  "orderStatus": "Ny order",
  "orderStatusId": 22,
  "invoiceOncePerMonth": false,
  "invoiceIndividual": true,
  "prepaidActive": true,
  "prepaidDate": "2026-07-03T02:30:00+02:00",
  "prepaidSum": 7000,
  "prepaidWatcherLevel": 1000,
  "prepaidCurrentSum": 5587.5,
  "prepaidLow": false,
  "wikiPageIds": [],
  "ecomLinks": [],
  "bannerSets": [],
  "channelUsers": [],
  "ecomShippingTypes": [],
  "prepaidLogs": [],
  "productCategories": [],
  "...": "..."
}
```

### Sensitive fields

`shopifyApiKey`, `shopifySecretKey`, `shopifyAccessToken`, `sveaAccessToken`, `sveaMerchantId`, `sveaMerchantSecret` and `postnordApiKey`:

- **Guest accounts (`ROLE_CHANNEL`):** removed from every response.
- **Other roles:** returned in plain text by every endpoint, including the list. ⚠️ Do not log these responses or forward them to a browser or a third party.

---

## Errors

| Status | Body | Cause |
|---|---|---|
| 400 | `{"<field>": "<message>"}` | Validation failed, see below |
| 401 | `{"message": "Invalid token authorization"}` | Bad token |
| 403 | `{"message": "Not allowed"}` | Guest account: write action, or a channel it is not linked to |
| 404 | `{"message": "Channel not found"}` | Unknown or deleted channel |
| 404 | Symfony "No route found" (not the JSON above) | `{id}` is not a number, e.g. `/channels/14abc` |
| 500 | `{"message": "<exception message>"}` | Unexpected error |

Validation rules:

| Field in the error | Rule |
|---|---|
| `channelName`, `channelShortName`, `name` | Must not be null |
| `channelShortName` | Unique |
| `slug` | Unique. Required when `showOnEcom` is on |
| `type` | `PDO`, `SPEC`, `ECOM` or null |
| `orderStatusId` | Must be an integer |
| `invoiceIndividual` | `Only one of "invoice once per month" and "invoice individual" can be enabled.` |

## Gotchas

- **Older channels can fail on any update.** A channel with both invoice options on returns `400` on every `POST /channels/{id}`, even with an empty body, until one option is turned off in the same request (`{"invoiceOncePerMonth": false}`).
- **New channel with `invoiceIndividual: true`:** also send `invoiceOncePerMonth: false`, because an unset value counts as on.
- **Invalid `prepaidDateString` on this endpoint gives no error.** The date is not saved and the request can still return `200`. In the same case `orderStatusId`, `defaultPaymentTypeId`, `productCategoryIds` and `deliveryTypeId` from that request are not fully applied. Always check the response.
- **Unknown ids are not always rejected:**
  - `orderStatusId` and `defaultPaymentTypeId`: the raw id is saved, while the name keeps its old value.
  - `deliveryTypeId`: the id becomes `0` and the name is cleared.
- **A failed image upload gives no error.** The request returns `200`, and the images after the failed one are not processed either.
- **Booleans:** `"true"`, `"false"` and JSON booleans work. Any other non-empty string, such as `"no"`, becomes `true`.
- **Any other key that matches a setter on the `Channel` entity is also written**, so do not forward untrusted client data blindly. A value of the wrong type can cause a `500`.
- Save an order status name or a payment type name through its `...Id` field, not through the name field.

## Related files

| File | Purpose |
|---|---|
| `src/Application/ApiBundle/Resources/config/route/channel.yaml` | Route definitions |
| `src/Application/ApiBundle/Controller/ChannelController.php` | Reads the request and uploaded files |
| `src/Service/ChannelService.php` | `list()`, `find()`, `add()`, `update()`, `delete()`, `generateItem()`, `generateUpdate()` |
| `src/Repository/ChannelRepository.php` | `query()`: list filters |
| `src/Entity/Channel.php` | Fields + validation rules |
