Skip to content

Update Device

Update an existing device on your Traccar server.

IMPORTANT

Recommended workflow: fetch the device DTO first, clone it, update the fields you need, then send the updated DTO. This preserves fields you are not changing and avoids accidental resets. See the server update docs for the same pattern.

  • Only update the fields you want to change
  • Keep the id and uniqueId consistent with the target device

Usage

php
use ThingsTelemetry\Traccar\Dto\DeviceData;
use ThingsTelemetry\Traccar\Dto\DeviceAttributesData;
use ThingsTelemetry\Traccar\Enums\DeviceCategory;
use ThingsTelemetry\Traccar\Enums\DeviceStatus;
use ThingsTelemetry\Traccar\Facades\Device;

// 1) Get an existing device (example: by uniqueId)
$devices = Device::get(uniqueIds: ['ABC123']);
$data = $devices->first(); // ThingsTelemetry\Traccar\Dto\DeviceData

// 2) Update the fields you want to change
$data->name = 'Truck 1 - Updated';
$data->attributes->speedLimit = 90.0;

// 3) Send the updated DTO
$updated = Device::update($data); // returns ThingsTelemetry\Traccar\Dto\DeviceData

Results

The response is a ThingsTelemetry\Traccar\Dto\DeviceData instance.

php
$name = $updated->name;                  // "Truck 1 - Updated"
$status = $updated->status->label();     // e.g., "Online"
$category = $updated->category->value;   // e.g., "truck"
$lastSeen = $updated->lastUpdate?->toIso8601String();

$speedLimit = $updated->attributes->speedLimit; // 90.0

Errors

400 - Key (groupid)=(123456) is not present in table "tc_groups"

shell
Bad Request (400) Response: org.traccar.storage.StorageException: org.postgresql.util.PSQLException: ERROR: insert or update on table "tc_devices" violates foreign key constraint "fk_devices_groupid" Detail: Key (groupid)=(123456) is not present in table "tc_groups".

This means that the groupId does not exist in the server. Use the group api to get the list of available groups.

Released under the MIT License.