-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi.yaml
More file actions
3414 lines (3348 loc) · 103 KB
/
openapi.yaml
File metadata and controls
3414 lines (3348 loc) · 103 KB
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
openapi: 3.0.2
info:
title: Akiles
description: Akiles API
contact:
email: support@akiles.app
version: "2.0"
servers:
- url: https://api.akiles.app/v2
tags:
- name: metadata
x-spectacular-title: Metadata
description: |
Most API objects allow you to attach your own, arbitrary key-value metadata in the `metadata` field. You can use it to store references to primary keys of your database, custom states, etc.
Metadata is visible to anyone with admin or API access to your organization. There is a storage limit of 1024 bytes of metadata per object.
- name: organization
x-spectacular-title: Organizations
description: |
Everything in Akiles APIs belongs to an Organization. An organization represents one Akiles customer and can handle multiple sites, gadgets, etc..
Access tokens are tied to organizations too, and they give access only to the objects belonging to the organization.
- name: site
x-spectacular-title: Sites
description: |
A site is a physical place where Akiles gadgets are installed. For example, it can be a building, a floor... Gadgets belong to a particular site.
End users will see one "card" in their app's home screen per site. The site information (email, contact, etc) is displayed in that card.
- name: product
x-spectacular-title: Products
- name: device
x-spectacular-title: Devices
description: |
Physical Akiles device installed in the organization.
Each device has a set of capabilities which depend on the product.
The `device` object also contains an overview of the current device status (online/offline, battery level).
If `hardware_id = null`, the device is "virtual". It is designed for API testing: it behaves as close as possible to a real
device in API calls but is not backed by a real hardware device. Gadget actions always succeed.
- name: gadget
x-spectacular-title: Gadgets
description: |
A gadget is a "thing that can be controlled" by the user. Gadgets can be doors, lights, heating, window blinds...
Gadgets are NOT physical devices. Some devices can have multiple gadgets because they have multiple inputs/outputs so
they can control multiple things (Controllers).
Others can have only one (the Cylinder and the Roomlock, for example). Others can have none (the Gateway Ethernet, for example.
Gadgets can have multiple actions depending on what they are. For example, a normal
door will just have an `open` action, but a blind\ncan have `raise` and `lower`
actions, and a light can have `on` and `off` actions. Actions are identified
by their string ID, and they\nalso have a human-friendly name for display in
the UI.
- name: member
x-spectacular-title: Members
description: ""
- name: member_group
x-spectacular-title: Member groups
description: ""
- name: schedule
x-spectacular-title: Schedules
description: ""
- name: card
x-spectacular-title: Cards
description: "Cards configured for a particular organization"
- name: event
x-spectacular-title: Events
description: |
Everything that happens in an Akiles organization is logged as an Event.
Events are structured in "subject - verb - object" form:
- Subject: *who* did the action. It can be a member, an administrator, an OAuth application...
- Verb: *what action* was done on the object. Create, edit, delete, use...
- Object: *what object* the action was done on. A member, a gadget...
For example:
- gadget action events (i.e. someone opening a door) are reported with the member in the subject, `use` as verb, and the gadget action as object.
- Member editions are reported with the admin user who did the action in the subject, `edit` as the verb, and the member as the object.
### Offline delayed events
Gadget action events originate from the Akiles device when the user uses PINs, NFC cards or phone, or BT from a phone to open. If the Akiles device
is offline (i.e. has no connection to Akiles Cloud), it buffers events in local persistent memory and reports them later when it
becomes online again. When this happens, the event appears with the `created_at` corresponding to the moment it originally happened,
NOT the moment when it was reported.
- name: webhook
x-spectacular-title: Webhooks
description: |
Webhooks allow your server to receive real-time notifications about events happening
in the Akiles organization.
Webhooks send a POST request to the indicated url when a matching event occurs. The request body is a JSON-encoded
[event](#/components/schemas/event), same as you would get in the response of the ["get event" endpoint](#/operations/event_get).
URL can be HTTP or HTTPS. We strongly recommend using HTTPS for production.
### Filtering
Each webhook has a "filter" which specifies which events should be sent to it. A filter is a list of "filter rules". Each rule specifies:
- `object_type`: The value of `object.type` to match. This must be specified, i.e. it's NOT possible to subscribe to all object types.
- `verb`: The value of `verb` to match. If it's set to `null` it matches all verbs, i.e. it IS possible to subscribe to all events about one object type, all verbs.
The webhook filter matches if any of the rules in the array match.
Some examples:
- `"filter": []`: Matches no events. Events match if at least one filter rule matches, which can't happen if there's no rules at all.
- `"filter": [{"verb": "use", "object_type": "gadget_action"}]`: Matches gadget action events.
- `"filter": [{"object_type": "member"}]`: Matches all events related to members (creation, edition, deletion...)
- `"filter": [{"verb": "edit", "object_type": "member"}]`: Matches member edition events.
- `"filter": [{"verb": "edit", "object_type": "member"}, {"verb": "use", "object_type": "gadget_action"}]`: Matches member editions, and gadget actions.
An event will be sent to this webhook if it matches at least one rule. If it matches multiple rules, it will only be sent once. If it matches multiple webhook objects, it will be sent once per webhook to its respective URL, even if the URL is the same.
### Signature
If an attacker learns the URL of your webhook, they could send requests themselves to it, spoofing webhooks.
To prevent this, Akiles signs the webhook requests so that your server can check they come from Akiles and not
an attacker. It's strongly recommended to verify the signature.
The signature is the result of applying HMAC-SHA256 to the raw request body bytes, using the webhook secret as a key.
It's sent in the `X-Akiles-Sig-SHA256` HTTP header.
The secret is returned when you create the webhook. It's not possible to view the secret of an existing webhook,
you have to delete and recreate it instead.
The following is an example of how to receive webhooks and validate the signature using nodejs:
```js
import url from 'url'
import http from 'http'
import crypto from 'crypto'
// replace with the secret you get when creating the webhook.
const webhookSecret = 'f305d484fd10de285b00bb203659e863';
const app = http.createServer((request, response) => {
let body = [];
request.on('data', (chunk) => {
body.push(chunk);
}).on('end', () => {
body = Buffer.concat(body).toString();
const gotSig = Buffer.from(request.headers['x-akiles-sig-sha256'], 'hex');
const expectedSig = crypto.createHmac("sha256", webhookSecret).update(body).digest();
const ok = crypto.timingSafeEqual(gotSig, expectedSig);
if (!ok) {
response.writeHead(400);
response.write('bad sig');
response.end();
return;
}
const event = JSON.parse(body.toString());
console.log('Got event!');
console.log(event);
response.writeHead(200);
response.write('cool');
response.end();
});
});
app.listen(8088);
```
### Delivery
Webhook delivery is considered successful if your server returns a 2xx status code.
Unsuccessful deliveries are retried, with an exponential backoff starting at a few seconds and
doubling every time, for up to 1 hour.
paths:
/organization:
get:
tags:
- organization
summary: Get organization
operationId: organization_get
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/organization"
patch:
tags:
- organization
summary: Edit organization
operationId: organization_edit
requestBody:
description: Member to edit
required: true
content:
application/json:
schema:
type: object
properties:
metadata:
$ref: "#/components/schemas/metadata"
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/organization"
/sites:
get:
tags:
- site
summary: List sites
operationId: site_list
parameters:
- $ref: "#/components/parameters/cursor"
- $ref: "#/components/parameters/limit"
- $ref: "#/components/parameters/sort"
responses:
200:
description: Success
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/site"
has_next:
type: boolean
example: true
cursor_next:
type: string
format: cursor
/sites/{site_id}:
parameters:
- name: site_id
in: path
description: site ID
required: true
schema:
type: string
format: site_id
get:
tags:
- site
summary: Get site
operationId: site_get
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/site"
patch:
tags:
- site
summary: Edit site
operationId: site_edit
requestBody:
description: Site to edit
required: true
content:
application/json:
schema:
type: object
properties:
metadata:
$ref: "#/components/schemas/metadata"
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/site"
/products:
get:
tags:
- product
summary: List products
operationId: product_list
parameters:
- $ref: "#/components/parameters/cursor"
- $ref: "#/components/parameters/limit"
- $ref: "#/components/parameters/sort"
responses:
200:
description: Success
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/product"
has_next:
type: boolean
example: true
cursor_next:
type: string
format: cursor
/products/{product_id}:
parameters:
- name: product_id
in: path
description: product ID
required: true
schema:
type: string
format: product_id
get:
tags:
- product
summary: Get product
operationId: product_get
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/product"
/devices:
get:
tags:
- device
summary: List devices
operationId: device_list
parameters:
- $ref: "#/components/parameters/cursor"
- $ref: "#/components/parameters/limit"
- $ref: "#/components/parameters/sort"
responses:
200:
description: Success
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/device"
has_next:
type: boolean
example: true
cursor_next:
type: string
format: cursor
/devices/{device_id}:
parameters:
- name: device_id
in: path
description: device ID
required: true
schema:
type: string
format: device_id
get:
tags:
- device
summary: Get device
operationId: device_get
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/device"
patch:
tags:
- device
summary: Edit device
operationId: device_edit
requestBody:
description: Gadget to edit
required: true
content:
application/json:
schema:
type: object
properties:
metadata:
$ref: "#/components/schemas/metadata"
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/device"
/gadgets:
get:
tags:
- gadget
summary: List gadgets
operationId: gadget_list
parameters:
- $ref: "#/components/parameters/cursor"
- $ref: "#/components/parameters/limit"
- $ref: "#/components/parameters/sort"
responses:
200:
description: Success
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/gadget"
has_next:
type: boolean
example: true
cursor_next:
type: string
format: cursor
/gadgets/{gadget_id}:
parameters:
- name: gadget_id
in: path
description: gadget ID
required: true
schema:
type: string
format: gadget_id
get:
tags:
- gadget
summary: Get gadget
operationId: gadget_get
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/gadget"
patch:
tags:
- gadget
summary: Edit gadget
operationId: gadget_edit
requestBody:
description: Gadget to edit
required: true
content:
application/json:
schema:
type: object
properties:
metadata:
$ref: "#/components/schemas/metadata"
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/gadget"
/gadgets/{gadget_id}/actions/{action_id}:
parameters:
- name: gadget_id
in: path
description: gadget ID
required: true
schema:
type: string
format: gadget_id
- name: action_id
in: path
description: gadget action ID
required: true
schema:
type: string
post:
tags:
- gadget
summary: Do gadget action
description: This endpoint is only available to Akiles customers that have the whitelabel integration feature which has extra cost. If you want to make your integration public we recommend using the non whitelabel option.
operationId: gadget_action
requestBody:
content:
application/json:
schema:
type: object
example: {}
required: true
responses:
200:
description: Success
content:
application/json:
schema:
type: object
example: {}
x-codegen-request-body-name: body
/events:
get:
tags:
- event
summary: List events
operationId: event_list
parameters:
- $ref: "#/components/parameters/cursor"
- $ref: "#/components/parameters/limit"
- $ref: "#/components/parameters/sort"
responses:
200:
description: Success
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/event"
has_next:
type: boolean
example: true
cursor_next:
type: string
format: cursor
/events/{event_id}:
parameters:
- name: event_id
in: path
description: event ID
required: true
schema:
type: string
format: event_id
get:
tags:
- event
summary: Get event
operationId: event_get
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/event"
/members:
get:
tags:
- member
summary: List members
operationId: member_list
parameters:
- $ref: "#/components/parameters/cursor"
- $ref: "#/components/parameters/limit"
- $ref: "#/components/parameters/sort"
- $ref: "#/components/parameters/is_deleted"
- name: email
in: query
description: Filter by email address
required: false
schema:
type: string
example: support@akiles.app
- name: metadata.source
in: query
description: Filter by metadata.source
required: false
schema:
type: string
- name: metadata.sourceID
in: query
description: Filter by metadata.sourceID
required: false
schema:
type: string
responses:
200:
description: Success
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/member"
has_next:
type: boolean
example: true
cursor_next:
type: string
format: cursor
post:
tags:
- member
summary: Create member
operationId: member_create
requestBody:
description: Member to create
required: true
content:
application/json:
schema:
type: object
properties:
name:
type: string
description:
Member name shown in the admin panel. This is for the organization
admins to identify the member, it's never shown to the user.
example: John Doe
starts_at:
type: string
description:
Start date of the member's access. If null, the access is valid
immediately.
nullable: true
format: date-time
ends_at:
type: string
description:
End date of the member's access. If null, the access is valid
forever (ie, until an end date is set or the member is deleted.)
nullable: true
format: date-time
metadata:
$ref: "#/components/schemas/metadata"
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/member"
/members/{member_id}:
parameters:
- name: member_id
in: path
description: member ID
required: true
schema:
type: string
format: member_id
get:
tags:
- member
summary: Get member
operationId: member_get
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/member"
patch:
tags:
- member
summary: Edit member
operationId: member_edit
requestBody:
description: Member to edit
required: true
content:
application/json:
schema:
type: object
required: []
properties:
name:
type: string
description:
Member name shown in the admin panel. This is for the organization
admins to identify the member, it's never shown to the user.
example: John Doe
starts_at:
type: string
nullable: true
description:
Start date of the member's access. If null, the access is valid
immediately.
format: date-time
ends_at:
type: string
nullable: true
description:
End date of the member's access. If null, the access is valid
forever (ie, until an end date is set or the member is deleted.)
format: date-time
is_deleted:
type: boolean
description: True if this object has been deleted.
example: false
metadata:
$ref: "#/components/schemas/metadata"
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/member"
delete:
tags:
- member
summary: Delete member
operationId: member_delete
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/member"
/members/{member_id}/emails:
parameters:
- name: member_id
in: path
description: member ID
required: true
schema:
type: string
format: member_id
get:
tags:
- member
summary: List emails
operationId: member_email_list
parameters:
- $ref: "#/components/parameters/cursor"
- $ref: "#/components/parameters/limit"
- $ref: "#/components/parameters/q"
- $ref: "#/components/parameters/sort"
responses:
200:
description: Success
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/member_email"
has_next:
type: boolean
example: true
cursor_next:
type: string
format: cursor
post:
tags:
- member
summary: Create email
operationId: member_email_create
requestBody:
description: Member email to create
required: true
content:
application/json:
schema:
type: object
properties:
email:
type: string
description: Email address
format: email
metadata:
$ref: "#/components/schemas/metadata"
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/member_email"
/members/{member_id}/emails/{member_email_id}:
parameters:
- name: member_id
in: path
description: member ID
required: true
schema:
type: string
format: member_id
- name: member_email_id
in: path
description: member email ID
required: true
schema:
type: string
format: member_email_id
get:
tags:
- member
summary: Get email
operationId: member_email_get
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/member_email"
patch:
tags:
- member
summary: Edit email
operationId: member_email_edit
requestBody:
description: Member email to edit
required: true
content:
application/json:
schema:
type: object
properties:
metadata:
$ref: "#/components/schemas/metadata"
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/member_email"
delete:
tags:
- member
summary: Delete email
operationId: member_email_delete
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/member_email"
/members/{member_id}/magic_links:
parameters:
- name: member_id
in: path
description: member ID
required: true
schema:
type: string
format: member_id
get:
tags:
- member
summary: List magic links
operationId: member_magic_link_list
parameters:
- $ref: "#/components/parameters/cursor"
- $ref: "#/components/parameters/limit"
- $ref: "#/components/parameters/sort"
responses:
200:
description: Success
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/member_magic_link"
has_next:
type: boolean
example: true
cursor_next:
type: string
format: cursor
post:
tags:
- member
summary: Create magic link
operationId: member_magic_link_create
requestBody:
description: Member magic_link to create
required: true
content:
application/json:
schema:
type: object
properties:
metadata:
$ref: "#/components/schemas/metadata"
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/member_magic_link_revealed"
/members/{member_id}/magic_links/{member_magic_link_id}:
parameters:
- name: member_id
in: path
description: member ID
required: true
schema:
type: string
format: member_id
- name: member_magic_link_id
in: path
description: member magic link ID
required: true
schema:
type: string
format: member_magic_link_id
get:
tags:
- member
summary: Get magic link
operationId: member_magic_link_get
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/member_magic_link"
patch:
tags:
- member
summary: Edit magic link
operationId: member_magic_link_edit
requestBody:
description: Member magic_link to edit
required: true
content:
application/json:
schema:
type: object
properties:
metadata:
$ref: "#/components/schemas/metadata"
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/member_magic_link"
delete:
tags:
- member
summary: Delete magic link
operationId: member_magic_link_delete
responses:
200:
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/member_magic_link"
/members/{member_id}/magic_links/{member_magic_link_id}/reveal:
parameters:
- name: member_id
in: path
description: member ID
required: true
schema:
type: string
format: member_id
- name: member_magic_link_id
in: path
description: member magic link ID
required: true
schema:
type: string
format: member_magic_link_id
post:
tags:
- member
summary: Reveal magic link
operationId: member_magic_link_reveal