Reputation: 1
I want to retrieve Asset Hierarchy of Twin Graph in Azure Digital Twins using REST API, is there any way to do so?
Upvotes: 0
Views: 301
Reputation: 4085
The situation you described in your question (and the comments) can be solved by writing multiple queries. To get the full graph as a hierarchy, you will first need to query the top-level items (in your case organisations) and then you can either run a query for every organisation or fit it all into one query. I'm making some assumptions about your hierarchy in these examples, you will need to adapt them to your ontology.
Getting all the organisations:
SELECT ROOM FROM DIGITALTWINS DT WHERE IS_OF_MODEL(DT, 'dtmi:example:organisation;1', exact)
Getting the hierarchy for one organisation:
SELECT Organisation, Factory, ProductionLine, Equipment
FROM DIGITALTWINS Organisation
JOIN Factory RELATED Organisation.contains
JOIN ProductionLine RELATED Factory.contains
JOIN Equipment RELATED ProductionLine.contains
WHERE Organisation.$dtId = 'Organisation1'
Getting the hierarchy for all previously found organisations:
SELECT Organisation, Factory, ProductionLine, Equipment
FROM DIGITALTWINS Organisation
JOIN Factory RELATED Organisation.contains
JOIN ProductionLine RELATED Factory.contains
JOIN Equipment RELATED ProductionLine.contains
WHERE Organisation.$dtId IN ['Organisation1', 'Organisation2', 'Organisation3', 'etc...']
There is a limitation of 5 JOIN statements to take into account. And both queries will return a row for every Equipment twin, so you will need to transform the result a bit.
In both the SDK and REST API, you can achieve this through the Query operation.
Upvotes: 1