Update Thing Hierarchy

Updates thing hierarchy with a specific ID

You can update the thing hierarchy name, external ID, and the language dependent descriptions using this service for a particular thing hierarchy. In addition, you can add new nodes or delete existing nodes in the existing thing hierarchy. The new nodes cannot appear multiple times in the same hierarchy and the nodes within a hierarchy must be connected to at least one node and should not form cyclic reference. The supported operations in this service are ADD and DELETE. The system does not allow you to delete objects with child nodes, you can only delete the child nodes. The system first executes all DELETE operations and then executes ADD operations. The sequence of operations you specify in the request payload does not alter the sequence of operations performed at the backend. You can perform all PATCH operations only on the existing state of the hierarchy.

The ETag value is not mandatory to update a thing hierarchy. However, to update a thing hierarchy using ETag, you must retrieve the ETag value of the thing hierarchy using the GET (/ThingHierarchy/v1/ThingHierarchies('<thing hierarchy ID>')) service. The ETag value is assigned to the request header parameter If-Match in the PATCH request. If the ETag value is not correct, the server sends HTTP response code 412 .

Request

URI: /v1/ThingHierarchies('<thing hierarchy ID>')

Operation Type: CRUD

HTTP Method: PATCH

Permissions:

<ths>.u

<ohs>.u

Request Header Parameters

Parameter Required Values
Accept-Language No Language of the thing type description. The default language is en.
If-Match No Latest ETag value of a specific thing hierarchy that is updated using the PATCH request.

Request Parameters

Parameter Required Data Type Description
HierarchyID Yes string Unique thing hierarchy identifier

Request Example

Example 1

/ThingHierarchy/v1/ThingHierarchies('582E4688A7647F2CE200229BE0434C65')
{
    "Name": "Car_XYZ_Hierarchy",
    "ExternalID": "CarXYZ-Hierarchy",
    "ThingHierarchyElements": [{
        "ThingID": "3467B81CFCE74A2B97E78000027D2105",
        "ParentThingID": "9EFAEFDB3F794ED0BE6ADD668D90169E",
        "Operation": "DELETE"
    }, {
        "ThingID": "4E60A688A13E43E28EC78A0606785435",
        "ParentThingID": "88E2BA6E7512439E9A771EE626AB25A2",
        "Operation": "DELETE"
    }],
    "ThingHierarchyDescriptions": [{
        "LanguageCode": "en",
        "Description": "Desccribes hierarchy of units in the updated carXYZ"
    },{
        "LanguageCode": "de",
        "Description": "Beschreibung der Hierarchie carXYZ"
    }]
}

In this example, the name, external ID, and the description in language code EN are modified for the thing hierarchy. In addition, two of the nodes are deleted from a different parent.

Example 2

/ThingHierarchy/v1/ThingHierarchies('582E4688A7647F2CE200229BE0434C65')
{
    "ThingHierarchyElements": [{
        "ThingID": "3467B81CFCE74A2B97E78000027D2105",
        "ParentThingID": "9EFAEFDB3F794ED0BE6ADD668D90169E",
        "Operation": "ADD"
    }, {
        "ThingID": "800DEE78D35D43D0BB404BB27B98CDA8",
        "ParentThingID": "88E2BA6E7512439E9A771EE626AB25A2",
        "Operation": "DELETE"
    }]
}

In this example, a new node is added and an existing node is deleted.

Example 3

/ThingHierarchy/v1/ThingHierarchies('582E4688A7647F2CE200229BE0434C65')
{
    "ThingHierarchyElements": [{
        "ThingID": "90589958BF6D530DE20017D91D3A7FDC",
        "ParentThingID": "9EFAEFDB3F794ED0BE6ADD668D90169E",
        "Operation": "ADD"
    }, {
        "ThingID": "90589958BF6D530DE20017D91D3A7FDC",
        "ParentThingID": "9EFAEFDB3F794ED0BE6ADD668D90169E",
        "Operation": "DELETE"
    }]
}

In this example, operations are not performed on the existing state of the hierarchy, as a new node that is not existing in the hierarchy is added and the same is deleted. Hence, the response code for this request is 400, as the object that does not exist is specified for deletion.

Example 4

/ThingHierarchies('C333A558EF82AC01E200D797B4576E03')
{
  "ThingHierarchyElements": [
    {
      "ThingID": "88E2BA6E7512439E9A771EE626AB25A2",
      "ParentThingID": "965B8AB45F624848BDEBD4837D093945",
      "Operation": "DELETE"
    },
    {
      "ThingID": "800DEE78D35D43D0BB404BB27B98CDA8",
      "ParentThingID": "88E2BA6E7512439E9A771EE626AB25A2",
      "Operation": "DELETE"
    },
    {
      "ThingID": "4E60A688A13E43E28EC78A0606785435",
      "ParentThingID": "88E2BA6E7512439E9A771EE626AB25A2",
      "Operation": "DELETE"
    }
  ]
}

In this example, the thing 88E2BA6E7512439E9A771EE626AB25A2 is specified for deletion. However, the thing contains two child nodes. Only after deleting the child nodes, the system allows you to delete the parent thing. Hence, in the payload of the request, you can also mention the child nodes (800DEE78D35D43D0BB404BB27B98CDA8 and 4E60A688A13E43E28EC78A0606785435) to be deleted.

Example 5

/ThingHierarchies('16ACA6581B8C530DE20017D91D3A7FDC')
{
  "ThingHierarchyElements": [
    {
      "ThingID": "9EFAEFDB3F794ED0BE6ADD668D90169E",
      "ParentThingID": "965B8AB45F624848BDEBD4837D093945",
      "Operation": "DELETE"
    },
    {
      "ThingID": "88E2BA6E7512439E9A771EE626AB25A2",
      "ParentThingID": "9EFAEFDB3F794ED0BE6ADD668D90169E",
      "Operation": "DELETE"
    },
    {
      "ThingID": "43B87CB55B2D43A29AAB08AD885A3461",
      "ParentThingID": "965B8AB45F624848BDEBD4837D093945",
      "Operation": "ADD"
    },
    {
      "ThingID": "9EFAEFDB3F794ED0BE6ADD668D90169E",
      "ParentThingID": "43B87CB55B2D43A29AAB08AD885A3461",
      "Operation": "ADD"
    },
    {
      "ThingID": "88E2BA6E7512439E9A771EE626AB25A2",
      "ParentThingID": "9EFAEFDB3F794ED0BE6ADD668D90169E",
      "Operation": "ADD"
    }
  ]
}

In this example, a new node (thing ID 43B87CB55B2D43A29AAB08AD885A3461) is added as an intermediate node.

The following diagram illustrates the existing hierarchy:

You might want to add an intermediate node and update the hierarchy as depicted in the following diagram:

Therefore, in the payload of the request, you specify the following:

  1. Delete the child nodes Thing T2 and Thing T3
  2. Add the new intermediate node Thing New to the parent node Thing T1
  3. Add the child node Thing T2 to its new parent node Thing New
  4. Add the child node Thing T3 to its parent node Thing T2

Response

Format: JSON

Response Status and Error Codes

Code Description
204 Thing hierarchy updated successfully.