Skip to content
Stand with Ukraine flag

Attributes

Upload client-side attributes for one or more devices.

Topic: v1/gateway/attributes

{
"Device A": {"fw_version": "1.0", "battery": 87},
"Device B": {"fw_version": "2.1", "battery": 92}
}

Replace GATEWAY_DEVICE_ACCESS_TOKEN in the commands below with the gateway device’s access token, and $THINGSBOARD_HOST with your ThingsBoard instance’s host.

Terminal window
mosquitto_pub -h "$THINGSBOARD_HOST" -t "v1/gateway/attributes" -u "GATEWAY_DEVICE_ACCESS_TOKEN" -m '{"Device A":{"fw_version":"1.0","battery":87}}'

Subscribe to the response topic first, then publish the request.

Subscribe: v1/gateway/attributes/response

Publish: v1/gateway/attributes/request

FieldRequiredDescription
idYesInteger request identifier — echoed in the response
deviceYesDevice name
keysYesArray of attribute keys to return
clientYesBoolean flag: set to true to request client-side attributes, or false to request shared attributes
{
"id": 1,
"device": "Device A",
"keys": ["fw_version", "battery"],
"client": true
}

Example:

The gateway keeps a single MQTT connection open per device, so use mosquitto_rr: it subscribes, publishes the request, and waits for the response over that one connection, matching the request/response pattern this API expects.

Replace GATEWAY_DEVICE_ACCESS_TOKEN in the commands below with the gateway device’s access token, and $THINGSBOARD_HOST with your ThingsBoard instance’s host.

Terminal window
mosquitto_rr -d -q 1 -h "$THINGSBOARD_HOST" -p 1883 -t "v1/gateway/attributes/request" -e "v1/gateway/attributes/response" -u "GATEWAY_DEVICE_ACCESS_TOKEN" -m '{"id":1,"device":"Device A","keys":["fw_version","battery"],"client":true}'

Subscribe to receive push notifications when shared attributes change for any downstream device.

Topic: v1/gateway/attributes (subscribe)

Terminal window
mosquitto_sub -h "$THINGSBOARD_HOST" -t "v1/gateway/attributes" -u "$ACCESS_TOKEN"

ThingsBoard delivers updates in this format:

{
"device": "Device A",
"data": {"targetFwVersion": "2.0", "enabled": true}
}