# Edit device labels

Edits existing labels and, optionally, their shipment, for up to 20 devices. A QR code with no
label in your account fails with `DEVICE_NOT_FOUND`; this call never creates a label. A device's
status is never changed (a `DEACTIVATED` device can be edited and stays deactivated).
**Headers.** Send `customer_id` and `authorized_group` only when your API identity has access to
more than one account.
### Device fields
For each listed device only the fields you send are written:
| Field | Omitted | `null` | Value |
|  --- | --- | --- | --- |
| `asset_barcode` | unchanged | cleared | replaced (must not be used by another device in your account) |
| `facility_id` | unchanged | cleared | replaced (must be a facility of your account) |
| `tape_displayname` | unchanged | cleared | replaced |
| `application_id` | unchanged | unchanged | must equal the device's current application; any other application fails with `APPLICATION_CHANGE_NOT_ALLOWED` |

**The application can't be changed by an edit.** `application_id` is accepted only so you can
confirm the current application. **Don't send it unless you need that check.** It must pass a
strict UUID format check (8-4-4-4-12 hex digits, the 13th digit `1`–`8` and the 17th digit `8`,
`9`, `a` or `b`), and most application ids, including ids returned by `GET`, don't. An id that
fails the check rejects the whole request with `400`.
### Shipment (`shipment_details`)
The target shipment is the shipment of the **first** device in `devices`. If that device has no
shipment, a new shipment is started. `scope` decides which devices receive the shipment update:
* `THIS_DEVICE` (default): only listed devices whose edit succeeded. A listed device (other than the
first) that already belongs to a **different** shipment fails with `SHIPMENT_CONFLICT` and is not
edited at all. Edit it in a separate call where it comes first.
* `ALL_DEVICES_IN_SHIPMENT`: every device in your account that carries the target shipment,
including devices you didn't list. A listed device that isn't in that shipment fails with
`NOT_IN_SHIPMENT`; its device fields (above) are still written. When the first device has no
shipment yet, this behaves like `THIS_DEVICE`.

`customer_name`, `customer_email`, `source_address` and `destination_address` are required.
`customer_contact`, `notes` and `mode_of_transport` keep their saved values when omitted or `null`.
An empty address (`{}`) keeps the saved location when one is saved; when the target shipment is
new, `{}` can't be resolved and the shipment write fails with `INTERNAL_ERROR`. This isn't checked
before processing. A failed shipment write is reported in `errors`;
the device-field edit made before it is kept. With `ALL_DEVICES_IN_SHIPMENT`, `errors` can include
a device you didn't list whose shipment update failed. `scope` is ignored without `shipment_details`.
### Per-device `error_code` values
| Value | Meaning | What to do |
|  --- | --- | --- |
| `DEVICE_NOT_FOUND` | No labelled device with this QR code in your account, the device is outside the applications or facilities your account can use, or (shipment update) the device's tracking record isn't available. | Label it with `POST` first; check the QR code. |
| `APPLICATION_CHANGE_NOT_ALLOWED` | `application_id` differs from the device's current application. | Omit `application_id`. The application can't be changed through this API. |
| `FACILITY_NOT_FOUND` | `facility_id` doesn't exist in your account or isn't one your account can use. | Fix `facility_id`. |
| `DUPLICATE_DEVICE` | `asset_barcode` is already used by another device in your account. | Use a different asset barcode. |
| `SHIPMENT_CONFLICT` | (`THIS_DEVICE`) The device already belongs to a different shipment from the first listed device. The device was not edited. | Edit it in a separate call. |
| `NOT_IN_SHIPMENT` | (`ALL_DEVICES_IN_SHIPMENT`) The device isn't part of the first device's shipment, so it didn't get the shipment update. Its device fields were written. | Update its shipment in a separate call. |
| `INTERNAL_ERROR` | Anything else, for example an `application_id` that matches no application, a shipment address that couldn't be resolved, or a temporary failure. | Check the inputs and retry. |

### Status codes
`200` when every device (and every shipment update) succeeded, `207` when at least one failed (also
when all failed). Edits are not rolled back.
### Retries
Resending the same request is safe: it writes the same values again. Once the first device has a
shipment, later calls reuse its `shipment_id`.

Endpoint: PUT /external/v1/devices/label
Version: 2.2
Security: bearerAuth

## Description:

  - `Device fields` ()
    For each listed device only the fields you send are written: FieldOmittednullValueasset_barcodeunchangedclearedreplaced (must not be used by another device in your account)facility_idunchangedclearedreplaced (must be a facility of your account)tape_displaynameunchangedclearedreplacedapplication_idunchangedunchangedmust equal the device's current application; any other application fails with APPLICATION_CHANGE_NOT_ALLOWED The application can't be changed by an edit. application_id is accepted only so you canconfirm the current application. Don't send it unless you need that check. It must pass astrict UUID format check (8-4-4-4-12 hex digits, the 13th digit 1–8 and the 17th digit 8,9, a or b), and most application ids, including ids returned by GET, don't. An id thatfails the check rejects the whole request with 400.

  - `Shipment (shipment_details)` ()
    The target shipment is the shipment of the first device in devices. If that device has noshipment, a new shipment is started. scope decides which devices receive the shipment update: THIS_DEVICE (default): only listed devices whose edit succeeded. A listed device (other than thefirst) that already belongs to a different shipment fails with SHIPMENT_CONFLICT and is notedited at all. Edit it in a separate call where it comes first.ALL_DEVICES_IN_SHIPMENT: every device in your account that carries the target shipment,including devices you didn't list. A listed device that isn't in that shipment fails withNOT_IN_SHIPMENT; its device fields (above) are still written. When the first device has noshipment yet, this behaves like THIS_DEVICE. customer_name, customer_email, source_address and destination_address are required.customer_contact, notes and mode_of_transport keep their saved values when omitted or null.An empty address ({}) keeps the saved location when one is saved; when the target shipment isnew, {} can't be resolved and the shipment write fails with INTERNAL_ERROR. This isn't checkedbefore processing. A failed shipment write is reported in errors;the device-field edit made before it is kept. With ALL_DEVICES_IN_SHIPMENT, errors can includea device you didn't list whose shipment update failed. scope is ignored without shipment_details.

  - `Per-device error_code values` ()
    ValueMeaningWhat to doDEVICE_NOT_FOUNDNo labelled device with this QR code in your account, the device is outside the applications or facilities your account can use, or (shipment update) the device's tracking record isn't available.Label it with POST first; check the QR code.APPLICATION_CHANGE_NOT_ALLOWEDapplication_id differs from the device's current application.Omit application_id. The application can't be changed through this API.FACILITY_NOT_FOUNDfacility_id doesn't exist in your account or isn't one your account can use.Fix facility_id.DUPLICATE_DEVICEasset_barcode is already used by another device in your account.Use a different asset barcode.SHIPMENT_CONFLICT(THIS_DEVICE) The device already belongs to a different shipment from the first listed device. The device was not edited.Edit it in a separate call.NOT_IN_SHIPMENT(ALL_DEVICES_IN_SHIPMENT) The device isn't part of the first device's shipment, so it didn't get the shipment update. Its device fields were written.Update its shipment in a separate call.INTERNAL_ERRORAnything else, for example an application_id that matches no application, a shipment address that couldn't be resolved, or a temporary failure.Check the inputs and retry.

  - `Status codes` ()
    200 when every device (and every shipment update) succeeded, 207 when at least one failed (alsowhen all failed). Edits are not rolled back.

  - `Retries` ()
    Resending the same request is safe: it writes the same values again. Once the first device has ashipment, later calls reuse its shipment_id.

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

  - `scope` (string)
    Which devices get the shipment update (uppercase only). Ignored without `shipment_details`.
    Enum: "THIS_DEVICE", "ALL_DEVICES_IN_SHIPMENT"

  - `shipment_details` (object)
    Shipment information. Unknown fields are ignored.

  - `shipment_details.customer_name` (string, required)
    Any string.
    Example: Acme Pharma

  - `shipment_details.customer_email` (string, required)
    Example: logistics@acmepharma.com

  - `shipment_details.customer_contact` (string)
    Omitted or `null` keeps the saved value (none on a new shipment).
    Example: +1 415 555 0100

  - `shipment_details.source_address` (object, required)
    An address. Send a free-text `label` (resolved to coordinates), `lat` + `lon` (resolved to an
address), or both (stored as sent). On `PUT`, an empty object keeps the saved location when one
is saved. An address with neither isn't rejected with `400`; the shipment write fails instead and
the device is reported as `INTERNAL_ERROR`.

  - `shipment_details.source_address.label` (string)
    Example: 1 Market St, San Francisco, CA 94105

  - `shipment_details.source_address.lat` (number)
    Example: 37.79404

  - `shipment_details.source_address.lon` (number)
    Example: -122.39504

  - `shipment_details.notes` (string)
    Omitted or `null` keeps the saved value.
    Example: Keep refrigerated

  - `shipment_details.mode_of_transport` (string)
    Case-insensitive (`air` is stored as `AIR`). Omitted or `null` keeps the saved value.
    Enum: "AIR", "GROUND", "SEA"

  - `devices` (array, required)
    1–20 devices. Duplicate `qrcode` values reject the whole request. The first device decides the target shipment.

  - `devices.qrcode` (string, required)
    QR code of a labelled device (spaces around it are trimmed). Unique within the request.
    Example: TRK0012345

  - `devices.asset_barcode` (string)
    Omitted → unchanged; `null` → cleared.
    Example: AWB-777-3001

  - `devices.application_id` (string)
    Optional confirmation of the device's current application; it can't change the application.
