Two ways to add, edit, or remove attributes from a device via the REST API:
Device: Patch - This method requires passing up the entire array of attributes with the request - as in, you must first fetch the device, operate on the correct array item, and then make the patch request with the full edited array in the body.
Devices: Patch - This is the bulk update endpoint (for updating multiple devices at once), but you can use it for your case as well.
I just tested out your example and it worked for me; can you verify the value of “key” is the name of an attribute on the device with the ID found at “data.params.machineId”? What is the response you are getting from the operation (if you put a payload path in the “Response” section and add a Debug Node after)?
I know that what I was doing was setting attribute tags, but my idea is to add attributes. I was just trying to do this using the updateOperations because I was thinking: what if i want to add attribute with attribute tags when the attribute doesnt exists a priori?
In that case, the issue is you are using the wrong operation; in your code sample, you are attempting to add an attribute tag to an existing attribute, not adding a new attribute to the device.
Instead, the item you pass in the “updateOperations” array should look like the following:
No, following that syntax it will only add the attribute and will leave the remaining ones in place.
When it comes to building these bulk update queries, I like to create the operation first in the user interface, submit the request, and then view how it is shaped in the browser’s “Network” tab. That’s what I did in this case as well. Just a tip for working with this endpoint in the future.