# Change device configuration

Applies one shared `firmware` and/or `metadata` change to up to **100** devices, identified by
`qrcode`. Each device can also get its own `asset_barcode` and `tape_displayname`.
### Headers
The account comes from your access token. Send `customer_id` and `authorized_group` only when your
API identity has access to more than one account.
### What you can change
- **`firmware`**: device firmware settings. Every firmware field you send must be enabled for
the device's application. Trackonomy enables firmware fields for your application during
onboarding. If a field isn't enabled for the application of any device in the request, the whole
request returns `400` with `errorCode: FIELD_NOT_ENABLED` and nothing is changed. Contact your
Trackonomy integration contact to enable more fields.
- **`metadata`**: descriptive device fields (facility, APN, battery and version details).
- **Per device**: `asset_barcode` and `tape_displayname` in each `devices[]` entry.

`firmware` and `metadata` are strict lists. Any other key returns `400`, and so does a value
of the wrong type or format. Fields you omit are left unchanged. For
`firmware` and `metadata` fields, `null` clears the value. For the per-device
`asset_barcode` and `tape_displayname`, `null` or omitting the field keeps the current value.
### How the request is processed
- The whole request is validated first, in this order: the envelope (`devices`, `firmware`,
`metadata`), then the `firmware` fields, then the `metadata` fields. The first group that
fails is reported with `400`, and nothing is changed. For `firmware` and `metadata` problems,
each error's `path` is relative to that object (for example `["heartbeatFreq"]`).
- Devices are then looked up in your account. A `qrcode` that isn't found is reported as
`DEVICE_NOT_FOUND`. The firmware-field check and the `facility_id` check apply only to the
devices that were found. If no device is found, the response is `207` with every device in
`errors`.
- The change is applied to every found device. A found device counts as successful even
when the request changes nothing on it (for example `"firmware": {}`).

### `error_code` values
| Value | Meaning | What to do |
|  --- | --- | --- |
| `DEVICE_NOT_FOUND` | No device has this exact `qrcode` (case-sensitive) in your account, or the device belongs to an application or facility your account can't use. Devices are found in any status, so a deactivated device can still be configured. | Check the QR code and the account. |

### Retries
Sending the same configuration again gives the same result, so a request can be safely
repeated. After a `500`, part of the change may already have been applied. Resend the same
request.

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

## Description:

  - `Headers` ()
    The account comes from your access token. Send customer_id and authorized_group only when yourAPI identity has access to more than one account.

  - `What you can change` ()
    firmware: device firmware settings. Every firmware field you send must be enabled forthe device's application. Trackonomy enables firmware fields for your application duringonboarding. If a field isn't enabled for the application of any device in the request, the wholerequest returns 400 with errorCode: FIELD_NOT_ENABLED and nothing is changed. Contact yourTrackonomy integration contact to enable more fields.metadata: descriptive device fields (facility, APN, battery and version details).Per device: asset_barcode and tape_displayname in each devices[] entry. firmware and metadata are strict lists. Any other key returns 400, and so does a valueof the wrong type or format. Fields you omit are left unchanged. Forfirmware and metadata fields, null clears the value. For the per-deviceasset_barcode and tape_displayname, null or omitting the field keeps the current value.

  - `How the request is processed` ()
    The whole request is validated first, in this order: the envelope (devices, firmware,metadata), then the firmware fields, then the metadata fields. The first group thatfails is reported with 400, and nothing is changed. For firmware and metadata problems,each error's path is relative to that object (for example ["heartbeatFreq"]).Devices are then looked up in your account. A qrcode that isn't found is reported asDEVICE_NOT_FOUND. The firmware-field check and the facility_id check apply only to thedevices that were found. If no device is found, the response is 207 with every device inerrors.The change is applied to every found device. A found device counts as successful evenwhen the request changes nothing on it (for example "firmware": {}).

  - `error_code values` ()
    ValueMeaningWhat to doDEVICE_NOT_FOUNDNo device has this exact qrcode (case-sensitive) in your account, or the device belongs to an application or facility your account can't use. Devices are found in any status, so a deactivated device can still be configured.Check the QR code and the account.

  - `Retries` ()
    Sending the same configuration again gives the same result, so a request can be safelyrepeated. After a 500, part of the change may already have been applied. Resend the samerequest.

## Security:

  - `bearerAuth` (unknown)
    http bearer JWT

## Header parameters:

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

  - `customer_id` (string)
    Only needed when your API identity has access to more than one account. Send it together
