How to overwrite the tags of a device using REST API
I am trying to use REST API to overwrite the device tags, but I when I make the request it is adding new tag to existing device tags instead of overwriting then with the newly supplied tags.
Is there any API or attribute that I need to send in JSON to overwrite the tags?
-
import requests
hostname = 'enterHostnameOrIP'url = "https://"+hostaddres+"/ot-base/api/v1/devices/"
auth = ("username", "password")
data = [{"deviceId": "DeviceId1","tags": ["tag1", "tag2"]}]response = requests.post(url, json=(data), auth=auth, verify = False)
# DeviceId1 tags updated with tag1, tag2
data = [{"deviceId": "DeviceId1","tags": ["tag1", "tag2", "tag3", "tag4"]}]response = requests.post(url, json=(data), auth=auth, verify = False)
# DeviceId1 tags updated with tag1, tag2, tag3 and tag4
# Now I want to overwrite tage with just tag3 and tag4data = [{"deviceId": "DeviceId1","tags": ["tag3", "tag4"]}]response = requests.post(url, json=(data), auth=auth, verify = False)
# Now tags are not getting updated with just tag3 and tag4, I see all four tags.# Tags are getting appended but not getting overwrite.
Please sign in to leave a comment.
Comments
3 comments