Don't send it unless you need that check: it must match the pattern shown, and most
application ids (including ids returned by `GET`) don't, which rejects the whole request with
`400`. Codes are rejected too. Omitted or `null` → unchanged.
    Example: 70481678-e88b-2198-98ad-4a2b091940d6

  - `devices.facility_id` (string)
    Facility UUID. Omitted → unchanged; `null` → cleared.
    Example: 0b6f7c1e-2d3a-4b5c-8d9e-0f1a2b3c4d5e

  - `devices.tape_displayname` (string)
    Omitted → unchanged; `null` → cleared.
    Example: Pallet 1A

## Request examples:

  - `Every field` (unknown)

  - `Rename one device` (unknown)

  - `Clear facility and display name` (unknown)

  - `Update the whole shipment of one device, keeping the saved source address` (unknown)

  - `Put two listed devices on the first device's shipment` (unknown)

## Response 200:

  - `200` (unknown)
    Every device and every shipment update succeeded.

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

  - `shipment_id` (string, required)
    The target shipment's id when `shipment_details` was sent; otherwise an empty string.
    Example: 9b2d4c4e-1f7a-4e8b-a0c1-3d5e7f9a1b2c

## Response 207:

  - `207` (unknown)
    At least one device or shipment update failed; also returned when all failed.

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

  - `shipment_id` (string, required)
    The target shipment's id when `shipment_details` was sent; otherwise an empty string.
    Example: 9b2d4c4e-1f7a-4e8b-a0c1-3d5e7f9a1b2c

## Response 400:

  - `400` (unknown)
    The body failed validation (nothing was changed; `errors` lists each problem with its `path`),
or your API identity has several accounts and no account headers were sent.

## 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)
    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)
    Unexpected failure outside per-device processing. Device edits made before the failure are
kept; check the devices with `GET` before resending.

## 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 to the minimal request without shipment_details` (unknown)

## Response 207 examples:

  - `Response to the two-devices shipment request: the second device is in another shipment` (unknown)

  - `Response to the two-devices shipment request with the all-devices scope: the second device is not in that shipment` (unknown)

  - `Response to the all-fields request when the device belongs to another application` (unknown)

  - `Response to the minimal request for a QR code with no label` (unknown)

## Response 400 examples:

  - `The application id is an application code or not a well-formed UUID` (unknown)

  - `Unknown scope` (unknown)

  - `Sending `shipment_details` without its required fields` (unknown)

  - `The same qrcode twice in one request` (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)

