# Deactivate devices

Deactivates up to **100** devices in one request. Each device is identified by its `qrcode`.
A deactivated device keeps its label and shipment details, but its status becomes `DEACTIVATED`.
A deactivated device cannot be reactivated through this API. Contact your Trackonomy integration
contact if a device needs to be reactivated.
### 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.
### `action` values
| Value | Effect |
|  --- | --- |
| `DEACTIVATE` | Moves an activated device to `DEACTIVATED`. |

The value is case-sensitive.
### How the request is processed
- The whole request is checked first. If the body is invalid (for example, a missing `action`,
more than 100 devices, or the same `qrcode` listed twice), the call returns `400` and no
device is changed.
- Each device is then processed on its own. One device's failure doesn't stop the others.
- `200` means every device was deactivated. `207` means at least one device failed. This
includes the case where every device failed (`successful: 0`). `errors` lists the failed
devices in request order. Every device not listed in `errors` was deactivated.

### `error_code` values
| Value | Meaning | What to do |
|  --- | --- | --- |
| `DEVICE_NOT_FOUND` | No labelled device has this exact `qrcode` (case-sensitive) in your account, the device belongs to an application or facility your account can't use, or the device's tracking record is missing. | Check the QR code and the account. Label the device first if it was never labelled. If `GET /external/v1/devices/label` shows the device, contact support. |
| `ALREADY_IN_TARGET_STATE` | The device is already `DEACTIVATED`. Nothing was changed. | Treat it as success. |
| `INVALID_TRANSITION` | The device can't be deactivated from its current status: it was never activated, it was rejected, or it has expired. Nothing was changed. | Don't retry. Check the device's status with `GET /external/v1/devices/label`. |
| `INTERNAL_ERROR` | An error occurred while deactivating this device. Usually temporary. | Retry the device with backoff. If it persists, contact support. |

### Retries
Deactivation is safe to repeat. If you resend a device that was already deactivated, you get
`ALREADY_IN_TARGET_STATE`. Treat that code as success. After a `500` or an `INTERNAL_ERROR`, resend the same request.

Endpoint: POST /external/v1/devices/status
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.

  - `action values` ()
    ValueEffectDEACTIVATEMoves an activated device to DEACTIVATED. The value is case-sensitive.

  - `How the request is processed` ()
    The whole request is checked first. If the body is invalid (for example, a missing action,more than 100 devices, or the same qrcode listed twice), the call returns 400 and nodevice is changed.Each device is then processed on its own. One device's failure doesn't stop the others.200 means every device was deactivated. 207 means at least one device failed. Thisincludes the case where every device failed (successful: 0). errors lists the faileddevices in request order. Every device not listed in errors was deactivated.

  - `error_code values` ()
    ValueMeaningWhat to doDEVICE_NOT_FOUNDNo labelled device has this exact qrcode (case-sensitive) in your account, the device belongs to an application or facility your account can't use, or the device's tracking record is missing.Check the QR code and the account. Label the device first if it was never labelled. If GET /external/v1/devices/label shows the device, contact support.ALREADY_IN_TARGET_STATEThe device is already DEACTIVATED. Nothing was changed.Treat it as success.INVALID_TRANSITIONThe device can't be deactivated from its current status: it was never activated, it was rejected, or it has expired. Nothing was changed.Don't retry. Check the device's status with GET /external/v1/devices/label.INTERNAL_ERRORAn error occurred while deactivating this device. Usually temporary.Retry the device with backoff. If it persists, contact support.

  - `Retries` ()
    Deactivation is safe to repeat. If you resend a device that was already deactivated, you getALREADY_IN_TARGET_STATE. Treat that code as success. After a 500 or an INTERNAL_ERROR, resend the same request.

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

  - `action` (string, required)
    The action to apply to every device in the request. Case-sensitive.
    Enum: "DEACTIVATE"

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

## Request examples:

  - `Every field` (unknown)

  - `One device` (unknown)

  - `Batch that partly fails, see the 207 example` (unknown)

## Response 200:

  - `200` (unknown)
    Every device in the request was deactivated.

## 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 device failed. This is also returned when every device failed, with
`successful: 0`. Devices not listed in `errors` were deactivated.

## 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. Either the body failed validation, or
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)
    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 before any device was processed. Resend the same request;
it is safe to repeat.

## 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 mixed request` (unknown)

  - `Every device failed` (unknown)

## Response 400 examples:

  - `Empty `devices` array` (unknown)

  - `More than 100 devices` (unknown)

  - `The same qrcode listed twice` (unknown)

  - `Empty qrcode` (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)

