Is there an example of an elegant way to create a new device in a workflow when processing a payload and the referenced device doesn’t already exist? The logic is simply:
JSON/payload triggers workflow
payload contains attribute like “DeviceID”
if “DeviceID” does not exist as a Losant device, create it with a pre-defined set of attributes and tags
then update appropriate attributes contained in payload
I realize I am being a bit lazy, but I am just hoping someone can quickly point me to something. Thank you.
This is actually a very common approach! You can check out our blog post, although it is a bit dated.
In practice, you would use a Device: Get Node to see if the device exists, and if it doesn’t, you would use the Device: Create Node to then create the device, and then subsequently update the state of that device (you will need to put the response of the Device: Create Node on the payload to reference the newly created device’s ID in the State node, though).