In order to get the total consumption for all meters for a building, city, or other groupings, it is possible to make an API request to fetch the consumption for a tree node. The consumption for all meters within that tree node will then be summed. The API looks and behaves in a similar way as when requesting consumption directly for a meter.
GET https://app.metry.io/api/2.0/consumptions/id/granularity/period?metrics=metrics
The ID parameter in the URL is the _id field of the tree object in Metry.
See the API reference for more information:
https://metry.docs.apiary.io/#reference/consumption/get-consumption/tree-node
Using external identifiers
Some systems have their own representations of buildings or other objects for which they want to get aggregated consumption data. In order to map these external objects to the tree nodes in Metry, an option is to configure your own ID on the tree groups. This can be done via the API or in Metry's portal.
In the API, this field is called custom_identifier which can hold a string as your ID. You can search for tree nodes using this custom identifier to find the tree node's id field you need to use when fetching consumption for that tree node.
First, make a request to query the tree nodes using your custom identifier:
GET https://app.metry.io/api/2.0/trees?custom_identifier=your_external_identifier
You will then receive a response like below:
{ "code": 200, "message": "OK", "count": 1, "skip": 0, "limit": 50, "data": [{ "_id": "5927dd3b28592700ad6185dc", "name": "Kungsgatan", "factor": 1,
"custom_identifier": "your_external_identifier", "app_custom_fields": {}, "custom_fields": {}, "parent": null, "meters": [], "location": null, "open_channel_ids": null }] }
Extract the _id fields from the first object in the data array to then request consumption.