Skip to content
Try for free

ThingsBoard Cloud

Choose your data region

Your data stays in the region you choose, for residency and compliance. No credit card required.

Rather run it yourself? Install on your own servers

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

Field Required Description
id Yes Integer request identifier — echoed in the response
device Yes Device name
keys Yes Array of attribute keys to return
client Yes Boolean 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}
}