How to publish an event to a single device

Is there an API to publish an event to a single device using a product-scoped customer access token?

There is no way to publish an event to a single device, product or non-product. One way to scope the event is to prefix it with a unique string, the device ID is a logical choice. When the device subscribes to the event, it will only get the one targeting that device.

However, there’s a problem with sending product events to devices. Product events are intended to only be used device to product. These events are can be subscribed to at the product level using webhooks or SSE and any device in the product can send a private product event.

There is no MY_PRODUCT analog to MY_DEVICES when subscribing on-device, however. In order to send a private event to a device you need the access token for the device’s owner.

If you have an Electron product where you claim all of the devices to a single user (the owner of the product), this isn’t a problem.

However if you are using customer accounts, as is common for Wi-Fi devices, then you pretty much need to use two-legged shadow customers because you need to be able to create a customer impersonation token for that user in order to sent private events to that device.

Another alternative is to use functions, which can be called with a product bearer token (regardless of who claimed the device), and it’s scoped to a specific device.

1 Like

Thanks for the quick response!

By the way, in 0.8.0-rc.4 the function argument was expanded from 63 bytes to 622 bytes, so it’s much more practical to use functions now.

1 Like