with `authorized_group` to choose the account. When your identity has a single account,
omit both headers: the account comes from the access token.

  - `authorized_group` (string)
    Only needed when your API identity has access to more than one account; send it together
with `customer_id`. `authorized_groups` is accepted as the same header.

## Request fields (application/json):

  - `devices` (array, required)
    1 to 100 devices. Each `qrcode` may appear only once (duplicates return `400`).

  - `devices.qrcode` (string, required)
    QR code of the device. Leading and trailing spaces are removed; otherwise matched exactly (case-sensitive).
    Example: TRK0012345

  - `devices.asset_barcode` (string)
    New asset barcode for this device. `null` or omitted keeps the current value.
    Example: PALLET-0042

  - `devices.tape_displayname` (string)
    New display name for this device. `null` or omitted keeps the current value.
    Example: Pallet 42 sensor

  - `firmware` (object)
    Firmware settings applied to every found device. Every field is optional. Only the fields
listed here are accepted, and any other key returns `400`. Each field you send must also be
enabled for the device's application during onboarding (otherwise `400` `FIELD_NOT_ENABLED`).
No value ranges are enforced. Number fields accept a JSON number or a numeric string.
Text fields must be JSON strings, and a JSON number in a text field returns `400`.

  - `firmware.zone_id` (any)
    Zone id. Whole number.

  - `firmware.timeoutPeriod` (any)
    A number. A numeric string such as `"300"` is also accepted and converted to a number. `null` clears the value.

  - `firmware.heartbeatFreq` (string)
    Text.
    Example: 600

  - `firmware.bsfid` (string)
    Hexadecimal text, 1 to 8 characters.
    Example: 0

  - `firmware.bafid` (string)
    Hexadecimal text, 1 to 8 characters.
    Example: 0

  - `firmware.gsd` (string)
    A number written as text, for example `"60"`.
    Example: 60

  - `firmware.gpslogging` (string)
    GPS logging on (`Y`) or off (`N`). Case-sensitive.
    Enum: "Y", "N", "null"

  - `firmware.dlat` (any)
    Geofence centre latitude.

  - `firmware.dlon` (any)
    Geofence centre longitude.

  - `firmware.drad` (string)
    Geofence radius, as a number written as text, for example `"500"`.
    Example: 500

  - `firmware.batTh` (string)
    Text.
    Example: 20

  - `metadata` (object)
    Descriptive fields applied to every found device. Every field is optional, and `null` clears
the value. Only the fields listed here are accepted, and any other key (for example
`displayname`, `asset_barcode` or `rssi_threshold`) returns `400`. Set `asset_barcode` and
`tape_displayname` per device in `devices[]` instead.

  - `metadata.facility_id` (string)
    Facility to assign: the facility's UUID or its designation (for example `DC-EAST`). It must
name a facility in your account or a facility Trackonomy provides to every account. Otherwise the whole request returns `400`
`facility not found: <value>` and nothing is changed. `null` removes the device's facility.
    Example: DC-EAST

  - `metadata.apn` (string)
    Example: iot.example

  - `metadata.track_number` (string)
    Example: TRK-000123

  - `metadata.battery_type` (string)
    Example: LiSOCl2

  - `metadata.battery_level` (any)
    Battery level. No range is enforced.

  - `metadata.fw_version` (string)
    Example: 2.4.1

  - `metadata.hw_version` (string)
    Example: 1.2

  - `metadata.sw_version` (string)
    Example: 3.0.0

  - `metadata.rssi_priority` (any)
    RSSI priority. Whole number.

## Request examples:

  - `Every field; each firmware field must be enabled for your application` (unknown)

  - `One firmware field on one device` (unknown)

  - `Metadata and per-device fields with one unknown QR code, see the 207 example` (unknown)

  - `Numeric firmware and metadata values sent as strings` (unknown)

## Response 200:

  - `200` (unknown)
    Every device in the request was found and updated.

## Response 200 fields (application/json):

  - `message` (string, required)
    `Successfully <action> <n> device(s).` when every device succeeded, otherwise `Some devices could not be <action>.`
    Example: Missing required headers: customer_id or authorized_groups

  - `successful` (integer, required)
    Number of devices that succeeded.
    Example: 1

  - `failed` (integer, required)
    Number of devices that failed.
    Example: 0

  - `errors` (array, required)
    One entry per failed device. Empty when every device succeeded.

  - `errors.qrcode` (string, required)
    QR code of the device that failed.
    Example: TRK0012345

  - `errors.error_code` (string, required)
    Machine-readable reason. Branch on this value, not on `message`.
    Example: ALREADY_LABELLED

