# Decode packets from many devices

Decodes up to 250 BLE packets, one per tape, in one call. Each item is processed the
same way as `POST /external/v1/devices/{mac_id}/decode`, and an item that fails does not
affect the others.
**Headers.** `customer_id` and `authorized_groups` (plural) are required and apply to
every item. Send `Content-Type: application/json`.
**Request checks** (in this order). Any failure rejects the whole request and no item is
processed:
1. The body is not valid JSON, or is larger than 50 MB → `401`.
2. `customer_id` or `authorized_groups` missing → `400`.
3. The body is not a non-empty JSON array → `400`.
4. More than 250 items → `413`.
5. Two items have the same `mac_id` (exact, case-sensitive comparison) → `400`. Two
items that both leave out `mac_id` also count as duplicates.

Every array element must be an object; a `null` element, or a request sent without a
JSON body, gets `500`.
**Results.** After those checks the response is `200` with one result per item, **in
the order of the request**. A decoded item is the single-device response plus `mac_id`.
A failed item is `{mac_id, error}`, where `error` is the message the single-device
endpoint would return for it (see the table there). An item sent without `mac_id`
fails with `Missing required mac address`, and its result has no `mac_id`.
**Per-item error messages:**
| `error` | What to do |
|  --- | --- |
| `Missing required mac address` | Add `mac_id` to the item. |
| `Missing required BLE packet` | Add `ble_packet` to the item. |
| `Invalid BLE packet. <reason>` | The packet could not be decoded. Check what your scanner captured; do not resend it unchanged. |
| `Invalid tape mac address` | The MAC is not a Trackonomy tape. |
| `Tape not associated under the current customer` | The tape is not labelled under this `customer_id` / `authorized_groups`. |

**Retries.** Resend only the failed items, after fixing them. The retry guidance of the
single-device endpoint applies to every item.

Endpoint: POST /external/v1/devices/decode
Version: 2.2
Security: bearerAuth

## Security:

  - `bearerAuth` (unknown)
    http bearer JWT

## Header parameters:

  - `customer_id` (string, required)
    Customer ID of the account the tape is labelled under. Required; missing or empty → `400`. Matched exactly (case-sensitive).

  - `authorized_groups` (string, required)
    Authorized group of the account the tape is labelled under. Required; missing or empty →
`400`. Note the **plural** header name: the singular `authorized_group` is not read here.
Matched exactly (case-sensitive).

  - `correlation_id` (string)
    Optional request ID. Trackonomy records it with the request so support can trace a call you report.

## Request fields (application/json):

  - `mac_id` (string, required)
    The tape's MAC address (12 hex characters, no separators). Must be unique within the request.
    Example: D4F5A1B2C3E8

  - `ble_packet` (string, required)
    The raw BLE payload as a hex string (see the `ble_packet` header of the single-device endpoint).
    Example: 525801172D0000012C0C0300000096000000012C00FFAC1E

  - `product_id` (string)
    Optional application ID (see the `product_id` header of the single-device endpoint).
    Example: 7b1e4c2a-9f3d-4e8a-b6c1-2d5f8a9e0c31

  - `scan_time` (any)
    Optional capture time in Unix epoch seconds, as a number or a numeric string.
    Example: 1791245700

## Request examples:

  - `All fields` (unknown)
    Every item sets all four fields. The list holds a full packet, a heartbeat and a
MAC that is not a Trackonomy tape, so the response shows each result shape.
`scan_time` may be a number or a numeric string.

  - `Minimal request with one item and required fields only` (unknown)

  - `Items that each fail` (unknown)

## Response 200:

  - `200` (unknown)
    One result per item, in request order.

## Response 200 fields (application/json):

  - `mac_id` (string)
    Example: D4F5A1B2C3E8

  - `qr_code` (string, required)
    The tape's QR code.
    Example: TRK8F3A21C7

  - `cts` (integer, required)
    Time Trackonomy decoded the packet, in Unix epoch seconds (not a device time). `null` for `4442` and `0202` packets.
    Example: 1791245815

  - `ts` (integer, required)
    The `scan_time` you sent, as an integer. `null` when it was missing or not numeric.
    Example: 1791245700

  - `bat` (number, required)
    Tape battery voltage, in volts. `null` for `4442` and `0202` packets.
    Example: 3

  - `temp` (any)
    Current temperature in °C. A number for most packets; a **string** (e.g. `"25.0"`) for
