Search code examples
httprequestthingsboard

How to retrieve multiple device attributes from a single HTTP request in Thingsboard?


I want to retrive multiple device attributes from a single HTTP API call. TB allows me to perform get request to retrive device data with corresponding access token specifying in the request. Is there any options to get all devices data from device group?


Solution

  • When you say multiple device attributes, are you asking for:

    1. Get ALL attributes from ONE device? If so you can use:
      curl -v -X GET "https://thingsboard.cloud/api/v1/$ACCESS_TOKEN/attributes

    2. Get ALL attributes for ALL devices in a specific device group. This is harder, you will need to use the full rest api found at https://cloud.thingsboard.io/swagger-ui.html

    If you need option 2, you will have to have a custom script to get a JWT token for your user credentials (or a low access level api user account) and use that to authenticate REST calls with the above link.

    Pseudo process:

    • Generate JWT token using user credentials.
    • Use REST calls to entity-group-controller > getEntityGroupsByType with groupType = 'DEVICE'
    • Loop through that for the group that you want
    • Use the corresponding groupId in a entity-group-controller > getEntities call
    • Loop through the returned entities and either execute Method 1 (above) on them or do a telemetry-controller > getAttributes call.

    That's far more than 1 HTTP call though...

    You could wrap it into a function so to make it easier to use, but I don't think you can reduce the number of calls further.