REST API Patch issue...
Has anyone had any success using the v2 of the REST API to push a PATCH to add a customer property to an object (in this case /device/groups/##### without wiping out any other custom properties that have already been set?
We've run into a curious behavior while trying to add a property to feed out integration to our ticketing system. It seems to replace the whole of the custom properties object, not just the child object within the customproperties level of the json:
<span class="pln">{ `"customProperties`" : [{
`"name`" : `"connectwisev2.companyid`",
`"value`" : `"$($integrationID.TrimEnd())`"
}]
}</span>We had 2-3 other properties in there that disappeared after patching.
Cole McDonald
Posted 6 years ago·Last reply 6 years ago
4 comments
LM User
·6 years agoThe HTTP verb you use will determine that. If I want to update existing properties, i use PUT. If i want to create a new one, i use POST.
These examples are for devices, but it's similar for groups:
To create a new property on device 43 called "my.new.property", I POST to "/device/devices/43/properties/" with the following payload:
If i repeat the same action, i get this response:
So, to update that property with a new value, I do a PUT to "/device/devices/43/properties/my.new.property" with the following payload:
More reading: https://medium.com/backticks-tildes/restful-api-design-put-vs-patch-4a061aa3ed0b
Cole McDonald
OP6 years agoThanks guys. Will this allow me to add customProperties or am I locked into accessing existing customProperties?
LM User
·6 years agoYeah, if you patch the group, you'd have to include all children in their entirety. If you patch just one property, you only have to provide that one property in its entirety.
Mike Moniz
·6 years agoTry using the /device/groups/{gid}/properties/{name}/ endpoint.