Repository navigation
Expand file tree
/
Copy pathopenapi.yaml
More file actions
1004 lines (992 loc) · 39.4 KB
/
Copy pathopenapi.yaml
File metadata and controls
1004 lines (992 loc) · 39.4 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.1.0
info:
title: Siren Affiliate Platform API
version: 0.2.0
summary: Headless affiliate & incentive tracking API for the Siren SaaS.
description: |
The Siren API lets any commerce stack record sales, refunds, and referred
visits, subscribe to program events via signed webhooks, and reconcile
Siren's ledger against its own.
This document describes the **developer-facing surface**: event ingestion,
webhooks, API keys, and read endpoints for reconciliation. The full admin
surface used by the Siren dashboard is intentionally out of scope here.
Every request carries a bearer token. An API key
(`Authorization: Bearer sk_live_...`) sends events with an event scope
and calls `GET /ping`. With a ledger scope it reads conversions,
transactions, obligations and payouts, and with a webhook scope it reads
and manages webhook subscriptions. Every other route, the API key routes
included, answers an API key with 401 `api_key_not_accepted`. Those take
a signed-in dashboard session's token. The reconciliation routes also
take a connected site's OAuth token that holds `connect:records:read`.
Each operation lists the credentials it takes in its `security`, and the
scopes an API key needs.
Success bodies are not wrapped. A record is a bare object. The webhook
and API key lists are bare arrays, and the reconciliation lists are
`{ items, total, page, perPage, totalPages }`. A failure is
`{ "error": { "message", "code"?, "context" } }`, and a few routes answer
`{ "error": "<message>" }`. A request whose fields fail their checks gets
a 400 with `context.type` of `VALIDATION_FAILED` and the messages in
`context.failedValidations`.
contact:
name: Siren
url: https://sirenaffiliates.com
license:
name: Proprietary
servers:
- url: https://api.sirenaffiliates.com/siren/v1
description: Production
- url: http://localhost:8080/siren/v1
description: Local development
security:
- dashboardSession: []
tags:
- name: Events
description: Ingest commerce and tracking events.
- name: Webhooks
description: |
Subscribe to program events, delivered as signed HTTP callbacks.
Each delivery is a `POST` with `X-Siren-Signature: sha256=<hex>` (an
HMAC-SHA256 of the raw body keyed by the subscription's signing secret),
`X-Siren-Event` (the event type) and `X-Siren-Delivery` (the event id,
`evt_...`, which stays the same across retries). For a subscription made
through `POST /webhooks` the body is the event's payload alone, such as
`{"conversionId": 991}`. A subscription that belongs to a connected site
gets a versioned envelope instead:
`{version, id, type, kind, occurredAt, propertyId, match,
originPropertyId, data, records, recordDetail, omittedRecords,
recordsTruncated}`. Both kinds carry the same headers. An envelope's
`id` is the `X-Siren-Delivery` value and its `type` is the
`X-Siren-Event` value, which a plain payload's own fields never match.
- name: API Keys
description: Manage API keys.
- name: Reconciliation
description: Read Siren's ledger to reconcile against your own records.
paths:
/event/sale:
post:
tags: [Events]
operationId: recordSale
summary: Record a completed sale
description: |
Records a sale so conversions and payouts compute for the attributed
collaborator. `total` is in major currency units (9.99 = $9.99). If
`items` are supplied, reward pools compute `amount × quantity` per line;
otherwise `total` is treated as one line. The opportunity id is returned
in the `X-Siren-OID` response header.
security:
- apiKey: []
- dashboardSession: []
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/SalePayload' }
responses:
'200':
description: |
The sale was handled. The body says what came of it. Sending the
same `source` and `externalId` again records nothing new and
answers `duplicate`.
headers:
X-Siren-OID: { $ref: '#/components/headers/XSirenOID' }
content:
application/json:
schema: { $ref: '#/components/schemas/SaleOutcome' }
'202': { $ref: '#/components/responses/Queued' }
'400': { $ref: '#/components/responses/BadRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'429': { $ref: '#/components/responses/RateLimited' }
'500':
description: The sale could not be recorded and nothing was saved. It is safe to send it again.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
/event/refund:
post:
tags: [Events]
operationId: recordRefund
summary: Record a refund
description: |
Reverses a previously recorded sale, matched by `(externalId, source)`.
Returns 404 if no matching sale transaction exists. While the
organization's processing is paused the refund is queued (202) and the
sale is looked up when the queue replays.
security:
- apiKey: []
- dashboardSession: []
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/RefundPayload' }
responses:
'200':
description: Refund accepted. The body is empty.
headers:
X-Siren-OID: { $ref: '#/components/headers/XSirenOID' }
'202': { $ref: '#/components/responses/Queued' }
'400': { $ref: '#/components/responses/BadRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'404': { $ref: '#/components/responses/NotFound' }
'429': { $ref: '#/components/responses/RateLimited' }
/event/site-visited:
post:
tags: [Events]
operationId: recordSiteVisited
summary: Record a referred visit
description: |
Records a referred visit and opens an opportunity attributed to the
given collaborator. A visit for a collaborator that does not exist or
is not active writes nothing and answers `not_attributed` with a
`reason`.
security:
- apiKey: []
- connectorToken: []
- dashboardSession: []
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/SiteVisitedPayload' }
responses:
'200':
description: The visit was handled. The body says what came of it.
headers:
X-Siren-OID: { $ref: '#/components/headers/XSirenOID' }
content:
application/json:
schema: { $ref: '#/components/schemas/VisitOutcome' }
'202':
description: |
The organization's processing is paused. The visit was queued and
will be recorded on the returned opportunity.
headers:
X-Siren-OID: { $ref: '#/components/headers/XSirenOID' }
content:
application/json:
schema: { $ref: '#/components/schemas/VisitOutcome' }
'400': { $ref: '#/components/responses/BadRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'429': { $ref: '#/components/responses/RateLimited' }
/event/{eventSlug}:
post:
tags: [Events]
operationId: recordEvent
summary: Record a custom event
description: |
Ingests any event type registered on the organization, including custom
event types. The three built-in slugs are `sale`, `refund`, and
`site-visited`. Custom slugs are lowercase letters and digits joined
by single hyphens. An unknown slug answers 404. The slugs a connected
site forwards, such as `sale-triggered`, need that exact
`event:{slug}` scope, and `event:*` does not reach them.
security:
- apiKey: []
- connectorToken: []
- dashboardSession: []
parameters:
- name: eventSlug
in: path
required: true
schema: { type: string, pattern: '^[a-z0-9]+(-[a-z0-9]+)*$' }
example: loyalty-points-earned
requestBody:
required: true
content:
application/json:
schema:
type: object
additionalProperties: true
responses:
'200':
description: Event accepted.
headers:
X-Siren-OID: { $ref: '#/components/headers/XSirenOID' }
'202': { $ref: '#/components/responses/Queued' }
'400': { $ref: '#/components/responses/BadRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'404': { $ref: '#/components/responses/NotFound' }
'429': { $ref: '#/components/responses/RateLimited' }
/ping:
get:
tags: [Events]
operationId: ping
summary: Check a credential
description: |
Answers with the organization the credential belongs to, so a sender
can check its API key before it sends events.
security:
- apiKey: []
- connectorToken: []
- dashboardSession: []
responses:
'200':
description: The credential works.
content:
application/json:
schema:
type: object
required: [ok, org]
properties:
ok: { type: boolean, const: true }
org:
type: object
properties:
id: { type: integer }
name: { type: string }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
/webhooks:
get:
tags: [Webhooks]
operationId: listWebhookSubscriptions
summary: List webhook subscriptions
description: |
An API key needs `webhook-subscriptions:read` or
`webhook-subscriptions:manage`, and must be organization-wide. A key
bound to one store is refused with 403 `store_key_not_allowed`.
security:
- apiKey: ['webhook-subscriptions:read']
- apiKey: ['webhook-subscriptions:manage']
- dashboardSession: []
parameters:
- { $ref: '#/components/parameters/Number200' }
- { $ref: '#/components/parameters/Offset' }
responses:
'200':
description: Subscriptions (bare array). The total is in `x-siren-estimated-count`.
headers:
x-siren-estimated-count: { $ref: '#/components/headers/EstimatedCount' }
content:
application/json:
schema:
type: array
items: { $ref: '#/components/schemas/WebhookSubscription' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
post:
tags: [Webhooks]
operationId: createWebhookSubscription
summary: Create a webhook subscription
description: |
Registers a URL to receive event callbacks. The response includes
`signingSecret`, returned **once** — store it to verify future
deliveries. Deliveries are signed with
`X-Siren-Signature: sha256=<hmac-sha256(rawBody, signingSecret)>`.
`events` is stored as given and is not checked against the catalog,
so a name Siren does not send is accepted and never delivered. An
organization holds at most 100 subscriptions.
An API key needs `webhook-subscriptions:manage`, and must be
organization-wide. A key bound to one store is refused with 403
`store_key_not_allowed`.
security:
- apiKey: ['webhook-subscriptions:manage']
- dashboardSession: []
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/WebhookSubscriptionCreate' }
responses:
'201':
description: Subscription created.
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/WebhookSubscription'
- type: object
properties:
signingSecret:
type: string
description: HMAC signing secret. Returned once.
'400': { $ref: '#/components/responses/BadRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
/webhooks/events:
get:
tags: [Webhooks]
operationId: listWebhookEventTypes
summary: List the event types a webhook can subscribe to
description: |
The catalog the dashboard's event picker is built from. It names
exactly the event types Siren sends.
An API key needs `webhook-subscriptions:read` or
`webhook-subscriptions:manage`, and must be organization-wide. A key
bound to one store is refused with 403 `store_key_not_allowed`.
security:
- apiKey: ['webhook-subscriptions:read']
- apiKey: ['webhook-subscriptions:manage']
- dashboardSession: []
responses:
'200':
description: Event types (bare array).
content:
application/json:
schema:
type: array
items: { $ref: '#/components/schemas/WebhookCatalogEntry' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
/webhooks/{id}:
get:
tags: [Webhooks]
operationId: getWebhookSubscription
summary: Get a webhook subscription
description: |
An API key needs `webhook-subscriptions:read` or
`webhook-subscriptions:manage`, and must be organization-wide. A key
bound to one store is refused with 403 `store_key_not_allowed`.
security:
- apiKey: ['webhook-subscriptions:read']
- apiKey: ['webhook-subscriptions:manage']
- dashboardSession: []
parameters:
- { name: id, in: path, required: true, schema: { type: integer } }
responses:
'200':
description: Subscription (bare object).
content:
application/json:
schema: { $ref: '#/components/schemas/WebhookSubscription' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'404': { $ref: '#/components/responses/NotFound' }
delete:
tags: [Webhooks]
operationId: deleteWebhookSubscription
summary: Delete a webhook subscription
description: |
An API key needs `webhook-subscriptions:manage`, and must be
organization-wide. A key bound to one store is refused with 403
`store_key_not_allowed`.
security:
- apiKey: ['webhook-subscriptions:manage']
- dashboardSession: []
parameters:
- { name: id, in: path, required: true, schema: { type: integer } }
responses:
'200':
description: Deleted.
content:
application/json:
schema:
type: object
properties:
success: { type: boolean, example: true }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'404': { $ref: '#/components/responses/NotFound' }
/webhooks/{id}/test:
post:
tags: [Webhooks]
operationId: sendWebhookTest
summary: Send a test delivery
description: |
Sends the subscription one signed sample delivery now. Siren answers
200 whatever the endpoint answered, with what came of it, and the
test shows in the subscription's delivery history. Siren answers 404
for a subscription the organization does not have and 409 for a
paused one. Each test makes Siren send a request, so the number of
tests per hour is limited, and Siren answers 429 past it.
An API key needs `webhook-subscriptions:manage`, and must be
organization-wide. A key that holds only `webhook-subscriptions:read`
is refused with 403 `missing_scope`, and a key bound to one store
with 403 `store_key_not_allowed`.
security:
- apiKey: ['webhook-subscriptions:manage']
- dashboardSession: []
parameters:
- { name: id, in: path, required: true, schema: { type: integer } }
responses:
'200':
description: The test was sent. The body says what the endpoint answered.
content:
application/json:
schema:
type: object
properties:
delivered: { type: boolean, description: Whether the endpoint accepted the delivery. }
httpStatus: { type: [integer, 'null'], description: The status the endpoint answered with, or null when it could not be reached. }
error: { type: [string, 'null'], description: Why the delivery failed, when it did. }
eventType: { type: string, description: The event type the sample delivery named. }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'404': { $ref: '#/components/responses/NotFound' }
'409':
description: The subscription is paused.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
'429':
description: Too many test deliveries in the last hour.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
/api-keys:
get:
tags: [API Keys]
operationId: listApiKeys
summary: List API keys
description: |
Organization admins only. Revoked keys are listed too.
Takes a signed-in dashboard session. No API key scope reaches this
route, and Siren answers an API key with 401 `api_key_not_accepted`.
security:
- dashboardSession: []
parameters:
- { $ref: '#/components/parameters/Number200' }
- { $ref: '#/components/parameters/Offset' }
responses:
'200':
description: API keys (bare array, without raw key material). The total is in `x-siren-estimated-count`.
headers:
x-siren-estimated-count: { $ref: '#/components/headers/EstimatedCount' }
content:
application/json:
schema:
type: array
items: { $ref: '#/components/schemas/ApiKey' }
'401': { $ref: '#/components/responses/Unauthorized' }
post:
tags: [API Keys]
operationId: createApiKey
summary: Create an API key
description: |
Creates a new API key. Organization admins only. The plaintext
`rawKey` (`sk_live_...`) is returned **once** and cannot be retrieved
later. A key holds event scopes (`event:*` or `event:{slug}`, or
`*`), the ledger read scopes and the webhook scopes. An older
resource scope such as `programs:read` or `conversions:read` is
refused with a 400. An organization holds at most 250 active keys.
Takes a signed-in dashboard session. No API key scope reaches this
route, and Siren answers an API key with 401 `api_key_not_accepted`.
security:
- dashboardSession: []
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/ApiKeyCreate' }
responses:
'201':
description: API key created.
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/ApiKey'
- type: object
properties:
rawKey:
type: string
description: Plaintext key. Returned once.
'400': { $ref: '#/components/responses/BadRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
/api-keys/{id}:
delete:
tags: [API Keys]
operationId: revokeApiKey
summary: Revoke an API key
description: |
Takes a signed-in dashboard session. No API key scope reaches this
route, and Siren answers an API key with 401 `api_key_not_accepted`.
security:
- dashboardSession: []
parameters:
- { name: id, in: path, required: true, schema: { type: integer } }
responses:
'200':
description: Revoked. The body is the revoked key.
content:
application/json:
schema: { $ref: '#/components/schemas/ApiKey' }
'401': { $ref: '#/components/responses/Unauthorized' }
'404': { $ref: '#/components/responses/NotFound' }
/conversions:
get:
tags: [Reconciliation]
operationId: listConversions
summary: List conversions
description: |
An API key needs the `ledger:conversions:read` scope. A key bound to one
store reads only its own store's rows. An organization-wide key may
narrow the read to one store with `propertyId` or the
`X-Siren-Property` header.
security:
- apiKey: ['ledger:conversions:read']
- dashboardSession: []
- connectorToken: []
parameters:
- { $ref: '#/components/parameters/Number' }
- { $ref: '#/components/parameters/Offset' }
- { $ref: '#/components/parameters/PropertyId' }
- { $ref: '#/components/parameters/XSirenProperty' }
responses:
'200': { $ref: '#/components/responses/PaginatedList' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
/transactions:
get:
tags: [Reconciliation]
operationId: listTransactions
summary: List transactions
description: |
An API key needs the `ledger:transactions:read` scope. A key bound to one
store reads only its own store's rows. An organization-wide key may
narrow the read to one store with `propertyId` or the
`X-Siren-Property` header.
security:
- apiKey: ['ledger:transactions:read']
- dashboardSession: []
- connectorToken: []
parameters:
- { $ref: '#/components/parameters/Number' }
- { $ref: '#/components/parameters/Offset' }
- { $ref: '#/components/parameters/PropertyId' }
- { $ref: '#/components/parameters/XSirenProperty' }
responses:
'200': { $ref: '#/components/responses/PaginatedList' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
/obligations:
get:
tags: [Reconciliation]
operationId: listObligations
summary: List obligations
description: |
An API key needs the `ledger:obligations:read` scope. A key bound to one
store reads only its own store's rows. An organization-wide key may
narrow the read to one store with `propertyId` or the
`X-Siren-Property` header.
security:
- apiKey: ['ledger:obligations:read']
- dashboardSession: []
- connectorToken: []
parameters:
- { $ref: '#/components/parameters/Number' }
- { $ref: '#/components/parameters/Offset' }
- { $ref: '#/components/parameters/PropertyId' }
- { $ref: '#/components/parameters/XSirenProperty' }
responses:
'200': { $ref: '#/components/responses/PaginatedList' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
/payouts:
get:
tags: [Reconciliation]
operationId: listPayouts
summary: List payouts
description: |
An API key needs the `ledger:payouts:read` scope, and must be
organization-wide. Payouts are not kept by store, so a key bound to
one store is refused with 403 `store_key_not_allowed`.
security:
- apiKey: ['ledger:payouts:read']
- dashboardSession: []
- connectorToken: []
parameters:
- { $ref: '#/components/parameters/Number' }
- { $ref: '#/components/parameters/Offset' }
responses:
'200': { $ref: '#/components/responses/PaginatedList' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
components:
securitySchemes:
apiKey:
type: http
scheme: bearer
bearerFormat: sk_live_...
description: |
An API key minted in the Siren dashboard or via createApiKey. Event
scopes send events. The ledger scopes read conversions, transactions,
obligations and payouts, and the webhook scopes read and manage
webhook subscriptions. Each operation lists the scopes that open it,
and holding any one listed requirement is enough. Every other route
answers an API key with 401 `api_key_not_accepted`, the API key
routes included. A key's requests count against the organization's
API rate limit.
dashboardSession:
type: http
scheme: bearer
bearerFormat: JWT
description: |
The access token of a person signed in to the Siren dashboard. Some
routes need the admin role, and refuse other roles with a 403 whose
code is `admin_required`.
connectorToken:
type: http
scheme: bearer
bearerFormat: JWT
description: |
A connected site's OAuth access token, issued when an organization
admin approves the site. The reconciliation routes take it when it
holds `connect:records:read`.
headers:
XSirenOID:
description: The opportunity (tracking) id associated with the event.
schema: { type: integer }
EstimatedCount:
description: Total number of records across all pages.
schema: { type: integer }
parameters:
Number:
name: number
in: query
description: Page size. A value above 200 is lowered to 200. Below 1 is refused with a 400.
schema: { type: integer, minimum: 1, default: 10 }
Number200:
name: number
in: query
description: Page size. A value above 200 is lowered to 200. Below 1 is refused with a 400.
schema: { type: integer, minimum: 1, default: 200 }
Offset:
name: offset
in: query
description: The first row to return.
schema: { type: integer, minimum: 0, default: 0 }
PropertyId:
name: propertyId
in: query
description: |
Narrows an organization-wide read to one store (Property). A key
bound to one store reads only its own store's rows, whatever it
sends here.
schema: { type: integer, minimum: 1 }
XSirenProperty:
name: X-Siren-Property
in: header
description: The same one-store filter as `propertyId`, sent as a header.
schema: { type: integer, minimum: 1 }
schemas:
SalePayload:
type: object
required: [source, externalId, total, trackingId]
properties:
source:
type: string
description: Commerce source identifier.
minLength: 1
maxLength: 249
example: stripe
externalId:
type: [string, number]
minLength: 1
maxLength: 32
description: |
Your order or transaction id, used to match refunds later. Siren
also takes a number and stores it as text.
example: cs_test_a1b2c3
total:
type: number
description: Order total in major currency units.
minimum: 0
maximum: 999999999.99
example: 49.99
trackingId:
type: integer
description: Opportunity id from the Siren tracking cookie / attribution.
minimum: 0
example: 4021
currency:
type: string
description: |
A currency code the organization uses. Every line is recorded in
it. Without it the lines carry no currency and read as the
organization's default.
example: USD
items:
type: array
maxItems: 500
description: The lines may add up to no more than 999,999,999.99.
items: { $ref: '#/components/schemas/LineItem' }
LineItem:
type: object
required: [amount]
properties:
externalId: { type: [string, number], maxLength: 255, description: 'Text, or a number that Siren stores as text.' }
name: { type: [string, number], maxLength: 255, description: 'Text, or a number that Siren stores as text.', example: Pro Plan (annual) }
quantity: { type: integer, minimum: 1, maximum: 1000000, default: 1 }
amount:
type: number
description: Per-unit price in major currency units.
minimum: 0
maximum: 999999999.99
example: 49.99
RefundPayload:
type: object
required: [source, externalId]
properties:
source: { type: string, minLength: 1, maxLength: 249, example: stripe }
externalId: { type: [string, number], minLength: 1, maxLength: 32, example: cs_test_a1b2c3 }
SiteVisitedPayload:
type: object
required: [collaboratorId]
properties:
collaboratorId: { type: integer, minimum: 1, example: 88 }
userId: { type: integer, minimum: 1, example: 12345 }
SaleOutcome:
type: object
properties:
status:
type: string
enum: [created, recorded, duplicate, unattributed, ignored]
created: { type: boolean }
transactionId: { type: integer, nullable: true }
conversions:
type: array
items:
type: object
properties:
id: { type: integer }
status: { type: string }
message: { type: string }
reason:
type: string
description: Present when a recorded sale earned nothing.
enum: [no_engagement, engagement_used, engagement_ended, not_awarded]
VisitOutcome:
type: object
properties:
status:
type: string
enum: [attributed, recorded, not_attributed, queued]
attributed: { type: boolean }
opportunityId: { type: integer, nullable: true }
queued: { type: boolean }
message: { type: string }
reason:
type: string
enum: [collaborator_not_found, collaborator_not_active]
QueuedEvent:
type: object
properties:
status: { type: string, enum: [queued] }
queued: { type: boolean, enum: [true] }
message: { type: string }
WebhookSubscription:
type: object
properties:
id: { type: integer }
targetUrl: { type: string, format: uri }
urlValid: { type: boolean }
urlProblem: { type: string, nullable: true }
events:
type: array
items: { type: string }
status: { type: string, example: active }
description: { type: string }
propertyId: { type: integer, nullable: true }
oauthClientId: { type: string, nullable: true }
dateCreated: { type: string, format: date-time, nullable: true }
dateModified: { type: string, format: date-time, nullable: true }
WebhookCatalogEntry:
type: object
properties:
event: { $ref: '#/components/schemas/WebhookEventType' }
category: { type: string, example: Conversions }
label: { type: string, example: A conversion was approved }
WebhookSubscriptionCreate:
type: object
required: [targetUrl, events]
properties:
targetUrl: { type: string, format: uri, example: https://example.com/webhooks/siren }
events:
type: array
items: { $ref: '#/components/schemas/WebhookEventType' }
example: ['conversion.approved', 'payout.paid']
description: { type: string, maxLength: 255 }
WebhookEventType:
type: string
description: A subscribable event type. Use `*` to subscribe to all.
enum:
- '*'
- allocation.completed
- collaborator.created
- collaborator.deactivated
- collaborator.registered
- collaborator.updated
- conversion.approved
- conversion.created
- conversion.rejected
- conversion.renewed
- coupon.applied
- credit.issued
- credit.redeemed
- currency.created
- currency.deleted
- distribution.completed
- engagement.awarded
- engagement.completed
- engagement.created
- fulfillment.created
- fulfillment.updated
- lead.created
- metrics.updated
- obligation.completed
- obligation.created
- opportunity.created
- opportunity.invalidated
- payout.created
- payout.paid
- program.created
- refund.created
- renewal.created
- sale.created
- transaction.completed
- transaction.created
ApiKey:
type: object
properties:
id: { type: integer }
keyPrefix: { type: string, example: sk_live_a1b2c3d4 }
label: { type: string }
status: { type: string, example: active }
propertyId: { type: integer, nullable: true }
scopes:
type: array
items: { type: string }
expiresAt: { type: string, format: date-time, nullable: true }
lastUsedAt: { type: string, format: date-time, nullable: true }
revokedAt: { type: string, format: date-time, nullable: true }
dateCreated: { type: string, format: date-time, nullable: true }
dateModified: { type: string, format: date-time, nullable: true }
ApiKeyCreate:
type: object
required: [scopes]
properties:
label: { type: string, example: Production server }
scopes:
type: array
minItems: 1
items: { type: string }
example: ['event:*', 'ledger:conversions:read']
description: |
Required. Event scopes: `event:*` for every event, or
`event:{slug}` for one event type. `*` is also accepted and grants
what `event:*` grants.
Ledger and webhook scopes: `ledger:conversions:read`,
`ledger:transactions:read`, `ledger:obligations:read`,
`ledger:payouts:read`, `webhook-subscriptions:read` and
`webhook-subscriptions:manage`. Each is granted only by its exact
name. `*`, `event:*` and wildcards such as `ledger:*` grant none
of them.
An older resource scope such as `programs:read` or
`conversions:read` is refused with 400.
expiresAt:
type: string
format: date-time
description: When the key stops working. Must be in the future.
propertyId:
type: integer
description: |
Binds the key to this Property of the organization. Siren stamps
it on the key's events, the key reads only that store's
conversions, transactions and obligations, and it is refused on
payouts and webhook subscriptions with 403 `store_key_not_allowed`.
Error:
type: object
description: |
`error` is polymorphic. Siren's REST layer returns an object with
`message`, `context`, and a stable `code` on refusals that have one
(such as `missing_scope`, `site_disconnected`, `plan_required` or
`not_permitted`). A few routes return a plain string message. Clients
must handle both.
An API key's refusals carry a stable `code`: `api_key_not_accepted`
(401) when the route takes a session and not a key, `missing_scope`
(403) when the key holds none of the route's scopes, with
`context.scope` and `context.anyOf`, and `store_key_not_allowed`
(403) when a key bound to one store asks for payouts or webhook
subscriptions, with `context.propertyId`. Branch on the code, not the
message.
properties:
error:
oneOf:
- type: string
- type: object
properties:
message: { type: string }
code: { type: string }
context:
description: |
Details of the refusal. A failed field check carries
`{type: VALIDATION_FAILED, failedValidations: {field: [message]}}`.
An empty context may be encoded as `[]`.
oneOf:
- type: object
additionalProperties: true
- type: array
maxItems: 0
responses:
PaginatedList:
description: |
One page of records with its paging details. The total is also in the
`x-siren-estimated-count` response header.
headers:
x-siren-estimated-count: { $ref: '#/components/headers/EstimatedCount' }
content:
application/json:
schema:
type: object
properties:
items:
type: array
items: { type: object, additionalProperties: true }
total: { type: integer }
page: { type: integer }
perPage: { type: integer }
totalPages: { type: integer }
Queued:
description: |
The organization's processing is paused. The event was queued and
will be processed once processing resumes. When the queue is full the
answer is a 429 instead.
headers:
X-Siren-OID: { $ref: '#/components/headers/XSirenOID' }
content:
application/json:
schema: { $ref: '#/components/schemas/QueuedEvent' }
BadRequest:
description: The request was malformed, or a field failed its check.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
Unauthorized:
description: |
Missing, invalid, expired or revoked credential, or the wrong kind. A
valid API key sent to a route that takes a session gets `error.code`
`api_key_not_accepted`.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
Forbidden:
description: |
The credential may not do this. For an API key, `error.code`
`missing_scope` means the key holds none of the route's scopes,
`error.context.scope` names one and `error.context.anyOf` lists every
scope that opens the route. `store_key_not_allowed` means a key bound
to one store asked for payouts or webhook subscriptions, which are
not kept by store.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
NotFound:
description: Resource not found.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
RateLimited:
description: Too many requests.
headers:
Retry-After:
schema: { type: integer }