# Ajour Public API endpoints

All paths are relative to `https://api.ajour.dk/v1`. The full OpenAPI file is https://docs.ajour.dk/openapi/public-v1.json.

## Shared sales filters

Used by `/sales/summary`, `/sales/breakdown`, `/sales` and `/reports/{reportType}`.

| Parameter | Type | Notes |
| --- | --- | --- |
| `from`, `to` | date, required | local dates in Europe/Copenhagen, `to` included |
| `locationId` | integer, repeatable | must be inside the key's locations |
| `productGroupId` | string | POS product group number |
| `productId` | string, repeatable | POS product numbers |
| `orderType` | `pos`, `online`, `invoice`; repeatable | |
| `salesperson` | string | name as on the register |
| `vat` | `include` (default) or `exclude` | |

## GET /company

Any scope. Response:

```json
{
  "id": 412,
  "name": "Café Nørrebro ApS",
  "cvr": "12345678",
  "currency": "DKK",
  "timeZone": "Europe/Copenhagen",
  "workHours": { "start": "07:00", "end": "23:00" },
  "key": { "keyId": "7Kq2Vx9b", "scopes": ["catalog:read", "sales:read"], "locationIds": null }
}
```

## GET /locations

`catalog:read`. `data[]`: `id` (integer), `name`, `lastSyncedAt` (newest sales upload).

## GET /product-groups

`catalog:read`. Parameters: `updatedSince`, `limit`, `cursor`. `data[]`: `id` (POS number, string), `name`, `updatedAt`.

## GET /products and GET /products/{productId}

`catalog:read`. Parameters: `productGroupId`, `updatedSince`, `limit`, `cursor`. Fields: `id`, `name`, `productGroupId`, `kind`, `salesPrice`, `costPrice`, `vatPercent`, `barcode`, `trackStock`, `stock`, `updatedAt`.

## GET /salespersons

`sales:read`. `data[]`: `name`. Only names found on sales in the last 13 months.

## GET /sales/summary

`sales:read`. Shared filters, plus `metrics` (repeatable) and `compare=previousYear`. Max 366 days.

```json
{
  "period": { "from": "2026-11-01", "to": "2026-11-21" },
  "currency": "DKK",
  "vat": "include",
  "metrics": {
    "totalTurnover": 486210.50, "posTurnover": 451900.00, "onlineTurnover": 34310.50,
    "transactions": 6120, "averageTransaction": 79.45, "discount": 8120.00, "returns": 1340.00,
    "contributionMargin": 301455.20, "contributionMarginPercent": 62.0
  },
  "previousYear": { "period": { "from": "2025-11-02", "to": "2025-11-22" }, "metrics": { "totalTurnover": 441870.00 } }
}
```

## GET /sales/breakdown

`sales:read`. Required `groupBy`: `productGroup`, `product`, `location`, `salesperson`, `hour`, `weekday`, `day`, `month`. Shared filters, plus `limit` (top N) and `compare=previousYear`. Max 366 days. Rows are sorted by turnover, except time groupings, which are sorted by time. `hour` only returns the company's work hours.

```json
{
  "groupBy": "productGroup",
  "period": { "from": "2026-11-01", "to": "2026-11-21" },
  "currency": "DKK",
  "vat": "include",
  "rows": [{ "key": "10", "label": "Kaffe", "quantity": 7410, "turnover": 288340.00, "share": 59.3 }],
  "total": { "quantity": 12880, "turnover": 486210.50 }
}
```

`key` is the POS number, location id, salesperson name, hour (`0`-`23`), weekday (`1` = Monday), date or month (`2026-11`).

## GET /sales

`sales:read`. Shared filters, plus `syncedSince`, `limit`, `cursor`. Max 92 days. Sorted by date, then id. Lines with the same `receiptNumber` and `locationId` make one receipt.

Fields: `id`, `locationId`, `date`, `receiptNumber`, `orderType`, `lineType`, `product { id, name }`, `productGroupId`, `quantity`, `unitPrice`, `discount`, `amountInclVat`, `amountExclVat`, `isReturn`, `salesperson`, `clientId`, `syncedAt`.

## GET /reports

`reports:read`. `data[]`: `type`, `name`, `formats`, `filters`.

## GET /reports/{reportType}

`reports:read`. Returns a file. `format=pdf` (default) or `xlsx`. Shared filters, plus `clientCode` and `cardType` where the report uses them. A key limited to several locations must pass exactly one `locationId`. `logbook-per-salesperson` and `client-card-balances` need a key for all locations.

Report types: `total-sales`, `total-sales-per-date`, `total-sales-per-product-group`, `sales-per-date-and-time`, `sales-per-date-time-and-product`, `sales-per-salesperson`, `sales-per-salesperson-avg-sales-per-expedition`, `sales-returns-per-salesperson`, `turnover-per-guest`, `logbook-per-salesperson`, `sales-per-client` (needs `customers:read`), `client-card-balances` (needs `customers:read`).
