-
Notifications
You must be signed in to change notification settings - Fork 0
/
apiary.apib
1722 lines (1371 loc) · 77.4 KB
/
apiary.apib
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
FORMAT: 1A
HOST: https://app.metry.io/api/2.0/
# Metry API v2
Metry collects consumption data from **meters** managed by utilities, as well as **meters** managed by building owners.
Developers can access this data to build apps that **help people and organizations save energy**. Or just something that makes energy usage a little bit more exciting.
## Getting started
Copy the command below into a terminal and run it.
```sh
curl -H 'Authorization: Bearer 9f999b72772410cfb4fe0d4309b5f9dabb01e2fafcd7ba946c6cdc11aa8e' https://app.metry.io/api/v2/accounts/me
```
<h3>So, what happened here?</h3>
You just made a request to our API and **requested basic information** about the authenticated user!
<h3>What about the energy consumption?</h3>
To fetch the energy consumption, we first need to see what meters the user has:
```sh
curl -H 'Authorization: Bearer 9f999b72772410cfb4fe0d4309b5f9dabb01e2fafcd7ba946c6cdc11aa8e' https://app.metry.io/api/v2/meters
```
And to see the **consumption for 2022**, you type...
```sh
curl -H 'Authorization: Bearer 9f999b72772410cfb4fe0d4309b5f9dabb01e2fafcd7ba946c6cdc11aa8e' https://app.metry.io/api/v2/consumptions/5824790e3d214b006271c515/month/2022
```
That's it! Now you have a basic understanding of how our API works. Just scroll down to dig into the details!
If you need help during your development process you're more than welcome to contact us at [[email protected]](mailto:[email protected]).
### Good to know
* API endpoint: https://app.metry.io/api/v2/
* Version numbers may be updated in the future, older versions will be supported for a period of time.
* All API traffic must be made over SSL (https://)
* You can find articles that will help you make your integration to Metry <a href="https://support.metry.io/hc/en-us/categories/360000328693-Developer-Resources">here</a>
## API Authentication
The Metry API requires authentication - specifically requests made on behalf of a user.
Authenticated requests require an access token. These tokens are unique to a user and should be stored securely.
There are two methods to authenticate to the API:
* **Private Access Token Authentication.** Used for internal integrations that are connected to a single Metry account.
* **OAuth2 Authentication.** Used for service providers that build a system that potentially allow many Metry accounts to connect. Register as a developer to get started at https://app.metry.io/id/register/developer-user?plan=developer_hobby
### Private access tokens
Private access-tokens are used to access data for your own account, and should never be
shared with anyone else. You can access your private access token in the Metry Portal ([https://app.metry.io](https://app.metry.io)).
Pass the access token in an Authorization-header
```
Authorization: Bearer <access-token>
```
It's still possible to pass the access-token in the URL, but be aware that we are planning to drop this feature.
```
https://app.metry.io/api/v2/accounts/me?access_token=<access-token>
```
### OAuth2 Authentication
The Metry API uses the standard OAuth 2.0 protocol for simple, but effective authentication and authorization to third parties.
As an app developer, you should direct your users to login with Metry and grant access to your app. This will give you the users `refresh_token`, which should be used to request the `access_token`.
The refresh token should be stored on your end with the same security in mind as a password. The `access_token` itself will expire after 1 hour at which point the `refresh_token` need to be used to fetch a new `access_token`, just as any other OAuth2 implementation.
**Read more about getting started with OAuth here:**
https://support.metry.io/hc/en-us/articles/360009388753-Third-Party-Access-to-Energy-Data
### Metry OAuth Connect
To make this implementation as smooth as possible, we've created a javascript library to connect the user. This will also demonstrate a general OAuth2 flow.
See the Github repository on https://github.com/metry-io/metry-oauth-connect and try the demo on http://metry-oauth-connect-demo.s3-website-eu-west-1.amazonaws.com/
### ClientID and ClientSecret
To get started you need to request a `client_id` and `client_secret`. Please contact our support ([[email protected]](mailto:[email protected])) and tell us a bit about your app.
### Metry oAuth 2.0 endpoints
If you decide to roll your own implementation, keep in mind the oAuth endpoints for Metry:
| Description | Url |
| ------------- | ------------- |
| Host | https://app.metry.io/ |
| oAuth 2.0 Authorize | https://app.metry.io/oauth/authorize |
| oAuth 2.0 Token | https://app.metry.io/oauth/token |
## List responses and pagination
All lists are paginated, and shows 50 items per request. You can advance to next pages by adding query params **skip** and the number
of items you want to skip (typically 50, 100, 150 and so on).
## Error handling
The Metry API attempts to return appropriate HTTP status codes for every request. A 2xx status code indicates success, whereas a 4xx or 5xx status code indicates an error.
### Status codes
| Status code | Description |
|---|---|
| 200 | Success |
| 400 | Validation error: An accompanying error message will explain further |
| 401 | Authentication error: The oAuth credentials were missing, incorrect or expired |
| 403 | Authentication error: The current authenticated user has no access to this resource |
| 404 | Invalid endpoint: The endpoint requested is invalid or the resource requested, such as a meter, does not exists. |
| 405 | The HTTP method used for this endpoint is invalid. |
| 429 | Too many requests: The client has exceeded our rate limiting threshold. |
| 5xx | An error has occurred within Metry.io and the request couldn't be completed. Metry.io has been notified about the problem |
| 503 | We're experiencing temporary server issues. Please try again |
### Error messages
When an API request fails, it will be accompanied with an explanatory message. For example, an error might look like this:
```
{
code: 404,
message: "Resource not found"
}
```
### Future compatibility
For future compatibility, please interpret the following HTTP status code ranges:
**200–299** as success<br>
**400–499** as client request errors<br>
**500–599** as server errors
## Rate limiting
If the rate of requests from a single client is greater than what we estimate to be reasonable which is about 10 requests/second, the API will temporarily respond with status code **429**. If your client does not make more than one request at a time, it is unlikely to be affected by this rate limit. The rate limit may change in the future if we see a need for it.
# Group Accounts
An account represents a person, business or organization that uses the Metry platform.
## Accounts resource [/accounts/{id}]
### Get an account [GET]
Tip: Use alias "me" to reference the currently authorized user.
+ Parameters
+ id (required, string, `5543677f37c6b65f008b46e4`) ... The id of the account to get info about
+ Request
+ Headers
Authorization: Bearer 9f999b72772410cfb4fe0d4309b5f9dabb01e2fafcd7ba946c6cdc11aa8e
+ Response 200 (application/json)
+ Attributes (Account)
+ Body
{
"code": 200,
"message": "OK",
"profiling": null,
"data": {
"_id": "5543677f37c6b65f008b46e4",
"name": "Example account",
"username": "[email protected]",
"sub_accounts_count": 1,
"sub_accounts": [
{
"_id": "565f0344c6db1f57008b5573",
"name": "Demo - Private Customer",
"username": "[email protected]",
"sub_accounts_count": 0,
"sub_accounts": [],
"created": "2015-12-02T14:42:12+0000",
"locale_string": null,
"language": "en",
"is_organization": false,
"entity_type": null,
"custom_identifier": "52472493"
}
],
"created": "2015-05-01T11:46:07+0000",
"locale_string": null,
"language": "en",
"is_organization": false,
"entity_type": null
}
}
# Group Meters
A meter represents a physical device that measures consumption from a utility such as heat, cooling or electricity.
Each meter has a holder who can **assign** or **share** the meter to other accounts.
Assigned or shared meters references a root meter, and it is good practice to use the
**root._id** as unique identifier in your own applications. The **_id** field only represents the
reference itself, and is used to updated meta-information about the meter such as name, tags or if the meter is active or not.
## Meter [/meters/{id}]
+ Parameters
+ id (string, required) - Id of the meter.
### Get a meter [GET]
+ Parameters
+ id: 5825c85d22c8aa00606b9dd5 (required, string) - The id of the account to get info about
+ Request
+ Headers
Authorization: Bearer 9f999b72772410cfb4fe0d4309b5f9dabb01e2fafcd7ba946c6cdc11aa8e
+ Response 200 (application/json)
+ Attributes (Meter)
+ Body
{
"code": 200,
"message": "OK",
"profiling": null,
"data": {
"_id": "5825c85d22c8aa00606b9dd5",
"ean": "1200004",
"name": null,
"holder": {
"_id": "5543677f37c6b65f008b46e4",
"name": "Example account",
"username": "[email protected]"
},
"root": {
"_id": "577fdd960c8a335c008b466f",
"holder": {
"_id": "577fd0170c8a335c008b45fe",
"name": "Rob Harvey Utility Company"
}
},
"assigner": {
"_id": "577fd0170c8a335c008b45fe",
"name": "Rob Harvey Utility Company",
"username": null
},
"created": "2016-11-11T13:32:13+0000",
"children": [],
"address": "Gränsvägen 12B",
"timezone": "Etc/GMT-1",
"control_level": "shared",
"generation": 1,
"tags": [],
"box": "active",
"revoked": false,
"metrics": [
"energy"
],
"type": "cooling",
"consumption_stats": {
"energy": {
"month": {
"count": 22,
"sum": 659440,
"max": 92560,
"last": 201610,
"min": 9730,
"first": 201501
},
"hour": {
"first": null,
"last": null,
"sum": null,
"max": null,
"min": null,
"count": 0
},
"day": {
"first": null,
"last": null,
"sum": null,
"max": null,
"min": null,
"count": 0
}
}
},
"readings_stats": null,
"has_active_complaints": false,
"representation": null,
"open_channel_ids": null,
"active_box_tree_paths": [
[{"_id": "5bc8408d0cfb6200783c389d", "name": "Göteborg"}, {"_id": "5bc8408d0cfb6200783c389f", "name": "Kämpegatan 6"}]
]
}
}
### Update a meter [POST /meters/{meter_id}]
Contact [[email protected]](mailto:[email protected]) to receive write access to meters.
+ Parameters
+ meter: 5927d86628592700964a702c (string) - The _id of the meter
+ Request (application/json)
+ Attributes
+ address: Klackvägen 12 (string) - Meta information.
+ name: Pumphuset vid sjön (string) - Meta information.
+ tags: foo, bar (array[string]) - Meta information.
+ box: inbox, ignored, temporary, active (enum [string]) - Change the box on a meter to move it to another box. Meters need to be in box active or temporary to be able to get consumption from the meter.
+ type: electricity, heat, cooling, gas, hot_water, water (enum) - What type of consumption the meter represents.
+ ean: 7501054530107 (number) - An International Article Number that uniquely identifies the physical metering point.
+ representation: consumption, production, `net_consumption`, `net_production`, sensor (enum [string]) - Does this meter record energy consumption or production
+ Response 200 (application/json)
+ Attributes (Meter)
## Meters collection [/meters{?box,name,address,tags,control_level,generation,type,metrics,ean,representation}]
You can list all meters accessible by the authenticated user.
Note that the response will only contain 50 meters at a time. To get additional meters, specify the amount to skip as a query parameter such as `skip=50`
### Filtering results
You can filter results by adding query params, for instance:
.../meters?box=active
... will only list active meters.
You can add multiple query params. For **dates and numbers** you can use greater than and less than characters. For instance
.../meters?consumption_stats.energy.month.last=<201503&box=active
This filter will only list *active* meters where *last month value is before March 2015*.
**NOTE!** Query params that are not recognized will be *silently ignored*, so make sure you spell them correctly!
**NOTE!** We suggest using the `box` attribute to list the meters that are activated by customers. So you can use `...meters?box=active...` instead of `... meters?active=true ...`.
### List meters [GET]
+ Parameters
+ address: Kungsgatan 2 (optional, string) - Meta information.
+ name: Home sweet home (optional, string) - Meta information.
+ `control_level`: subscribed (optional, enum [string])
+ generation: 1 (optional, number) - Integer that represents the current meters level in a tree structure, gen 0 (root meter) is held by the owner of the meter, gen 1 is the subscribed meter held by company or person that's energy usage is recorded by the meter, gen 2 is a shared meter which has been shared with a 3rd party.
+ tags: bar (optional, array[string]) - Meta information.
+ box: active (optional, enum [string]) - - When a Metry robot finds a new meter it places it in the customer's inbox, the customer is then able to move the meter to ignored or active. Metry only collects consumption data for meters placed in active.
+ type: electricity (optional, enum) - What type of consumption the meter represents.
+ metrics: energy (optional, enum [string]) - Which metrics the meter is recording data in.
+ ean: 7501054530107 (optional, number) - An International Article Number that uniquely identifies the physical meter
+ representation: production (optional, enum [string]) - Does this meter record energy consumption or production
+ Request
+ Headers
Authorization: Bearer 9f999b72772410cfb4fe0d4309b5f9dabb01e2fafcd7ba946c6cdc11aa8e
+ Response 200 (application/json)
+ Attributes (Meter)
# Group Trees
Trees are a way to structure meters in a hierarchical structure. The implementation is intended to be as flexible as possible so that users and applications can group meters however needed, for instance, by cities, properties, buildings, and other logical groups. Consumption requests can then be made on tree nodes to get the aggregated consumption or temperature of the underlying meters.
## Create [/trees]
Create a new tree or add tree nodes to an existing tree.
This requires an OAuth client with the the scope `write_trees`.
### Create tree node [POST]
+ Request (application/json)
+ Attributes
+ parent: null (string) - The _id of the parent if adding as a child to another node in an existing tree
+ name: Kungsgatan (string) - A name to put on the tree node
+ Response 200 (application/json)
+ Attributes (Tree)
+ Body
{
"code": 200,
"message": "OK",
"profiling": [],
"data": {
"_id": "5927d86628592700964a702c",
"name": "user node",
"factor": 1,
"children": [],
"app_custom_fields": [],
"parent": null,
"meters": [],
"location": null,
"open_channel_ids": null
}
}
## Modify a Tree node [/trees/{tree_id}]
Update or delete a tree node. Application specific data can be specified on the tree node as custom fields which will only be available in your application.
+ Parameters
+ tree_id: 5927d86628592700964a702c (string) - The _id of the tree node
### Update tree node [PUT]
+ Request
+ Attributes
+ parent: null (string) - The _id of the parent if adding as a child to another node in an existing tree
+ name: Kungsgatan (string) - A name to put on the tree node
+ `app_custom_fields`: (object) - Custom key value pairs set by a third party application.
+ `custom_fields`: (object) - Custom key value pairs set by an internal integration.
+ Response 200 (application/json)
+ Attributes (Tree)
+ Body
{
"code": 200,
"message": "OK",
"count": 1,
"skip": 0,
"limit": 50,
"data": [{
"_id": "5927dd3b28592700ad6185dc",
"name": "user node",
"factor": 1,
"app_custom_fields": {},
"parent": null,
"meters": [],
"location": null,
"open_channel_ids": null
}]
}
### Delete tree node [DELETE]
+ Response 200 (application/json)
+ Attributes (Tree)
+ Body
{
"code": 200,
"message": "OK",
"count": 1,
"skip": 0,
"limit": 50,
"data": [{
"_id": "5927dd3b28592700ad6185dc",
"name": "user node",
"factor": 1,
"app_custom_fields": [],
"parent": null,
"meters": [],
"location": null,
"open_channel_ids": null
}]
}
## Add meters to a tree node [/trees/{tree_id}/meters]
Add the user's meters to tree nodes so consumption requests can be made to a node to aggregate values for any meters on that tree node.
Note that to request consumption values for a tree node, every meter added in the tree needs to be in box `active`.
+ Parameters
+ tree_id: 5927d86628592700964a702c (string) - The _id of the tree node
### Add a meter [POST]
+ Request (application/json)
+ Attributes
+ `_id`: 5927dd3b28592700ad6185dc (string) - The _id of meter to add.
+ `factor`: 1 (number) - How much the meter's consumption should contribute to the aggregated consumption value
+ Response 200 (application/json)
+ Attributes (Tree)
+ Body
{
"code": 200,
"message": "OK",
"profiling": [],
"data": {
"_id": "592bc4d328592700c26532bf",
"name": "Kungsgatan",
"factor": 1,
"app_custom_fields": [],
"parent": null,
"meters": [{
"_id": "592bc4d328592700c26532c0",
"root_id": "592bc4d328592700c26532c0",
"factor": 1
}],
"location": null,
"open_channel_ids": null
}
}
## Remove a meter from a Tree node [/trees/{tree_id}/meters/{meter_id}]
Remove a meter reference from a tree node
+ Parameters
+ tree_id: 5927d86628592700964a702c (string) - The _id of the tree node
+ meter_id: 5927d86628592700964a702d (string) - The _id of an addedd meter
### Remove a meter [DELETE]
+ Response 200 (application/json)
## Trees collection [/trees{?parent,app_custom_fields}]
List all of a user's trees or get a subtree by including the query parameter `parent` as the **_id** of the parent node.
It is also possible to filter tree nodes based on app specific custom fields using the query parameter syntax `app_custom_fields.{your_field}={your_value}`
### List trees [GET]
+ Parameters
+ parent: 5927d86628592700964a702c (string) - The _id of the nodes parent. Use `null` to only get root nodes. Then use the _id of each root node to get the nodes below it.
+ Response 200 (application/json)
+ Attributes (Tree)
+ Body
{
"code": 200,
"message": "OK",
"count": 1,
"skip": 0,
"limit": 50,
"data": [{
"_id": "5927dd3b28592700ad6185dc",
"name": "Kungsgatan",
"factor": 1,
"app_custom_fields": {},
"custom_fields": {"object_id": "13415-2345"}
"custom_identifier": "A-4536432"
"parent": null,
"meters": [],
"location": null,
"open_channel_ids": null
}]
}
# Group Consumption
Consumption is the use of energy or other metrics for a meter or a tree node. Consumption is available by the granularities month, day and hour, however, it is important to understand that the availability differs depending on the meter/node and other external factors.
It is only allowed to get consumption for meters that the user has activated and that are not revoked. If a request is made to a meter for which consumption the user does not have access, the response code will be **403 Forbidden**. To avoid this error, you can look on the attributes on the meter "box" and "revoked" to make sure that they have values that indicated that the user is allowed to get consumption values. "revoked" must be false and "box" must be either "active" or "temporary".
## Get Consumption [/consumptions/{id}/{granularity}/{period}?metrics={metrics}]
We support the following **granularities**: hour, day and month, but we cannot guarantee that it is available for every meter.
The following **metrics** are supported:
* energy (kWh)
* estimated_energy (kWh)
* flow (m<sup>3</sup>)
* estimated_flow (m<sup>3</sup>)
* return_temperature (°C)
* supply_temperature (°C)
* temperature (°C)
* tvoc (ppm)
* co2 (ppm)
**Note:** Metric availability varies between meters/nodes.
The response with consumption **values will always match your query**. Missing values are replaced with <code>NULL</code>
Each period in the response will have a `start_date` and `end_date` property. Note that these are UTC dates, so depending on the meter's time zone they may appear to not match the date specified in the `period` input parameter. The `period` parameter is always interpreted using the meter's local timezone.
**Note:** One request is limited 100000 values. To fetch data for a longer period, split the period into multiple requests.
### Meter [GET]
+ Parameters
+ id: 5825c6f6de22ae00632e86f3 (required, string) - The id of the meter to get consumption data for
+ period: `2015-201511` (required, string) - Defines what period to fetch data for. You may enter any combination of YYYY, YYYYMM, YYYYMMDD or YYYYMMDDHH as long as the start date is before the end date. You may also leave out the end date, if you, for instance, would like to just fetch data for 2013. All date will be interpreted using the meters time zone.
+ granularity: month (required, string) - The granularity to get consumption data for (month, day or hour)
+ Updated cost response : `2015-201511` (required, string) - Defines what period to fetch data for. You may enter any combination of YYYY, YYYYMM or YYYYMMDD as long as the start date is before the end date. You may also leave out the end date, if you, for instance, would like to just fetch data for 2013. All date will be interpreted using the meters time zone.
+ metrics: energy (optional, string) - Limits the response to one or more metrics separated by commas. If not specified, default metric is returned.
+ Request
+ Headers
Authorization: Bearer 9f999b72772410cfb4fe0d4309b5f9dabb01e2fafcd7ba946c6cdc11aa8e
+ Response 200 (application/json)
+ Attributes (Consumption)
+ Body
{
"code": 200,
"message": "OK",
"data": [
{
"periods" : [
{
"start_date" : "2013-01-01T00:00:00+0001",
"end_date" : "2013-11-30T23:00:00+0001",
"energy": [1,2,3,4,5,6,7,8,9,10,11],
"flow": [1,2,3,4,5,6,7,8,9,10,11]
}
],
"meter_id": "5825c6f6de22ae00632e86f3"
}
]
}
### Tree Node [GET]
Requesting consumption for a tree node returns the sum of the consumption of all the node's meters per metric. To get the summed consumption for a specific type, add type=heat as a parameter to the url.
+ Parameters
+ id: 5825c6f6de22ae00632e86f3 (required, string) - The id of the tree node to get consumption data for. Only aggregated consumption for meters where box is active are included in the sum.
+ granularity: month (required, string) - The granularity to get consumption data for (month, day or hour)
+ period: `2015-201511` (required, string) - Defines what period to fetch data for. You may enter any combination of YYYY, YYYYMM or YYYYMMDD as long as the start date is before the end date. You may also leave out the end date, if you, for instance, would like to just fetch data for 2013. All date will be interpreted using the meters time zone.
+ metrics: energy (optional, string) - Limits the response to one or more metrics separated by commas. If not specified metric energy is returned.
+ type: heat (optional, string) - Returns the sum for meters that matches the type.
+ Request
+ Headers
Authorization: Bearer 9f999b72772410cfb4fe0d4309b5f9dabb01e2fafcd7ba946c6cdc11aa8e
+ Response 200 (application/json)
+ Attributes (Consumption)
+ Body
{
"code": 200,
"message": "OK",
"data": [
{
"periods" : [
{
"start_date" : "2013-01-01T00:00:00+0001",
"end_date" : "2013-11-30T23:00:00+0001",
"energy": [1,2,3,4,5,6,7,8,9,10,11],
"flow": [1,2,3,4,5,6,7,8,9,10,11],
"energy_quality": [1,1,1,1,1,1,1,1,1,1,0.5]
}
],
"tree_id": "5825c6f6de22ae00632e86f3"
}
]
}
## Multiple meters [/consumptions/multi/{granularity}/{period}?metrics={metrics}]
### Meter by meter [GET]
+ Parameters
+ granularity: month (required, string) - The granularity to get consumption data for (month, day or hour)
+ period: `2015-201511` (required, string) - Defines what period to fetch data for. You may enter any combination of YYYY, YYYYMM or YYYYMMDD as long as the start date is before the end date. You may also leave out the end date, if you, for instance, would like to just fetch data for 2013. All date will be interpreted using the meters time zone.
+ meters: `5825c6f6de22ae00632e86f3,5825c76920fe9b006308e412` (required, array[string]) - An array of meters to return consumptions data for
+ metrics: energy (optional, string) - Limits the response to one or more metrics separated by commas. If not specified metric energy is returned.
+ Request
+ Headers
Authorization: OAuth 9f999b72772410cfb4fe0d4309b5f9dabb01e2fafcd7ba946c6cdc11aa8e
+ Response 200 (application/json)
+ Attributes (Consumption)
+ Body
{
"code": 200,
"message": "OK",
"profiling": null,
"data": [
{
"meter_id": "526f7711a158318a068b475f",
"periods": [
{
"energy": [
null,
57.037,
68.031
],
"start_date": "2017-05-31T23:00:00+0000",
"end_date": "2017-08-31T22:59:59+0000"
}
]
},
{
"meter_id": "56b06f2c81376f5a008b4b23",
"periods": [
{
"energy": [
2369.78,
2236.336,
1488.188
],
"start_date": "2017-05-31T23:00:00+0000",
"end_date": "2017-08-31T22:59:59+0000"
}
]
}
]
}
## Sum of meters [/consumptions/sum/{granularity}/{period}?metrics={metrics}]
### Sum of meters [GET]
+ Parameters
+ granularity: month (required, string) - The granularity to get consumption data for (month, day or hour)
+ period: `2015-201511` (required, string) - Defines what period to fetch data for. You may enter any combination of YYYY, YYYYMM or YYYYMMDD as long as the start date is before the end date. You may also leave out the end date, if you, for instance, would like to just fetch data for 2013. All date will be interpreted using the meters time zone.
+ meters: `5825c6f6de22ae00632e86f3,5825c76920fe9b006308e412` (required, array[string]) - An array of meters to return consumptions data for
+ metrics: energy (optional, string) - Limits the response to one or more metrics separated by commas. If not specified metric energy is returned.
+ Request
+ Headers
Authorization: OAuth 9f999b72772410cfb4fe0d4309b5f9dabb01e2fafcd7ba946c6cdc11aa8e
+ Response 200 (application/json)
+ Attributes (Consumption)
+ Body
{
"code": 200,
"message": "OK",
"profiling": null,
"data": [
{
"periods": [
{
"energy": [
2369.78,
2293.373,
1556.219
],
"energy_quality": [
0.5,
1,
1
]
}
]
}
]
}
# Group Costs
Data representing the cost of energy usage parsed from invoices. Costs are stored as time series data in the same way as consumptions and the api works similarly.
## Get Costs [/costs/{id}/month/{period}?metrics={metrics}]
The only granularity available for costs is month.
The following **metrics** are supported:
* retail_subscription
* retail_usage
* retail_undefined
* retail_total
* grid_subscription
* grid_subscription_power
* grid_subscription_return_temperature
* grid_subscription_flow
* grid_usage
* grid_undefined
* grid_total
Learn more about the definition of each metric here (in Swedish only): https://metry.zendesk.com/hc/sv/articles/360005144654
**Note:** Metric availability varies between meters.
The response with cost **values will always match your query**. Missing values are replaced with <code>NULL</code>
### For a Meter [GET]
+ Parameters
+ id: `5b7e64209b8cffjt9e114d3e` (required, string) - The id of the meter to get cost data for
+ period: `2016` (required, string) - Defines what period to fetch data for. You may enter any combination of YYYY, YYYYMM or YYYYMMDD as long as the start date is before the end date. You may also leave out the end date, if you, for instance, would like to just fetch data for 2013. All date will be interpreted using the meters time zone.
+ metrics: `retail_total,grid_total` (optional, enum [string]) - Limits the response to one or more metrics separated by commas. If not specified `retail_total` and `grid_total`.
+ Request
+ Headers
Authorization: Bearer 9f999b72772410cfb4fe0d4309b5f9dabb01e2fafcd7ba946c6cdc11aa8e
+ Response 200 (application/json)
+ Attributes (Consumption)
+ account_id: (string) The account that the costs are held by.
+ meter_id: (string) The id of the meter the cost data is for.
+ currency: (string) The monetary unit the costs are recorded in.
+ periods: (array[Cost])
+ Body
{
"code": 200,
"message": "OK",
"profiling": [],
"data": [
{
"account_id": "5b7e64f8tb8cfb009e114d3f",
"meter_id": "5b7e64209b8cffjt9e114d3e",
"currency": "SEK",
"periods": [
{
"retail_total": [null, null, null, null, null, null, null, null, null, null, null, null],
"grid_total": [345, 343, 321, 433, 345, 546, 234, 212, 256, 396, 194, 390],
"start_date": "2015-12-31T23:00:00+0000",
"end_date": "2016-12-31T22:59:59+0000"
}
]
}
]
}
# Group Invoices
## Invoices collection [/invoices?status={status}&meter_ids={root_meter_id}&results.ean={ean}&results.invoice_number={invoice_number}]
Invoices collected or uploaded can be listed including the parsed results. The parsed results include various fields that are extracted from the invoice and invoice rows describing the pricing components.
The response will only contain 50 invoices at a time. To get additional invoices, specify the amount to skip as a query parameter as `skip=50`.
Invoices that have successfully been parsed and interpreted will have the `status` property set to **completed**. Add this as a query parameter when listing invoices to not find invoices that for some reason could not be parsed `?status=completed`.
### List invoices [GET]
+ Parameters
+ status: `completed` (string) - Filter invoices with a specific status.
+ meter_ids: `5b7e64209b8cffjt9e114d3e` (string) - The root ID of a meter to find invoices for a specific meter.
+ results.ean: `735999100057526501` (string) - The ID defined for the metering point by the utility provider parsed from the invoices.
+ results.invoice_number: `1234525` (string) - Find an invoice by the invoice number found on the invoice.
+ Request
+ Headers
Authorization: Bearer 9f999b72772410cfb4fe0d4309b5f9dabb01e2fafcd7ba946c6cdc11aa8e
+ Response 200 (application/json)
+ Body
{
"code": 200,
"message": "OK",
"profiling": [],
"count": 1,
"limit": 50,
"skip": 0,
"data": [{
"_id": "540da71a2c3d1c3c008b53682",
"account": {
"_id": "540da71a2c3d1c3c008b53684",
"name": "Example Account"
},
"owner": {
"_id": "540da71a2c3d1c3c008b53683",
"name": "E.ON Sverige"
},
"status": "completed",
"results": [{
"ean": "735999100057526501",
"period": "20190101-20190131",
"due_date": "2019-02-31T00:00:00+0100",
"metrics": {
"grid_total": 2692.884
},
"invoice_number": "1234525",
"total_vat": 673.221,
"total_amount_excl_vat": 2692.884,
"total_amount_due": 3366.105,
"invoice_rows": [{
"description": "Effekt",
"amount": 522,
"contract_type": "grid",
"metric": "grid_subscription_power",
"price": 6,
"price_unit": "kr/kW",
"quantity": 87,
"quantity_unit": "kW,mnd",
"period": "20190101-20190131"
}, {
"description": "Energi",
"amount": 2170.884,
"contract_type": "grid",
"metric": "grid_usage",
"price": 7.778,
"price_unit": "öre/kWh",
"quantity": 27912,
"quantity_unit": "kWh",
"period": "20190101-20190131"
}]
}]
}]
}
# Group Readings
Readings are the exact timestamped values for a meter.
## Get readings [/readings/{meter_id}/{period}?metrics={metrics}]
Each period in the response will have a start_date and end_date property. Note that these are UTC dates, so depending on the meter's time zone they may appear to not match the date specified in the period input parameter. The period parameter is always interpreted in the meter's local timezone.
### Reading status
The `status` for a reading value can be `recorded`, `interpolated` or `meter_change`.
* **recorded:** The value has been recorded exactly at the given point.
* **interpolated:** The value is interpolated based on the surrounded recorded values
* **meter_change:** The meter has changed. A meter change reading is the reading that occurred after a meter change.
### Readings blocked
As new readings are stored in Metry, the system automatically tries to find anomalous readings that could suggest that the incoming readings are incorrect.
If an anomaly is found, then the meter attribute `readings_blocked` will be set to `true`. This prevents new consumption values from being calculated from that point forward and that no readings will be interpolated until the meter attribute `readings_blocked` is changed back to `false`.
This attribute is also included in the response when requesting readings as seen in the example response.
Importing readings from Metry when readings are blocked is possible but should be avoided until the user has resolved the issue with the anomalous reading and unblocked readings.
### Get readings for a meter [GET]
+ Parameters
+ meter_id (required, string, `53294e5ae9cada3306001735`) ... The id of the meter to get reading data for
+ period (required, string `2013-201311`) ... Defines what period to fetch data for. You may enter any combination of YYYY, YYYYMM, YYYYMMDD or YYYYMMDDHH as
long as the start date is before the end date. You may also leave out the end date, if you, for instance, would like to just fetch data for 2013.
All date will be interpreted using the meters timezone.
+ metrics (optional, string `energy,flow,power`) ... Limits the response to one or more metrics separated by commas. If not specified metric energy is returned.
+ Response 200 (application/json)
+ Body
{
"code": 200,
"message": "OK",
"data": [
{
"periods" : [
{
"start_date" : "2016-01-01T14:00:00+0100",
"end_date" : "2016-01-01T15:00:00+0100",
"energy": [
{
"time" : "2016-01-01T14:00:00+0100",
"value" : 12345.11,
"status" : "recorded",
"counter" : null
},
{
"time" : "2016-01-01T15:00:00+0100",
"value" : 12365.11,
"status" : "interpolated",
"counter" : null
},
{
"time" : "2016-01-01T15:13:00+0100",
"value" : 12369.94,
"status" : "recorded",
"counter" : null
}
]
}
],
"readings_blocked": false,
"meter_id" : "53185731df62324818000007"