/
iterable.rb
3376 lines (3318 loc) · 123 KB
/
iterable.rb
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
{
title: 'Iterable',
connection: {
fields: [
{
name: 'api_key',
label: 'API key',
control_type: 'password',
optional: false,
hint: 'Get your <b>standard</b> API key <a href="https://app.' \
'iterable.com/settings/apiKeys" target="_blank">here</a>.'
}
],
authorization: {
type: 'api_key',
credentials: ->(connection) { headers(api_key: connection['api_key']) }
},
base_uri: lambda do
'https://api.iterable.com'
end
},
test: lambda do
get('/api/channels')
end,
methods: {
format_api_input_field_names: lambda do |input|
if input.is_a?(Array)
input.map do |array_value|
call('format_api_input_field_names', array_value)
end
elsif input.is_a?(Hash)
input.map do |key, value|
value = call('format_api_input_field_names', value)
{ key.gsub('_', '.') => value }
end.inject(:merge)
else
input
end
end,
format_api_output_field_names: lambda do |input|
if input.is_a?(Array)
input.map do |array_value|
call('format_api_output_field_names', array_value)
end
elsif input.is_a?(Hash)
input.map do |key, value|
value = call('format_api_output_field_names', value)
{ key.gsub('.', '_') => value }
end.inject(:merge)
else
input
end
end,
make_schema_builder_fields_sticky: lambda do |input|
input.map do |field|
if field[:properties].present?
field[:properties] = call('make_schema_builder_fields_sticky',
field[:properties])
elsif field['properties'].present?
field['properties'] = call('make_schema_builder_fields_sticky',
field['properties'])
end
field[:sticky] = true
field
end
end,
custom_input_schema: lambda do |input|
input_schema =
case input['object_name']
when 'users'
parse_json(input&.
dig('users', 'dataFields', 'input', 'schema') || '[]')
when 'subscribers'
parse_json(input&.
dig('subscribers', 'dataFields', 'input', 'schema') || '[]')
when 'catalog_item'
parse_json(input&.
dig('value', 'input', 'schema') || input&.
dig('update', 'input', 'schema') || '[]')
else
parse_json(input&.
dig('dataFields', 'input', 'schema') || '[]')
end
[
{
name: 'input',
type: 'object',
properties: [
{
name: 'schema',
extends_schema: true,
schema_neutral: true,
control_type: 'schema-designer',
sample_data_type: 'json_input',
sticky: input_schema.blank?,
label: 'Request body parameters',
add_field_label: 'Add request body parameter'
},
(
if input_schema.present?
{
name: 'data',
type: 'object',
properties: call('make_schema_builder_fields_sticky',
input_schema)
}
end
)
].compact
}
]
end,
custom_output_schema: lambda do |_input|
[
{
name: 'output',
label: 'Custom fields',
control_type: 'schema-designer',
sample_data_type: 'json_http',
hint: 'Use this to define your custom fields from the output. E.g. <b>dataFields</b>',
extends_schema: true,
schema_neutral: true,
sticky: true
}
]
end,
response_schema: lambda do |input|
if input['response_schema'].present?
parse_json(input['response_schema'])
else
parse_json(input['output'] || '[]')
end
end,
format_unix_to_utc_time: lambda do |input|
date_fields = %w[createdAt updatedAt startAt endedAt lastModified]
if input.is_a?(Array)
input.map do |array_value|
call('format_unix_to_utc_time', array_value)
end
elsif input.is_a?(Hash)
input.map do |key, value|
value = call('format_unix_to_utc_time', value)
if date_fields.include?(key)
{ key => (value.to_i / 1000).to_i.to_time.utc }
else
{ key => value }
end
end.inject(:merge)
else
input
end
end,
format_date_time_field: lambda do |input|
input&.to_time&.utc&.strftime('%Y-%m-%d %H:%M:%S') || ''
end,
### SCHEMAS ###
list: lambda do |_input|
[
{ name: 'id' },
{ name: 'name' },
{ name: 'createdAt', type: 'datetime' },
{ name: 'listType' }
]
end,
event: lambda do |_input|
[
{ name: 'email', sticky: true,
hint: 'Either email or userId must be passed in to identify the user. If both are ' \
'passed in, email takes precedence.' },
{ name: 'eventName', sticky: true, optional: false },
{ name: 'id', sticky: true,
hint: 'Optional event ID. If an event exists with that ID, the event will be updated. ' \
'If none is specified, a new ID will automatically be generated and returned.' },
{
sticky: true,
control_type: 'date_time',
hint: 'Time event happened. Set to the time event was received if unspecified.',
type: 'date_time',
name: 'createdAt'
},
{ name: 'userId', sticky: true },
{
sticky: true,
control_type: 'number',
label: 'Campaign ID',
parse_output: 'float_conversion',
type: 'number',
name: 'campaignId'
},
{
sticky: true,
control_type: 'number',
label: 'Template ID',
parse_output: 'float_conversion',
type: 'number',
name: 'templateId'
}
]
end,
user: lambda do |_input|
[
{ name: 'email' },
{ name: 'userId' },
{ name: 'mergeNestedObjects', type: 'boolean' },
{ name: 'correlationId' }
]
end,
catalog_item: lambda do |_input|
[
{ name: 'catalogName' },
{ name: 'itemId' },
{ control_type: 'number', parse_output: 'float_conversion', type: 'number', name: 'size' },
{ control_type: 'date_time', render_input: 'date_time_conversion', parse_output: 'date_time_conversion',
type: 'date_time', name: 'lastModified' }
]
end,
channel: lambda do |_input|
[
{ control_type: 'number', parse_output: 'float_conversion',
type: 'number', name: 'id' },
{ name: 'name' },
{ name: 'channelType' },
{ name: 'messageMedium' }
]
end,
message_type: lambda do |_input|
[
{ name: 'id', type: 'integer' },
{ name: 'name' },
{ name: 'channelId', type: 'integer' }
]
end,
### CREATE METHODS ###
format_create_payload: lambda do |input|
case input['object_name']
when 'list'
input
when 'campaign'
lists = %w[listIds suppressionListIds]
input.map do |key, value|
if lists.include?(key)
{ key => value.split(',').map do |ids|
[ids.to_i]
end.flatten }
elsif key.include?('sendAt')
{ key => call('format_date_time_field', value) }
elsif key.include?('dataFields')
{ key => value&.dig('input', 'data') }
else
{ key => value }
end
end.inject(:merge)
when 'event'
formatted_input = input.map do |key, value|
if %w[dataFields].include?(key)
{ key => value&.dig('input', 'data') }
elsif key == 'createdAt'
{ key => value.to_time.to_i }
else
{ key => value }
end
end.inject(:merge)
payload = call('format_api_input_field_names',
formatted_input).compact
payload
else
{}
end
end,
create_endpoint: lambda do |input|
case input['object_name']
when 'list'
'/api/lists'
when 'campaign'
'/api/campaigns/create'
when 'event'
'/api/events/track'
when 'catalog'
"/api/catalogs/#{input['catalogName']}"
end
end,
sample_create_record: lambda do |input|
case input['object_name']
when 'list'
{ "listId": '432438' }
when 'campaign'
{ "campaignId": '432438' }
when 'event'
{
"msg": 'Event with id: 1a3c9d2705754a74kadf53d9276f7e12 tracked.',
"code": 'Success',
"params": { "id": '1a3c9d2705754a749adf53k9276f7e12' }
}
when 'catalog'
{
"msg": 'Catalog with id: 1a3c9d2705754a74kadf53d9276f7e12 created.',
"code": 'Success',
"params": { "id": '2688', "name": 'TEST-catalog', "url": '/api/catalogs/TEST-catalog' }
}
end
end,
create_object_output: lambda do |input|
case input['object_name']
when 'list'
[{ name: 'listId', type: 'integer' }]
when 'campaign'
[{ name: 'campaignId', type: 'integer' }]
when 'event'
[{ name: 'msg', label: 'Message' },
{ name: 'code' },
{ name: 'params', type: 'object', properties: [
{ name: 'id' }
] }]
when 'catalog'
[{ name: 'msg', label: 'Message' },
{ name: 'code' },
{ name: 'params', type: 'object', properties: [
{ name: 'id' },
{ name: 'name' },
{ name: 'url' }
] }]
end
end,
create_list_schema: lambda do |_input|
[{ name: 'name', label: 'List name', optional: false }]
end,
create_campaign_schema: lambda do |input|
[
{ name: 'name', optional: false, label: 'Campaign name' },
{ name: 'listIds',
control_type: 'multiselect',
pick_list: 'project_lists',
delimiter: ',',
type: 'string',
optional: false,
label: 'List IDs',
toggle_hint: 'Select from list',
toggle_field: {
name: 'listIds',
label: 'List IDs',
type: :string,
control_type: 'text',
optional: false,
toggle_hint: 'Use List IDs',
hint: 'Please enter list IDs with commas as delimiter and without spaces.'
} },
{ control_type: 'number',
label: 'Template ID',
type: 'number',
render_input: 'integer_conversion',
parse_output: 'integer_conversion',
optional: false,
name: 'templateId' },
{ name: 'suppressionListIds',
control_type: 'multiselect',
pick_list: 'project_lists',
delimiter: ',',
type: 'string',
hint: 'Optional IDs of lists of users that this campaign should not send emails to.',
optional: true,
label: 'Suppression list IDs',
toggle_hint: 'Select from list',
toggle_field: {
name: 'suppressionListIds',
label: 'Suppression list IDs',
type: :string,
control_type: 'text',
optional: true,
toggle_hint: 'Use List IDs',
hint: 'Please enter list IDs with commas as delimiter and without spaces.'
} },
{ name: 'sendAt',
hint: 'When to send the message, it can be up to 7 days in the future. ' \
'If in the past, email is sent immediately.',
control_type: 'date_time' },
{ name: 'sendMode',
control_type: 'select',
pick_list: 'send_mode',
hint: 'Send campaign based on project time zone or recipient time zone.',
toggle_hint: 'Select from list',
toggle_field: {
name: 'sendMode',
label: 'Send mode',
type: :string,
control_type: 'text',
optional: true,
toggle_hint: 'Use custom value',
hint: 'Valid values are: <b>ProjectTimeZone</b> or <b>RecipientTimeZone</b>'
} },
{ name: 'startTimeZone',
control_type: 'select',
pick_list: 'timezones',
hint: 'The starting time zone in for recipient time zone-based sends.',
toggle_hint: 'Select from list',
toggle_field: {
name: 'startTimeZone',
label: 'Start time zone',
type: :string,
control_type: 'text',
optional: true,
toggle_hint: 'Use custom value',
hint: 'Enter timezone in IANA format. Click <a href="https://en.wikipedia.org/wiki' \
'/List_of_tz_database_time_zones" target="_blank" >here</a> to learn more.'
} },
{ name: 'defaultTimeZone',
control_type: 'select',
pick_list: 'timezones',
hint: 'The fallback time zone for recipient time zone-based sends if the recipient does not ' \
'have time zone set.',
toggle_hint: 'Select from list',
toggle_field: {
name: 'defaultTimeZone',
label: 'Default time zone',
type: :string,
control_type: 'text',
optional: true,
toggle_hint: 'Use custom value',
hint: 'Enter timezone in IANA format. Click <a href="https://en.wikipedia.org/wiki' \
'/List_of_tz_database_time_zones" target="_blank" >here</a> to learn more.'
} },
{ name: 'dataFields', type: 'object', extends_schema: true,
properties: call('custom_input_schema', input) }
]
end,
create_event_schema: lambda do |input|
call('event', '').
concat([{ name: 'dataFields', type: 'object', extends_schema: true,
hint: 'Additional data associated with event (i.e. item amount, item quantity). ' \
'For events of the same name, ' \
'identically named data fields must be of the same type',
properties: call('custom_input_schema', input) }])
end,
create_catalog_schema: lambda do |_input|
[{ name: 'catalogName', optional: false, hint: 'Catalog names have a maximum length of 255 characters ' \
'and must contain only alphanumeric characters and dashes.' }]
end,
### UPDATE METHODS ###
format_update_payload: lambda do |input|
case input['object_name']
when 'catalog_item'
payload = input.map do |key, val|
if ['value'].include?(key)
{ key => val&.dig('input', 'data') }
else
{}
end
end.inject(:merge)
payload
when 'user_subscription'
payload = input.map do |key, val|
if %w[emailListIds unsubscribedChannelIds unsubscribedMessageTypeIds subscribedMessageTypeIds].
include?(key)
value = val.split(',')&.map { |id| id.to_i }
{ key => value }
else
{ key => val }
end
end.inject(:merge)
payload
else
{}
end
end,
update_endpoint: lambda do |input|
case input['object_name']
when 'catalog_item'
catalog_name = input.delete('catalogName')
item_id = input.delete('itemId')
"/api/catalogs/#{catalog_name}/items/#{item_id}"
when 'user_subscription'
'/api/users/updateSubscriptions'
end
end,
sample_update_record: lambda do |input|
case input['object_name']
when 'catalog_item'
{
"msg": 'Response description',
"code": 'Success',
"params": {
"catalogName": 'TEST-catalog',
"itemId": 'TEST-catalog-item',
"url": '/api/catalogs/TEST-catalog/items/TEST-catalog-item'
}
}
when 'user_subscription'
{
"msg": 'Response description',
"code": 'Success',
"params": {}
}
end
end,
update_object_output: lambda do |input|
case input['object_name']
when 'catalog_item'
[{ name: 'msg', label: 'Message' },
{ name: 'code' },
{ name: 'params', type: 'object', properties: [
{ name: 'catalogName' },
{ name: 'itemId' },
{ name: 'url' }
] }]
when 'user_subscription'
[{ name: 'msg', label: 'Message' },
{ name: 'code' },
{ name: 'params', type: 'object' }]
end
end,
update_catalog_item_schema: lambda do |input|
[
{ name: 'value', type: 'object', extends_schema: true, optional: false,
hint: 'JSON representation of the catalog item.',
properties: call('custom_input_schema', input) },
{ name: 'catalogName', optional: false },
{ name: 'itemId', optional: false,
hint: "A catalog item's ID must be unique, contain only alphanumeric characters " \
'and dashes, and have a maximum length of 255 characters.' }
]
end,
update_user_subscription_schema: lambda do |_input|
[
{ name: 'email', sticky: true },
{ name: 'userId', sticky: true },
{ name: 'emailListIds',
control_type: 'multiselect',
pick_list: 'project_lists',
delimiter: ',',
type: 'string',
sticky: true,
hint: 'Lists that a user is subscribed to.',
label: 'Email list IDs',
toggle_hint: 'Select from list',
toggle_field: {
name: 'emailListIds',
label: 'Email list IDs',
type: :string,
control_type: 'text',
optional: true,
toggle_hint: 'Use List IDs',
hint: 'Please enter list IDs separated by commas and without spaces.'
} },
{ name: 'unsubscribedChannelIds',
control_type: 'multiselect',
pick_list: 'channels',
delimiter: ',',
type: 'string',
sticky: true,
hint: 'Email channel IDs to unsubscribe from.',
label: 'Unsubscribed channel IDs',
toggle_hint: 'Select from list',
toggle_field: {
name: 'unsubscribedChannelIds',
label: 'Unsubscribed channel IDs',
type: :string,
control_type: 'text',
optional: true,
toggle_hint: 'Use List IDs',
hint: 'Please enter Channel IDs separated by commas and without spaces.'
} },
{ name: 'unsubscribedMessageTypeIds',
control_type: 'multiselect',
pick_list: 'message_types',
delimiter: ',',
type: 'string',
sticky: true,
hint: 'Individual message type IDs to unsubscribe (does not impact channel subscriptions).',
label: 'Unsubscribed message type IDs',
toggle_hint: 'Select from list',
toggle_field: {
name: 'unsubscribedMessageTypeIds',
label: 'Unsubscribed message type IDs',
type: :string,
control_type: 'text',
optional: true,
toggle_hint: 'Use Message type IDs',
hint: 'Please enter Message type IDs separated by commas and without spaces.'
} },
{ name: 'subscribedMessageTypeIds',
control_type: 'multiselect',
pick_list: 'message_types',
delimiter: ',',
type: 'string',
sticky: true,
hint: 'Individual message type IDs to subscribe (does not impact channel subscriptions). ' \
'To set a value for this field, first have your CSM enable the opt-in message types feature. ' \
'Otherwise, attempting to set this field causes an error.',
label: 'Subscribed message type IDs',
toggle_hint: 'Select from list',
toggle_field: {
name: 'subscribedMessageTypeIds',
label: 'Subscribed message type IDs',
type: :string,
control_type: 'text',
optional: true,
toggle_hint: 'Use Message type IDs',
hint: 'Please enter Message type IDs separated by commas and without spaces.'
} },
{ name: 'campaignId', sticky: true, control_type: 'select',
label: 'Campaign',
pick_list: 'campaigns',
render_input: 'integer_conversion',
parse_output: 'integer_conversion',
hint: 'Campaign to attribute unsubscribes.',
toggle_hint: 'Select campaign',
toggle_field: {
name: 'campaignId', label: 'Campaign ID',
control_type: 'number',
type: 'integer',
optional: true,
render_input: 'integer_conversion',
parse_output: 'integer_conversion',
toggle_hint: 'Use custom value',
hint: 'Please enter Campaign ID.'
} },
{ name: 'templateId',
control_type: 'number',
type: 'integer',
sticky: true,
hint: 'Template to attribute unsubscribes.',
render_input: 'integer_conversion',
parse_output: 'integer_conversion' }
]
end,
### UPSERT METHODS ###
format_upsert_payload: lambda do |input|
case input['object_name']
when 'user'
payload = input.map do |key, val|
if ['dataFields'].include?(key)
{ key => val&.dig('input', 'data') }
else
{ key => val }
end
end.inject(:merge)
payload
when 'catalog_item'
payload = input.map do |key, val|
if ['update'].include?(key)
{ key => val&.dig('input', 'data') }
else
{}
end
end.inject(:merge)
payload
else
{}
end
end,
upsert_endpoint: lambda do |input|
case input['object_name']
when 'user'
'/api/users/update'
when 'catalog_item'
catalog_name = input.delete('catalogName')
item_id = input.delete('itemId')
"/api/catalogs/#{catalog_name}/items/#{item_id}"
end
end,
sample_upsert_record: lambda do |input|
case input['object_name']
when 'user'
{
"msg": 'Message',
"code": 'Success',
"params": {}
}
when 'catalog_item'
{
"msg": 'Response description',
"code": 'Success',
"params": {
"catalogName": 'TEST-catalog',
"itemId": 'TEST-catalog-item',
"url": '/api/catalogs/TEST-catalog/items/TEST-catalog-item'
}
}
end
end,
upsert_object_output: lambda do |input|
case input['object_name']
when 'user'
[{ name: 'msg', label: 'Message' },
{ name: 'code' },
{ name: 'params', type: 'object' }]
when 'catalog_item'
[{ name: 'msg', label: 'Message' },
{ name: 'code' },
{ name: 'params', type: 'object', properties: [
{ name: 'catalogName' },
{ name: 'itemId' },
{ name: 'url' }
] }]
end
end,
upsert_user_schema: lambda do |input|
[
{ name: 'email', control_type: 'email',
label: 'Email address', sticky: true,
hint: 'An email must be set unless a profile already exists' \
' with a userId set. In which case, a lookup from userId ' \
'to email is performed.' },
{ name: 'userId', sticky: true,
hint: 'Optional user ID, typically your ' \
'database generated ID. Either email or user ID must be ' \
'specified.' },
{ name: 'preferUserId', type: 'boolean',
sticky: true,
control_type: 'checkbox',
hint: 'Create a new user with the specified user ID if ' \
'the user does not exist yet.',
toggle_hint: 'Select from list',
toggle_field:
{ name: 'preferUserId',
label: 'Prefer user ID',
type: :boolean,
control_type: 'text',
optional: true,
render_input: 'boolean_conversion',
toggle_hint: 'Use custom value',
hint: 'Allowed values are true or false' } },
{ name: 'mergeNestedObjects', type: 'boolean',
sticky: true,
control_type: 'checkbox',
hint: 'Merge top level objects instead of overwriting.',
toggle_hint: 'Select from list',
toggle_field:
{ name: 'mergeNestedObjects',
label: 'Merge nested objects',
type: :boolean,
control_type: 'text',
optional: true,
render_input: 'boolean_conversion',
toggle_hint: 'Use custom value',
hint: 'Allowed values are true or false' } },
{ name: 'dataFields', type: 'object', extends_schema: true,
properties: call('custom_input_schema', input) }
]
end,
upsert_catalog_item_schema: lambda do |input|
[
{ name: 'update', type: 'object', extends_schema: true, optional: false,
hint: 'JSON representation of the catalog item.',
properties: call('custom_input_schema', input) },
{ name: 'catalogName', optional: false },
{ name: 'itemId', optional: false,
hint: "A catalog item's ID must be unique, contain only alphanumeric characters " \
'and dashes, and have a maximum length of 255 characters.' }
]
end,
### SEARCH METHODS ###
format_search_params: lambda do |input|
case input['object_name']
when 'events'
{ limit: input['limit'] }
when 'catalogs'
{
page: input['page'],
pageSize: input['pageSize']
}
when 'catalog_items'
{
page: input['page'],
pageSize: input['pageSize'],
orderBy: input['orderBy'],
sortAscending: input['sortAscending']
}
end
end,
search_endpoint: lambda do |input|
case input['object_name']
when 'campaigns'
'/api/campaigns'
when 'events'
"/api/events/#{input['email']}"
when 'channels'
'/api/channels'
when 'catalogs'
'/api/catalogs'
when 'catalog_items'
"/api/catalogs/#{input['catalog_name']}/items"
when 'lists'
'/api/lists'
when 'message_types'
'/api/messageTypes'
end
end,
sample_search_record: lambda do |input|
case input['object_name']
when 'campaigns'
response = get('/api/campaigns')
result = parse_json(response.to_json)
call('format_unix_to_utc_time', result)
when 'channels'
get('/api/channels')
when 'catalogs'
get('/api/catalogs')&.dig('params')
when 'catalog_items'
catalog_name = get('/api/catalogs')&.dig('params', 'catalogNames', 0, 'name')
response = get("/api/catalogs/#{catalog_name}/items")&.dig('params')
result = parse_json(response.to_json)
call('format_unix_to_utc_time', result)
when 'lists'
get('/api/lists')
when 'message_types'
get('/api/messageTypes')
end
end,
search_object_output: lambda do |input|
case input['object_name']
when 'campaigns'
[
{ name: 'campaigns', type: 'array', of: 'object',
properties: [
{ control_type: 'number', type: 'number', name: 'id' },
{ control_type: 'date_time', type: 'date_time', name: 'createdAt' },
{ control_type: 'date_time', type: 'date_time', name: 'updatedAt' },
{ control_type: 'date_time', type: 'date_time', name: 'startAt' },
{ control_type: 'date_time', type: 'date_time', name: 'endedAt' },
{ name: 'name' },
{ control_type: 'number', parse_output: 'float_conversion',
type: 'number', name: 'templateId' },
{ name: 'messageMedium' },
{ name: 'createdByUserId' },
{ name: 'campaignState' },
{ control_type: 'number', parse_output: 'float_conversion',
type: 'number', name: 'sendSize' },
{ control_type: 'number', parse_output: 'float_conversion',
type: 'number', name: 'recurringCampaignId' },
{ control_type: 'number', parse_output: 'float_conversion',
type: 'number', name: 'workflowId' },
{ name: 'labels', type: 'array', of: 'string', control_type: 'text' },
{ name: 'listIds', type: 'array', of: 'number', control_type: 'text',
label: 'List IDs', parse_output: 'float_conversion' },
{ name: 'suppressionListIds', type: 'array', of: 'number', control_type: 'text',
label: 'Suppression list IDs', parse_output: 'float_conversion' },
{ name: 'type' }
] }
]
when 'events'
call('response_schema', input)
when 'channels'
[
{ name: 'channels', type: 'array', of: 'object',
properties: call('channel', '') }
]
when 'catalogs'
[{ name: 'catalogNames', type: 'array', of: 'object',
properties: [{ name: 'name' }] }]
when 'catalog_items'
[
{
name: 'catalogItemsWithProperties',
label: 'Catalog items',
type: 'array',
of: 'object',
properties: call('catalog_item', '').
concat([
{ name: 'value',
label: 'Custom fields',
type: 'object',
properties: call('response_schema', input) }
])
}
]
when 'lists'
[
{ name: 'lists', type: 'array', of: 'object',
properties: call('list', '') }
]
when 'message_types'
[
{ name: 'messageTypes', type: 'array', of: 'object',
properties: call('message_type', '') }
]
end
end,
search_campaigns_schema: lambda do |_input|
[]
end,
search_events_schema: lambda do |_input|
[
{ name: 'email', label: 'Email address', optional: false,
hint: 'Email of the user whose events you are retrieving.' },
{ name: 'limit', hint: 'The number of events to retrieve. (Max is 200)', sticky: true },
{
name: 'response_schema',
label: 'Response Schema',
control_type: 'schema-designer',
sample_data_type: 'json',
optional: true,
sticky: true,
empty_schema_title: 'Describe your response schema in JSON',
empty_schema_message: '<button type="button" ' \
'data-action="generateSchema">Use sample JSON</button> to ' \
'generate fields at once.<br>Response Schema should match the ' \
'<a href="https://api.iterable.com/api/docs#events_User_events" target="_blank">response syntax</a> ' \
'specified by the API.'
}
]
end,
search_catalogs_schema: lambda do |_input|
[
{ name: 'page', hint: 'Page number to list (starting at 1).', sticky: true },
{ name: 'pageSize', hint: 'Number of results to display per page (defaults to 10).', sticky: true }
]
end,
search_catalog_items_schema: lambda do |_input|
[
{ name: 'catalogName', optionl: false },
{ name: 'page', hint: 'Page number to list (starting at 1).', sticky: true },
{ name: 'pageSize', hint: 'Number of results to display per page (defaults to 10).', sticky: true },
{ name: 'orderBy', hint: 'Field by which results should be ordered. To also use the <b>Sort ascending</b> ' \
'parameter, this field must have a defined type.' },
{
name: 'sortAscending',
control_type: 'checkbox',
type: 'boolean',
hint: 'Sort results by ascending (Defaults to false).',
sticky: true,
toggle_hint: 'Select value',
render_input: 'boolean_conversion',
parse_output: 'boolean_conversion',
toggle_field: {
name: 'sortAscending',
label: 'Sort ascending',
toggle_hint: 'Use custom value',
hint: 'Valid values are <b>true</b> or <b>false</b>',
control_type: 'text',
type: 'string',
optional: true,
render_input: 'boolean_conversion',
parse_output: 'boolean_conversion'
}
}
].concat(call('custom_output_schema', ''))
end,
### RETRIEVE METHODS ###
format_get_params: lambda do |input|
case input['object_name']
when 'user'
{ email: input['email'] }
when 'email'
{ email: input['email'], messageId: input['messageId'] }
end
end,
get_endpoint: lambda do |input|
case input['object_name']
when 'user'
'/api/users/getByEmail'
when 'email'
'/api/email/viewInBrowser'
when 'catalog_item'
catalog_name = input.delete('catalogName')
item_id = input.delete('itemId')
"/api/catalogs/#{catalog_name}/items/#{item_id}"
end
end,
sample_get_record: lambda do |input|
case input['object_name']
when 'user'
{
"email": 'email@test.com',
"dataFields": 'Custom data fields',
"userId": '58124',
"mergeNestedObjects": 'true',
"correlationId": 'XXXXXX'
}
when 'catalog_item'
catalog_name = get('/api/catalogs')&.dig('params', 'catalogNames', 0, 'name')
get("/api/catalogs/#{catalog_name}/items")&.dig('params', 'catalogItemsWithProperties', 0)
end
end,
get_object_output: lambda do |input|
case input['object_name']
when 'user'
call('user', '').
concat([
{ name: 'dataFields',
label: 'Custom fields',
type: 'object',
properties: call('response_schema', input) }
])
when 'catalog_item'
call('catalog_item', '').
concat([
{ name: 'value',
label: 'Custom fields',
type: 'object',