`FFF9` packets. Absent when the packet carries no temperature.
    Example: 23

  - `over_temp` (number)
    Recorded over-temperature excursion, in °C. Present only when the packet reports one.
    Example: 45

  - `over_temp_ts` (integer)
    Estimated time of the over-temperature excursion, in Unix epoch seconds, worked out from `scan_time`. Present with `over_temp`; `null` when `scan_time` was not sent.
    Example: 1791245100

  - `shock` (string)
    Maximum shock magnitude in raw device units, as a numeric **string**. Present only when the packet reports a shock.
    Example: 12

  - `shock_ts` (integer)
    Estimated time of the shock, in Unix epoch seconds, worked out from `scan_time`. Present with `shock`; `null` when `scan_time` was not sent.
    Example: 1791245400

  - `bat_percent` (number, required)
    Battery state of charge (0–100), from the tape's battery type and the decoded voltage and temperature. `null` when it cannot be worked out.
    Example: 100

  - `fw_ver` (any)
    Firmware version Trackonomy has for the tape. Usually a string (e.g. `"1.1"`); a number
(e.g. `1.2`) once the tape has reported its firmware in a heartbeat. Absent when no
version is known.
    Example: 1.1

  - `cts` (integer, required)
    Time Trackonomy decoded the packet, in Unix epoch seconds.
    Example: 1791245815

  - `bat` (number)
    Battery voltage from the packet, in volts. Absent for heartbeat types that carry no battery reading.
    Example: 3

  - `fw_ver` (number)
    Firmware version from the packet, as a **number** (e.g. `1.2`). Absent for heartbeat types that carry no version.
    Example: 1.2

  - `bat_percent` (number, required)
    Battery state of charge (0–100). `null` when it cannot be worked out.
    Example: 100

  - `mac_id` (string)
    The item's `mac_id`, as sent. Absent when the item had none.
    Example: E7A01B9C44D2

  - `error` (string, required)
    The message the single-device endpoint would return for this item.
    Example: Invalid tape mac address

## Response 400:

  - `400` (unknown)
    The request failed a request check. No item was processed.

## Response 400 fields (application/json):

  - `message` (string, required)
    What went wrong.
    Example: Missing required headers: customer_id or authorized_groups

  - `code` (integer)
    The HTTP status code.
    Example: 400

## Response 401:

  - `401` (unknown)
    The access token is missing, expired, issued for another environment's audience, or your API
identity isn't granted this action. The same response is returned when the request body isn't
valid JSON or is larger than 50 MB. Check the body, request a new token and retry once; if it
still fails, contact your Trackonomy integration contact.

## Response 401 fields (application/json):

  - `message` (string, required)
    What went wrong.
    Example: Missing required headers: customer_id or authorized_groups

  - `code` (integer)
    The HTTP status code.
    Example: 400

## Response 413:

  - `413` (unknown)
    More than 250 items. The message gives the limit and the number of items received. Split the request.

## Response 413 fields (application/json):

  - `message` (string, required)
    What went wrong.
    Example: Missing required headers: customer_id or authorized_groups

  - `code` (integer)
    The HTTP status code.
    Example: 400

## Response 500:

  - `500` (unknown)
    The request had no JSON body (for example, `Content-Type` was not `application/json`)
or an array element was `null`. Fix the request and resend it.

## Response 500 fields (application/json):

  - `message` (string, required)
    What went wrong.
    Example: Missing required headers: customer_id or authorized_groups

  - `code` (integer)
    The HTTP status code.
    Example: 400

## Response 200 examples:

  - `Response to the all-fields request` (unknown)
    A full-packet result, a heartbeat result and a failed item.

  - `Response to the minimal request: without scan_time, ts and the *_ts fields are null` (unknown)

  - `Response to the item-errors request` (unknown)
    Unknown packet prefix; a registered tape that is not labelled under this account.

## Response 400 examples:

  - `Missing `customer_id` or `authorized_groups` header` (unknown)

  - `Body is an object or an empty array` (unknown)

  - `Two items share a mac_id` (unknown)

