如何以编程方式从 ThingsBoard 获取设备令牌

How to get device token programmatically from ThingsBoard

我的目标是将属性发送到每个设备。

我可以通过 /api/tenant/devices 获得设备。但这不包括设备令牌。

{
  "data": [
    {
      "id": {
        "entityType": "DEVICE",
        "id": "66c2f980-4568-11e9-a10d-9be803b14c20"
      },
      "createdTime": 1552465031448,
      "additionalInfo": null,
      "tenantId": {
        "entityType": "TENANT",
        "id": "3a0833a0-455a-11e9-8dde-a383dc31d4aa"
      },
      "customerId": {
        "entityType": "CUSTOMER",
        "id": "13814000-1dd2-11b2-8080-808080808080"
      },
      "name": "USB 23393",
      "type": "usb"
    },

我应该使用 API 是 /api/v1/[device toekn]/attributes

我该怎么做?

我可以从 Thingsboard 的 swagger api 中找到。

这是我的最终代码。希望这对某人。

          let url = '/api/device/' + device.id.id + '/credentials';
          axios.defaults.headers.common['X-Authorization'] =
                            'Bearer ' + localStorage.getItem('accessToken');

          axios.get(url)
          .then(response => {
            console.log(response.data);
            let credentialsId = response.data.credentialsId;
            return credentialsId;
          })
          .then(credentialsId => {
            url = '/api/v1/' + credentialsId + '/attributes';
            console.log(url);