sungyong
sungyong

Reputation: 2499

How to get device token programmatically from ThingsBoard

My aim is send attribute to each device.

I can get device by /api/tenant/devices. But this doesn't include device token.

{
  "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"
    },

What I should use the API is /api/v1/[device toekn]/attributes

How can I do that?

Upvotes: 2

Views: 1718

Answers (1)

sungyong
sungyong

Reputation: 2499

I can find from swagger api of Thingsboard.

Here is my final code. Hope this to someone.

          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);

Upvotes: 4

Related Questions