How to overwrite the tags of a device using REST API

Comments

3 comments

  • Ralph Langner

    Sample code?

    0
    Comment actions Permalink
  • forsites
    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 tag4
    data = [
        {"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.
    0
    Comment actions Permalink
  • Bill McGuire

    Hi,

    Your code works for me as expected with overwrites working properly. Please open a ticket and we can address this issue with you directly. 

     

    0
    Comment actions Permalink

Please sign in to leave a comment.