## Response 207:

  - `207` (unknown)
    At least one `qrcode` wasn't found. This is also returned when no device was found, with
`successful: 0`. Every device that was found was updated.

## Response 207 fields (application/json):

  - `message` (string, required)
    `Successfully <action> <n> device(s).` when every device succeeded, otherwise `Some devices could not be <action>.`
    Example: Missing required headers: customer_id or authorized_groups

  - `successful` (integer, required)
    Number of devices that succeeded.
    Example: 1

  - `failed` (integer, required)
    Number of devices that failed.
    Example: 0

  - `errors` (array, required)
    One entry per failed device. Empty when every device succeeded.

  - `errors.qrcode` (string, required)
    QR code of the device that failed.
    Example: TRK0012345

  - `errors.error_code` (string, required)
    Machine-readable reason. Branch on this value, not on `message`.
    Example: ALREADY_LABELLED

## Response 400:

  - `400` (unknown)
    The request was rejected and no device was changed. Possible causes:
- the body failed validation (`Validation failed`);
- a firmware field isn't enabled for the application of a device in the request
(`errorCode: FIELD_NOT_ENABLED`; `violations` lists each application and its fields);
- `metadata.facility_id` doesn't match a facility in your account or one Trackonomy provides;
- your API identity has access to several accounts and the request didn't say which one.

## Response 400 fields (application/json):

  - `message` (string, required)
    Example: Validation failed

  - `code` (integer, required)
    Example: 400

  - `errors` (array, required)
    One entry per problem. Each entry has the `path` of the field that failed, a `message` and
an issue `code`; some issues add detail such as `expected`, `values`, `minimum`, `maximum`,
`inclusive`, `origin`, `format` or `pattern`.

  - `errors.path` (array)

  - `errors.message` (string)
    Example: Missing required headers: customer_id or authorized_groups

  - `errors.code` (string)
    Example: invalid_type

  - `message` (string, required)
    `Firmware fields not enabled for this application: <application> (<fields>)`, one entry per application, separated by `; `.
    Example: Missing required headers: customer_id or authorized_groups

  - `errorCode` (string, required)
    Enum: "FIELD_NOT_ENABLED"

  - `violations` (array, required)

  - `violations.application` (string, required)
    Code of the application whose devices don't have these fields enabled.
    Example: smart-tape

  - `violations.fields` (array, required)
    The requested firmware fields that aren't enabled for that application.
    Example: ["dlat"]

  - `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 403:

  - `403` (unknown)
    The `customer_id` / `authorized_group` pair isn't one of the accounts your API identity can access, or the identity has no account.

## Response 403 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 429:

  - `429` (unknown)
    More than 10 requests in 60 seconds from your API identity. The limit is shared by label,
edit label, get labels, deactivate and configuration calls. Wait and retry with backoff.

## Response 429 fields (application/json):

  - `message` (string)
    Example: Missing required headers: customer_id or authorized_groups

## Response 500:

  - `500` (unknown)
    An unexpected error occurred. Part of the change may already have been applied. Resend the
same request.

## 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 503:

  - `503` (unknown)
    Trackonomy couldn't resolve your account access. Temporary; retry with exponential backoff.

## Response 503 fields (application/json):

  - `message` (string)
    Example: Missing required headers: customer_id or authorized_groups

  - `code` (integer)
    Example: 400

  - `success` (boolean)
    Example: false

## Response 200 examples:

  - `Response to the all-fields request` (unknown)

## Response 207 examples:

  - `Response to the metadata-with-unknown-device request` (unknown)

  - `No device found` (unknown)

## Response 400 examples:

  - `Neither firmware nor metadata sent` (unknown)

  - `The same qrcode listed twice` (unknown)

  - `The `firmware` value is not an object` (unknown)

  - `Field that isn't on the list, rssi_threshold` (unknown)

  - `Text field sent as a number, heartbeat frequency` (unknown)

  - `Number field dlat that isn't numeric` (unknown)

  - `Value in the wrong format, bsfid must be hexadecimal` (unknown)

  - `Invalid gpslogging value` (unknown)

  - `Firmware field not enabled for the application` (unknown)

  - `Unknown facility_id` (unknown)

  - `Identity with several accounts sent no account headers` (unknown)

## Response 403 examples:

  - `Account headers outside your access` (unknown)

  - `Identity has no account access` (unknown)

