Balena SDK - device type

Hi,

I’ve used the Balena Node.JS SDK version 13.8.0 because openBalena wasn’t compatible with newer versions. When our device booted for the first time, it registered itself via our container to our server. The server then got the device’s Balena details, like device_type. However, it seems like it’s gone and I can’t find how to get the device type via the Balena Node.JS SDK v15.17.0.

I’ve always used the following

const device = balena.models.device.get(<uuid>);
device.device_type

However, this is gone. Is there another way to retrieve the device type using the uuid of the device?

Thanks in advance!

The field is now called is_of__device_type and is a FK to the device_type table, which you can $expand like any other relation. See here: https://github.com/balena-io/balena-sdk/blob/master/typings/balena-sdk/models.d.ts#L341

So to my understanding, I’ve to do the following:

const device = balenaDevice = await balenaInstance.models.device.get(uuid, {
  $expand: {
    is_of__device_type: {},
  }
});

const deviceType = (balenaDevice.is_of__device_type as Array<balena.DeviceType>)[0].slug;

Yes, exactly.

1 Like

If that doesn’t work exactly as written, try explicitly selecting the slug (which is a good practice anyway), like so:

...
$expand: {
  is_of__device_type: {
    $select: 'slug'
  }
}

Thanks, I added the $select, but it had to be an array. It works now :slight_smile: