I’m trying to create a device using the Create Device node in a workflow. I’d like to dictate the recipe based on global variable. When I try that, I receive the below:
{
“error”: {
“type”: “NotFound”,
“message”: “Device Recipe was not found”
}
}
Is the “Device Recipe Template” templatable?
Yes, it is templatable. As a next step, I would verify that the value at working.fleet_globals.default_recipe
corresponds to an ID of a device recipe within your application. You can do this by viewing the debug log from a run where you attempt to use the value or by using the workflow’s template tester.
Also, you said …
I’d like to dictate the recipe based on global variable.
Does that mean the ID is stored in a workflow or application global? If so, assuming you are not mutating the payload in a way to move the value from its default spot, it should be available at a path of globals.default_recipe
(replacing default_recipe
with whatever you named the variable).
Thanks Dylan, I just wanted to make sure it was templatable before I kept hammering at it. Thank you for the quick reply. Will post back here when I figure out what I messed up.
I did get the device created with a templated recipe, but only using it’s 24 digit ID. The recipe is more readable in my global JSON data using the string descriptor. Is it possible to easily look up the 24 digit ID from the recipe name? Or does that involve using the Losant API node?
It’s no big deal to use the 24 digit ID; just interested.
The Device: Create Node requires using the ID for referencing the recipe. You could look up the recipe ID by providing a name to the Device Recipes: Get endpoint in the Losant API Node but that would require the addition of several new nodes, not to mention adding an awful lot of overhead to each and every request. You’d also have to ensure that no name searches could match multiple recipes (for example, “my great” matching “my great recipe” and “my great device recipe”). I’d recommend biting the bullet and just using the ID.
Alternatively you could maintain a map of recipe names to IDs as an object in globals, but you’d have to update this object every time a recipe was created, deleted, or had a name change. You could then use the {{lookup}}
helper to retrieve the ID given a full name match.
1 Like
Great to know the options Dylan. Feeling pretty proud of myself for having ID’d them prior to your response. The globals are intended to be used by personnel well trained in our implementation, so having to go grab that ID upon new fleet setup is a reasonable thing to do. Maybe I’ll put a recipe lookup custom node on our backlog, but for now we’ll just use the Recipe ID.
Thank you so much for the prompt responses.