-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtenantwebhook.go
More file actions
967 lines (895 loc) · 36.4 KB
/
tenantwebhook.go
File metadata and controls
967 lines (895 loc) · 36.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package ark
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"time"
"github.com/ArkHQ-io/ark-go/internal/apijson"
"github.com/ArkHQ-io/ark-go/internal/apiquery"
"github.com/ArkHQ-io/ark-go/internal/requestconfig"
"github.com/ArkHQ-io/ark-go/option"
"github.com/ArkHQ-io/ark-go/packages/param"
"github.com/ArkHQ-io/ark-go/packages/respjson"
"github.com/ArkHQ-io/ark-go/shared"
)
// TenantWebhookService contains methods and other services that help with
// interacting with the ark API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewTenantWebhookService] method instead.
type TenantWebhookService struct {
Options []option.RequestOption
}
// NewTenantWebhookService generates a new service that applies the given options
// to each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewTenantWebhookService(opts ...option.RequestOption) (r TenantWebhookService) {
r = TenantWebhookService{}
r.Options = opts
return
}
// Create a webhook endpoint to receive email event notifications for a tenant.
//
// **Available events:**
//
// - `MessageSent` - Email accepted by recipient server
// - `MessageDeliveryFailed` - Delivery permanently failed
// - `MessageDelayed` - Delivery temporarily failed, will retry
// - `MessageBounced` - Email bounced
// - `MessageHeld` - Email held for review
// - `MessageLinkClicked` - Recipient clicked a link
// - `MessageLoaded` - Recipient opened the email
// - `DomainDNSError` - Domain DNS issue detected
func (r *TenantWebhookService) New(ctx context.Context, tenantID string, body TenantWebhookNewParams, opts ...option.RequestOption) (res *TenantWebhookNewResponse, err error) {
opts = slices.Concat(r.Options, opts)
if tenantID == "" {
err = errors.New("missing required tenantId parameter")
return
}
path := fmt.Sprintf("tenants/%s/webhooks", tenantID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Get webhook details
func (r *TenantWebhookService) Get(ctx context.Context, webhookID string, query TenantWebhookGetParams, opts ...option.RequestOption) (res *TenantWebhookGetResponse, err error) {
opts = slices.Concat(r.Options, opts)
if query.TenantID == "" {
err = errors.New("missing required tenantId parameter")
return
}
if webhookID == "" {
err = errors.New("missing required webhookId parameter")
return
}
path := fmt.Sprintf("tenants/%s/webhooks/%s", query.TenantID, webhookID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Update a webhook
func (r *TenantWebhookService) Update(ctx context.Context, webhookID string, params TenantWebhookUpdateParams, opts ...option.RequestOption) (res *TenantWebhookUpdateResponse, err error) {
opts = slices.Concat(r.Options, opts)
if params.TenantID == "" {
err = errors.New("missing required tenantId parameter")
return
}
if webhookID == "" {
err = errors.New("missing required webhookId parameter")
return
}
path := fmt.Sprintf("tenants/%s/webhooks/%s", params.TenantID, webhookID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, &res, opts...)
return
}
// Get all configured webhook endpoints for a tenant.
func (r *TenantWebhookService) List(ctx context.Context, tenantID string, opts ...option.RequestOption) (res *TenantWebhookListResponse, err error) {
opts = slices.Concat(r.Options, opts)
if tenantID == "" {
err = errors.New("missing required tenantId parameter")
return
}
path := fmt.Sprintf("tenants/%s/webhooks", tenantID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Delete a webhook
func (r *TenantWebhookService) Delete(ctx context.Context, webhookID string, body TenantWebhookDeleteParams, opts ...option.RequestOption) (res *TenantWebhookDeleteResponse, err error) {
opts = slices.Concat(r.Options, opts)
if body.TenantID == "" {
err = errors.New("missing required tenantId parameter")
return
}
if webhookID == "" {
err = errors.New("missing required webhookId parameter")
return
}
path := fmt.Sprintf("tenants/%s/webhooks/%s", body.TenantID, webhookID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return
}
// Get a paginated list of delivery attempts for a specific webhook.
//
// Use this to:
//
// - Monitor webhook health and delivery success rate
// - Debug failed deliveries
// - Find specific events to replay
//
// **Filtering:**
//
// - Filter by success/failure to find problematic deliveries
// - Filter by event type to find specific events
// - Filter by time range for debugging recent issues
//
// **Retry behavior:** Failed deliveries are automatically retried with exponential
// backoff over ~3 days. Check `willRetry` to see if more attempts are scheduled.
func (r *TenantWebhookService) ListDeliveries(ctx context.Context, webhookID string, params TenantWebhookListDeliveriesParams, opts ...option.RequestOption) (res *TenantWebhookListDeliveriesResponse, err error) {
opts = slices.Concat(r.Options, opts)
if params.TenantID == "" {
err = errors.New("missing required tenantId parameter")
return
}
if webhookID == "" {
err = errors.New("missing required webhookId parameter")
return
}
path := fmt.Sprintf("tenants/%s/webhooks/%s/deliveries", params.TenantID, webhookID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, params, &res, opts...)
return
}
// Re-send a webhook delivery to your endpoint.
//
// **Use cases:**
//
// - Recover from transient failures after fixing your endpoint
// - Test endpoint changes with real historical data
// - Retry deliveries that failed due to downtime
//
// **How it works:**
//
// 1. Fetches the original payload from the delivery
// 2. Generates a new timestamp and signature
// 3. Sends to your webhook URL immediately
// 4. Returns the result (does not queue for retry if it fails)
//
// **Note:** The webhook must be enabled to replay deliveries.
func (r *TenantWebhookService) ReplayDelivery(ctx context.Context, deliveryID string, body TenantWebhookReplayDeliveryParams, opts ...option.RequestOption) (res *TenantWebhookReplayDeliveryResponse, err error) {
opts = slices.Concat(r.Options, opts)
if body.TenantID == "" {
err = errors.New("missing required tenantId parameter")
return
}
if body.WebhookID == "" {
err = errors.New("missing required webhookId parameter")
return
}
if deliveryID == "" {
err = errors.New("missing required deliveryId parameter")
return
}
path := fmt.Sprintf("tenants/%s/webhooks/%s/deliveries/%s/replay", body.TenantID, body.WebhookID, deliveryID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return
}
// Get detailed information about a specific webhook delivery attempt.
//
// Returns:
//
// - The complete request payload that was sent
// - Request headers including the signature
// - Response status code and body from your endpoint
// - Timing information
//
// Use this to debug why a delivery failed or verify what data was sent.
func (r *TenantWebhookService) GetDelivery(ctx context.Context, deliveryID string, query TenantWebhookGetDeliveryParams, opts ...option.RequestOption) (res *TenantWebhookGetDeliveryResponse, err error) {
opts = slices.Concat(r.Options, opts)
if query.TenantID == "" {
err = errors.New("missing required tenantId parameter")
return
}
if query.WebhookID == "" {
err = errors.New("missing required webhookId parameter")
return
}
if deliveryID == "" {
err = errors.New("missing required deliveryId parameter")
return
}
path := fmt.Sprintf("tenants/%s/webhooks/%s/deliveries/%s", query.TenantID, query.WebhookID, deliveryID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Send a test payload to your webhook endpoint and verify it receives the data
// correctly.
//
// Use this to:
//
// - Verify your webhook URL is accessible
// - Test your signature verification code
// - Ensure your server handles the payload format correctly
//
// **Test payload format:** The test payload is identical to real webhook payloads,
// containing sample data for the specified event type. Your webhook should respond
// with a 2xx status code.
func (r *TenantWebhookService) Test(ctx context.Context, webhookID string, params TenantWebhookTestParams, opts ...option.RequestOption) (res *TenantWebhookTestResponse, err error) {
opts = slices.Concat(r.Options, opts)
if params.TenantID == "" {
err = errors.New("missing required tenantId parameter")
return
}
if webhookID == "" {
err = errors.New("missing required webhookId parameter")
return
}
path := fmt.Sprintf("tenants/%s/webhooks/%s/test", params.TenantID, webhookID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
return
}
type TenantWebhookNewResponse struct {
Data TenantWebhookNewResponseData `json:"data,required"`
Meta shared.APIMeta `json:"meta,required"`
Success bool `json:"success,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
Meta respjson.Field
Success respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookNewResponse) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookNewResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type TenantWebhookNewResponseData struct {
// Webhook ID
ID string `json:"id,required"`
// Whether subscribed to all events
AllEvents bool `json:"allEvents,required"`
CreatedAt time.Time `json:"createdAt,required" format:"date-time"`
// Whether the webhook is active
Enabled bool `json:"enabled,required"`
// Subscribed events
//
// Any of "MessageSent", "MessageDelayed", "MessageDeliveryFailed", "MessageHeld",
// "MessageBounced", "MessageLinkClicked", "MessageLoaded", "DomainDNSError".
Events []string `json:"events,required"`
// Webhook name for identification
Name string `json:"name,required"`
// Webhook endpoint URL
URL string `json:"url,required" format:"uri"`
Uuid string `json:"uuid,required" format:"uuid"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
AllEvents respjson.Field
CreatedAt respjson.Field
Enabled respjson.Field
Events respjson.Field
Name respjson.Field
URL respjson.Field
Uuid respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookNewResponseData) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookNewResponseData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type TenantWebhookGetResponse struct {
Data TenantWebhookGetResponseData `json:"data,required"`
Meta shared.APIMeta `json:"meta,required"`
Success bool `json:"success,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
Meta respjson.Field
Success respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookGetResponse) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookGetResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type TenantWebhookGetResponseData struct {
// Webhook ID
ID string `json:"id,required"`
// Whether subscribed to all events
AllEvents bool `json:"allEvents,required"`
CreatedAt time.Time `json:"createdAt,required" format:"date-time"`
// Whether the webhook is active
Enabled bool `json:"enabled,required"`
// Subscribed events
//
// Any of "MessageSent", "MessageDelayed", "MessageDeliveryFailed", "MessageHeld",
// "MessageBounced", "MessageLinkClicked", "MessageLoaded", "DomainDNSError".
Events []string `json:"events,required"`
// Webhook name for identification
Name string `json:"name,required"`
// Webhook endpoint URL
URL string `json:"url,required" format:"uri"`
Uuid string `json:"uuid,required" format:"uuid"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
AllEvents respjson.Field
CreatedAt respjson.Field
Enabled respjson.Field
Events respjson.Field
Name respjson.Field
URL respjson.Field
Uuid respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookGetResponseData) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookGetResponseData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type TenantWebhookUpdateResponse struct {
Data TenantWebhookUpdateResponseData `json:"data,required"`
Meta shared.APIMeta `json:"meta,required"`
Success bool `json:"success,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
Meta respjson.Field
Success respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookUpdateResponse) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookUpdateResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type TenantWebhookUpdateResponseData struct {
// Webhook ID
ID string `json:"id,required"`
// Whether subscribed to all events
AllEvents bool `json:"allEvents,required"`
CreatedAt time.Time `json:"createdAt,required" format:"date-time"`
// Whether the webhook is active
Enabled bool `json:"enabled,required"`
// Subscribed events
//
// Any of "MessageSent", "MessageDelayed", "MessageDeliveryFailed", "MessageHeld",
// "MessageBounced", "MessageLinkClicked", "MessageLoaded", "DomainDNSError".
Events []string `json:"events,required"`
// Webhook name for identification
Name string `json:"name,required"`
// Webhook endpoint URL
URL string `json:"url,required" format:"uri"`
Uuid string `json:"uuid,required" format:"uuid"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
AllEvents respjson.Field
CreatedAt respjson.Field
Enabled respjson.Field
Events respjson.Field
Name respjson.Field
URL respjson.Field
Uuid respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookUpdateResponseData) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookUpdateResponseData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type TenantWebhookListResponse struct {
Data TenantWebhookListResponseData `json:"data,required"`
Meta shared.APIMeta `json:"meta,required"`
Success bool `json:"success,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
Meta respjson.Field
Success respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookListResponse) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookListResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type TenantWebhookListResponseData struct {
Webhooks []TenantWebhookListResponseDataWebhook `json:"webhooks,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Webhooks respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookListResponseData) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookListResponseData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type TenantWebhookListResponseDataWebhook struct {
// Webhook ID
ID string `json:"id,required"`
Enabled bool `json:"enabled,required"`
Events []string `json:"events,required"`
Name string `json:"name,required"`
URL string `json:"url,required" format:"uri"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Enabled respjson.Field
Events respjson.Field
Name respjson.Field
URL respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookListResponseDataWebhook) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookListResponseDataWebhook) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type TenantWebhookDeleteResponse struct {
Data TenantWebhookDeleteResponseData `json:"data,required"`
Meta shared.APIMeta `json:"meta,required"`
Success bool `json:"success,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
Meta respjson.Field
Success respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookDeleteResponse) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookDeleteResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type TenantWebhookDeleteResponseData struct {
Message string `json:"message,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Message respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookDeleteResponseData) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookDeleteResponseData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Paginated list of webhook delivery attempts
type TenantWebhookListDeliveriesResponse struct {
Data []TenantWebhookListDeliveriesResponseData `json:"data,required"`
Meta shared.APIMeta `json:"meta,required"`
// Current page number
Page int64 `json:"page,required"`
// Items per page
PerPage int64 `json:"perPage,required"`
// Total number of deliveries matching the filter
Total int64 `json:"total,required"`
// Total number of pages
TotalPages int64 `json:"totalPages,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
Meta respjson.Field
Page respjson.Field
PerPage respjson.Field
Total respjson.Field
TotalPages respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookListDeliveriesResponse) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookListDeliveriesResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Summary of a webhook delivery attempt
type TenantWebhookListDeliveriesResponseData struct {
// Unique delivery ID (UUID)
ID string `json:"id,required"`
// Attempt number (1 for first attempt, increments with retries)
Attempt int64 `json:"attempt,required"`
// Event type that triggered this delivery
//
// Any of "MessageSent", "MessageDelayed", "MessageDeliveryFailed", "MessageHeld",
// "MessageBounced", "MessageLinkClicked", "MessageLoaded", "DomainDNSError".
Event string `json:"event,required"`
// HTTP status code returned by the endpoint (null if connection failed)
StatusCode int64 `json:"statusCode,required"`
// Whether the delivery was successful (2xx response)
Success bool `json:"success,required"`
// When this delivery attempt occurred
Timestamp time.Time `json:"timestamp,required" format:"date-time"`
// URL the webhook was delivered to
URL string `json:"url,required" format:"uri"`
// ID of the webhook this delivery belongs to
WebhookID string `json:"webhookId,required"`
// Whether this delivery will be retried (true if failed and retries remaining)
WillRetry bool `json:"willRetry,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Attempt respjson.Field
Event respjson.Field
StatusCode respjson.Field
Success respjson.Field
Timestamp respjson.Field
URL respjson.Field
WebhookID respjson.Field
WillRetry respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookListDeliveriesResponseData) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookListDeliveriesResponseData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Result of replaying a webhook delivery
type TenantWebhookReplayDeliveryResponse struct {
Data TenantWebhookReplayDeliveryResponseData `json:"data,required"`
Meta shared.APIMeta `json:"meta,required"`
Success bool `json:"success,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
Meta respjson.Field
Success respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookReplayDeliveryResponse) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookReplayDeliveryResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type TenantWebhookReplayDeliveryResponseData struct {
// Request duration in milliseconds
Duration int64 `json:"duration,required"`
// ID of the new delivery created by the replay
NewDeliveryID string `json:"newDeliveryId,required"`
// ID of the original delivery that was replayed
OriginalDeliveryID string `json:"originalDeliveryId,required"`
// HTTP status code from your endpoint
StatusCode int64 `json:"statusCode,required"`
// Whether the replay was successful (2xx response from endpoint)
Success bool `json:"success,required"`
// When the replay was executed
Timestamp time.Time `json:"timestamp,required" format:"date-time"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Duration respjson.Field
NewDeliveryID respjson.Field
OriginalDeliveryID respjson.Field
StatusCode respjson.Field
Success respjson.Field
Timestamp respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookReplayDeliveryResponseData) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookReplayDeliveryResponseData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Detailed information about a webhook delivery attempt
type TenantWebhookGetDeliveryResponse struct {
// Full details of a webhook delivery including request and response
Data TenantWebhookGetDeliveryResponseData `json:"data,required"`
Meta shared.APIMeta `json:"meta,required"`
Success bool `json:"success,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
Meta respjson.Field
Success respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookGetDeliveryResponse) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookGetDeliveryResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Full details of a webhook delivery including request and response
type TenantWebhookGetDeliveryResponseData struct {
// Unique delivery ID (UUID)
ID string `json:"id,required"`
// Attempt number for this delivery
Attempt int64 `json:"attempt,required"`
// Event type that triggered this delivery
//
// Any of "MessageSent", "MessageDelayed", "MessageDeliveryFailed", "MessageHeld",
// "MessageBounced", "MessageLinkClicked", "MessageLoaded", "DomainDNSError".
Event string `json:"event,required"`
// The request that was sent to your endpoint
Request TenantWebhookGetDeliveryResponseDataRequest `json:"request,required"`
// The response received from your endpoint
Response TenantWebhookGetDeliveryResponseDataResponse `json:"response,required"`
// HTTP status code returned by the endpoint
StatusCode int64 `json:"statusCode,required"`
// Whether the delivery was successful (2xx response)
Success bool `json:"success,required"`
// When this delivery attempt occurred
Timestamp time.Time `json:"timestamp,required" format:"date-time"`
// URL the webhook was delivered to
URL string `json:"url,required" format:"uri"`
// ID of the webhook this delivery belongs to
WebhookID string `json:"webhookId,required"`
// Name of the webhook for easy identification
WebhookName string `json:"webhookName,required"`
// Whether this delivery will be retried
WillRetry bool `json:"willRetry,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Attempt respjson.Field
Event respjson.Field
Request respjson.Field
Response respjson.Field
StatusCode respjson.Field
Success respjson.Field
Timestamp respjson.Field
URL respjson.Field
WebhookID respjson.Field
WebhookName respjson.Field
WillRetry respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookGetDeliveryResponseData) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookGetDeliveryResponseData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The request that was sent to your endpoint
type TenantWebhookGetDeliveryResponseDataRequest struct {
// HTTP headers that were sent with the request
Headers map[string]string `json:"headers,required"`
// The complete webhook payload that was sent
Payload map[string]any `json:"payload,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Headers respjson.Field
Payload respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookGetDeliveryResponseDataRequest) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookGetDeliveryResponseDataRequest) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The response received from your endpoint
type TenantWebhookGetDeliveryResponseDataResponse struct {
// HTTP status code from your endpoint
StatusCode int64 `json:"statusCode,required"`
// Response body from your endpoint (may be truncated)
Body string `json:"body,nullable"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
StatusCode respjson.Field
Body respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookGetDeliveryResponseDataResponse) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookGetDeliveryResponseDataResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type TenantWebhookTestResponse struct {
Data TenantWebhookTestResponseData `json:"data,required"`
Meta shared.APIMeta `json:"meta,required"`
Success bool `json:"success,required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
Meta respjson.Field
Success respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookTestResponse) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookTestResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type TenantWebhookTestResponseData struct {
// Request duration in milliseconds
Duration int64 `json:"duration,required"`
// Event type that was tested
Event string `json:"event,required"`
// HTTP status code from the webhook endpoint
StatusCode int64 `json:"statusCode,required"`
// Whether the webhook endpoint responded with a 2xx status
Success bool `json:"success,required"`
// Response body from the webhook endpoint (truncated if too long)
Body string `json:"body,nullable"`
// Error message if the request failed
Error string `json:"error,nullable"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Duration respjson.Field
Event respjson.Field
StatusCode respjson.Field
Success respjson.Field
Body respjson.Field
Error respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r TenantWebhookTestResponseData) RawJSON() string { return r.JSON.raw }
func (r *TenantWebhookTestResponseData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type TenantWebhookNewParams struct {
// Webhook name for identification
Name string `json:"name,required"`
// HTTPS endpoint URL
URL string `json:"url,required" format:"uri"`
// Subscribe to all events (ignores events array, accepts null)
AllEvents param.Opt[bool] `json:"allEvents,omitzero"`
// Whether the webhook is enabled (accepts null)
Enabled param.Opt[bool] `json:"enabled,omitzero"`
// Events to subscribe to (accepts null):
//
// - `MessageSent` - Email successfully delivered to recipient's server
// - `MessageDelayed` - Temporary delivery failure, will retry
// - `MessageDeliveryFailed` - Permanent delivery failure
// - `MessageHeld` - Email held for manual review
// - `MessageBounced` - Email bounced back
// - `MessageLinkClicked` - Recipient clicked a tracked link
// - `MessageLoaded` - Recipient opened the email (tracking pixel loaded)
// - `DomainDNSError` - DNS configuration issue detected
//
// Any of "MessageSent", "MessageDelayed", "MessageDeliveryFailed", "MessageHeld",
// "MessageBounced", "MessageLinkClicked", "MessageLoaded", "DomainDNSError".
Events []string `json:"events,omitzero"`
paramObj
}
func (r TenantWebhookNewParams) MarshalJSON() (data []byte, err error) {
type shadow TenantWebhookNewParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *TenantWebhookNewParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type TenantWebhookGetParams struct {
TenantID string `path:"tenantId,required" json:"-"`
paramObj
}
type TenantWebhookUpdateParams struct {
TenantID string `path:"tenantId,required" json:"-"`
AllEvents param.Opt[bool] `json:"allEvents,omitzero"`
Enabled param.Opt[bool] `json:"enabled,omitzero"`
Name param.Opt[string] `json:"name,omitzero"`
URL param.Opt[string] `json:"url,omitzero" format:"uri"`
Events []string `json:"events,omitzero"`
paramObj
}
func (r TenantWebhookUpdateParams) MarshalJSON() (data []byte, err error) {
type shadow TenantWebhookUpdateParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *TenantWebhookUpdateParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type TenantWebhookDeleteParams struct {
TenantID string `path:"tenantId,required" json:"-"`
paramObj
}
type TenantWebhookListDeliveriesParams struct {
TenantID string `path:"tenantId,required" json:"-"`
// Only deliveries after this Unix timestamp
After param.Opt[int64] `query:"after,omitzero" json:"-"`
// Only deliveries before this Unix timestamp
Before param.Opt[int64] `query:"before,omitzero" json:"-"`
// Page number (default 1)
Page param.Opt[int64] `query:"page,omitzero" json:"-"`
// Items per page (default 30, max 100)
PerPage param.Opt[int64] `query:"perPage,omitzero" json:"-"`
// Filter by delivery success (true = 2xx response, false = non-2xx or error)
Success param.Opt[bool] `query:"success,omitzero" json:"-"`
// Filter by event type
//
// Any of "MessageSent", "MessageDelayed", "MessageDeliveryFailed", "MessageHeld",
// "MessageBounced", "MessageLinkClicked", "MessageLoaded", "DomainDNSError".
Event TenantWebhookListDeliveriesParamsEvent `query:"event,omitzero" json:"-"`
paramObj
}
// URLQuery serializes [TenantWebhookListDeliveriesParams]'s query parameters as
// `url.Values`.
func (r TenantWebhookListDeliveriesParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Filter by event type
type TenantWebhookListDeliveriesParamsEvent string
const (
TenantWebhookListDeliveriesParamsEventMessageSent TenantWebhookListDeliveriesParamsEvent = "MessageSent"
TenantWebhookListDeliveriesParamsEventMessageDelayed TenantWebhookListDeliveriesParamsEvent = "MessageDelayed"
TenantWebhookListDeliveriesParamsEventMessageDeliveryFailed TenantWebhookListDeliveriesParamsEvent = "MessageDeliveryFailed"
TenantWebhookListDeliveriesParamsEventMessageHeld TenantWebhookListDeliveriesParamsEvent = "MessageHeld"
TenantWebhookListDeliveriesParamsEventMessageBounced TenantWebhookListDeliveriesParamsEvent = "MessageBounced"
TenantWebhookListDeliveriesParamsEventMessageLinkClicked TenantWebhookListDeliveriesParamsEvent = "MessageLinkClicked"
TenantWebhookListDeliveriesParamsEventMessageLoaded TenantWebhookListDeliveriesParamsEvent = "MessageLoaded"
TenantWebhookListDeliveriesParamsEventDomainDNSError TenantWebhookListDeliveriesParamsEvent = "DomainDNSError"
)
type TenantWebhookReplayDeliveryParams struct {
TenantID string `path:"tenantId,required" json:"-"`
WebhookID string `path:"webhookId,required" json:"-"`
paramObj
}
type TenantWebhookGetDeliveryParams struct {
TenantID string `path:"tenantId,required" json:"-"`
WebhookID string `path:"webhookId,required" json:"-"`
paramObj
}
type TenantWebhookTestParams struct {
TenantID string `path:"tenantId,required" json:"-"`
// Event type to simulate
//
// Any of "MessageSent", "MessageDelayed", "MessageDeliveryFailed", "MessageHeld",
// "MessageBounced", "MessageLinkClicked", "MessageLoaded", "DomainDNSError".
Event TenantWebhookTestParamsEvent `json:"event,omitzero,required"`
paramObj
}
func (r TenantWebhookTestParams) MarshalJSON() (data []byte, err error) {
type shadow TenantWebhookTestParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *TenantWebhookTestParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Event type to simulate
type TenantWebhookTestParamsEvent string
const (
TenantWebhookTestParamsEventMessageSent TenantWebhookTestParamsEvent = "MessageSent"
TenantWebhookTestParamsEventMessageDelayed TenantWebhookTestParamsEvent = "MessageDelayed"
TenantWebhookTestParamsEventMessageDeliveryFailed TenantWebhookTestParamsEvent = "MessageDeliveryFailed"
TenantWebhookTestParamsEventMessageHeld TenantWebhookTestParamsEvent = "MessageHeld"
TenantWebhookTestParamsEventMessageBounced TenantWebhookTestParamsEvent = "MessageBounced"
TenantWebhookTestParamsEventMessageLinkClicked TenantWebhookTestParamsEvent = "MessageLinkClicked"
TenantWebhookTestParamsEventMessageLoaded TenantWebhookTestParamsEvent = "MessageLoaded"
TenantWebhookTestParamsEventDomainDNSError TenantWebhookTestParamsEvent = "DomainDNSError"
)