# Recipes (/recipes)

All examples read the key from the `AJOUR_API_KEY` environment variable. See [Quick start](/quick-start/).

## Daily turnover to a spreadsheet [#daily-turnover-to-a-spreadsheet]

Get the turnover per day for a month and save it as a CSV file. You can open the file in Excel, Numbers or Google Sheets.

```sh
curl -s "https://api.ajour.dk/v1/sales/breakdown?groupBy=day&from=2026-11-01&to=2026-11-30" \
  -H "Authorization: Bearer $AJOUR_API_KEY" \
  | jq -r '["date","quantity","turnover_dkk"], (.rows[] | [.key, .quantity, .turnover]) | @csv' \
  > turnover-november.csv
```

The same in Python:

```python
import csv, os, requests

response = requests.get(
    "https://api.ajour.dk/v1/sales/breakdown",
    params={"groupBy": "day", "from": "2026-11-01", "to": "2026-11-30"},
    headers={"Authorization": f"Bearer {os.environ['AJOUR_API_KEY']}"},
    timeout=60,
)
response.raise_for_status()

with open("turnover-november.csv", "w", newline="") as f:
    writer = csv.writer(f)
    writer.writerow(["date", "quantity", "turnover_dkk"])
    for row in response.json()["rows"]:
        writer.writerow([row["key"], row["quantity"], row["turnover"]])
```

Add `vat=exclude` to get turnover without VAT.

## Sales per location [#sales-per-location]

Compare your locations for a period, with last year's figures for the same weekdays:

```sh
curl "https://api.ajour.dk/v1/sales/breakdown?groupBy=location&from=2026-11-01&to=2026-11-30&compare=previousYear" \
  -H "Authorization: Bearer $AJOUR_API_KEY"
```

```json
{
  "groupBy": "location",
  "period": { "from": "2026-11-01", "to": "2026-11-30" },
  "currency": "DKK",
  "vat": "include",
  "rows": [
    { "key": "1031", "label": "Nørrebrogade", "quantity": 8120, "turnover": 301200.00, "share": 61.9,
      "previousYear": { "quantity": 7740, "turnover": 279850.00 } },
    { "key": "1032", "label": "Vesterbro", "quantity": 4760, "turnover": 185010.50, "share": 38.1,
      "previousYear": { "quantity": 4610, "turnover": 162020.00 } }
  ],
  "total": { "quantity": 12880, "turnover": 486210.50 }
}
```

Other values for `groupBy`: `productGroup`, `product`, `salesperson`, `hour`, `weekday`, `day` and `month`. Use `groupBy=product&limit=10` for the 10 most popular products.

## Download a report as PDF [#download-a-report-as-pdf]

The key needs the `reports:read` scope.

```sh
curl "https://api.ajour.dk/v1/reports/total-sales?from=2026-11-01&to=2026-11-30&format=pdf" \
  -H "Authorization: Bearer $AJOUR_API_KEY" \
  -o total-sales-november.pdf
```

If the key is limited to more than one location, a report must be for one location: add exactly one `locationId`. The reports `logbook-per-salesperson` and `client-card-balances` need a key for all locations.

Use `format=xlsx` for an Excel file. Call `GET /v1/reports` to see all report types and the filters each one accepts. A report can take up to 90 seconds to build.

## Copy all sales lines every night [#copy-all-sales-lines-every-night]

Store the newest `syncedAt` you have received. The next night, pass it as `syncedSince` and follow `nextCursor` until it is `null`.

```python
import os, requests

API = "https://api.ajour.dk/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['AJOUR_API_KEY']}"}

def fetch_new_lines(from_date, to_date, synced_since):
    params = {"from": from_date, "to": to_date, "syncedSince": synced_since, "limit": 1000}
    while True:
        page = requests.get(f"{API}/sales", params=params, headers=HEADERS, timeout=60)
        page.raise_for_status()
        body = page.json()
        yield from body["data"]
        if not body["nextCursor"]:
            break
        params["cursor"] = body["nextCursor"]
```

A register can send sales some time after the sale. So ask for a few days back with `from`, and use `syncedSince` to skip lines you already have. Use `id` to find duplicates.

## Power BI and Excel [#power-bi-and-excel]

Power BI and Excel can read the API with **Power Query**. Use **Get Data → Blank query**, open the **Advanced editor**, and paste:

```text
let
    ApiKey = "ajr_live_...",
    Response = Json.Document(
        Web.Contents(
            "https://api.ajour.dk/v1/sales/breakdown",
            [
                Query = [groupBy = "day", from = "2026-11-01", to = "2026-11-30"],
                Headers = [Authorization = "Bearer " & ApiKey]
            ]
        )
    ),
    Rows = Table.FromRecords(Response[rows])
in
    Rows
```

When Power BI asks how to connect, choose **Anonymous**. The key is already in the header.

<Callout type="warn">
Anyone who can open the file can read the key. Share the file only with people who may see the data. Use a key with only the scopes and locations they need.
</Callout>