klaviyo_sdk 1.0.0.20220329
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +6 -0
- data/README.md +1121 -0
- data/klaviyo_sdk.gemspec +35 -0
- data/lib/klaviyo_sdk/api/campaigns_api.rb +717 -0
- data/lib/klaviyo_sdk/api/data_privacy_api.rb +86 -0
- data/lib/klaviyo_sdk/api/lists_segments_api.rb +1101 -0
- data/lib/klaviyo_sdk/api/metrics_api.rb +343 -0
- data/lib/klaviyo_sdk/api/profiles_api.rb +381 -0
- data/lib/klaviyo_sdk/api/templates_api.rb +555 -0
- data/lib/klaviyo_sdk/api/track_identify_api.rb +288 -0
- data/lib/klaviyo_sdk/api_client.rb +389 -0
- data/lib/klaviyo_sdk/api_error.rb +57 -0
- data/lib/klaviyo_sdk/configuration.rb +278 -0
- data/lib/klaviyo_sdk/models/campaign.rb +310 -0
- data/lib/klaviyo_sdk/models/check_membership_request.rb +244 -0
- data/lib/klaviyo_sdk/models/delete_email.rb +218 -0
- data/lib/klaviyo_sdk/models/delete_person.rb +218 -0
- data/lib/klaviyo_sdk/models/delete_phone.rb +219 -0
- data/lib/klaviyo_sdk/models/deprecated_get_list_response.rb +298 -0
- data/lib/klaviyo_sdk/models/deprecated_get_list_response_data.rb +263 -0
- data/lib/klaviyo_sdk/models/global_exclusion_response_data.rb +274 -0
- data/lib/klaviyo_sdk/models/identify_payload.rb +237 -0
- data/lib/klaviyo_sdk/models/identify_payload_properties.rb +327 -0
- data/lib/klaviyo_sdk/models/inline_object.rb +220 -0
- data/lib/klaviyo_sdk/models/inline_object3.rb +226 -0
- data/lib/klaviyo_sdk/models/inline_object4.rb +254 -0
- data/lib/klaviyo_sdk/models/inline_object5.rb +288 -0
- data/lib/klaviyo_sdk/models/metric.rb +265 -0
- data/lib/klaviyo_sdk/models/metric_export.rb +285 -0
- data/lib/klaviyo_sdk/models/metric_timeline.rb +271 -0
- data/lib/klaviyo_sdk/models/metric_timeline_data.rb +294 -0
- data/lib/klaviyo_sdk/models/person.rb +389 -0
- data/lib/klaviyo_sdk/models/person.rb.bak +389 -0
- data/lib/klaviyo_sdk/models/privacy_email.rb +218 -0
- data/lib/klaviyo_sdk/models/privacy_id.rb +218 -0
- data/lib/klaviyo_sdk/models/privacy_phone.rb +218 -0
- data/lib/klaviyo_sdk/models/rendered_template.rb +247 -0
- data/lib/klaviyo_sdk/models/template.rb +272 -0
- data/lib/klaviyo_sdk/models/track_payload.rb +261 -0
- data/lib/klaviyo_sdk/models/track_payload_customer_properties.rb +227 -0
- data/lib/klaviyo_sdk/models/track_payload_properties.rb +237 -0
- data/lib/klaviyo_sdk/version.rb +15 -0
- data/lib/klaviyo_sdk.rb +124 -0
- metadata +120 -0
data/README.md
ADDED
@@ -0,0 +1,1121 @@
|
|
1
|
+
# Klaviyo Ruby SDK
|
2
|
+
|
3
|
+
- SDK version: 1.0.0.20220329
|
4
|
+
|
5
|
+
## Helpful Resources
|
6
|
+
|
7
|
+
- [API Reference](https://developers.klaviyo.com/en/reference/api-overview)
|
8
|
+
- [API Guides](https://developers.klaviyo.com/en/docs)
|
9
|
+
- [Postman Workspace](https://www.postman.com/klaviyo/workspace/klaviyo-developers)
|
10
|
+
|
11
|
+
## Design & Approach
|
12
|
+
|
13
|
+
This SDK is a thin wrapper around our API. See our API Reference for full documentation on API behavior.
|
14
|
+
|
15
|
+
## Organization
|
16
|
+
|
17
|
+
This SDK is organized into the following resources:
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
- Campaigns
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
- DataPrivacy
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
- ListsSegments
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
- Metrics
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
- Profiles
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
- Templates
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
- TrackIdentify
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
# Installation
|
50
|
+
|
51
|
+
|
52
|
+
## Build
|
53
|
+
|
54
|
+
To build the Ruby code into a gem:
|
55
|
+
|
56
|
+
```shell
|
57
|
+
gem build klaviyo_sdk.gemspec
|
58
|
+
```
|
59
|
+
|
60
|
+
Then install the gem locally:
|
61
|
+
|
62
|
+
```shell
|
63
|
+
gem install ./klaviyo_sdk-1.0.0.20220329.gem
|
64
|
+
```
|
65
|
+
|
66
|
+
|
67
|
+
Finally add this to the Gemfile:
|
68
|
+
|
69
|
+
gem 'klaviyo_sdk', '~> 1.0.0.20220329'
|
70
|
+
|
71
|
+
To install directly from rubygems:
|
72
|
+
|
73
|
+
```shell
|
74
|
+
gem install klaviyo_sdk
|
75
|
+
```
|
76
|
+
|
77
|
+
# Usage Example
|
78
|
+
|
79
|
+
### To load the gem
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
# Load the gem
|
83
|
+
require 'klaviyo_sdk'
|
84
|
+
|
85
|
+
# Setup authorization
|
86
|
+
Client.configure do |config|
|
87
|
+
config.api_key['ApiKeyAuth'] = 'YOUR API KEY'
|
88
|
+
#config.max_retries = 5 # optional
|
89
|
+
#config.max_delay = 60 # optional
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
93
|
+
NOTE:
|
94
|
+
* The SDK retries on resolvable errors, namely: rate limits (common) and server errors on klaviyo (rare).
|
95
|
+
* `max_retry` denotes number of attempts the client will make in order to execute the request successfully.
|
96
|
+
* `max_delay` denotes total delay (in seconds) across all attempts.
|
97
|
+
|
98
|
+
### To call the `metric-export` operation:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
metric_id = 'METRIC_ID'
|
102
|
+
count = 100
|
103
|
+
|
104
|
+
begin
|
105
|
+
result = Client::Metrics.metric_export(metric_id, count=count)
|
106
|
+
end
|
107
|
+
```
|
108
|
+
|
109
|
+
# Error Handling
|
110
|
+
|
111
|
+
This SDK throws an `ApiException` error when the server returns a non-`2XX` response.
|
112
|
+
```ruby
|
113
|
+
metric_id = 'METRIC_ID'
|
114
|
+
count = 100
|
115
|
+
|
116
|
+
begin
|
117
|
+
result = Client::Metrics.metric_export(metric_id, count=count)
|
118
|
+
rescue Client::ApiError => e
|
119
|
+
puts "Error when calling Metrics.metric_export #{e}"
|
120
|
+
end
|
121
|
+
```
|
122
|
+
|
123
|
+
# Comprehensive list of Operations & Parameters
|
124
|
+
|
125
|
+
_**NOTE:**_
|
126
|
+
- Organization: Resource groups and operation_ids are listed in alphabetical order, first by Resource name, then by **OpenAPI Summary**. Operation summaries are those listed in the right side bar of the [API Reference](https://developers.klaviyo.com/en/reference/track-post).
|
127
|
+
- For example values / data types, as well as whether parameters are required/optional, please reference the corresponding API Reference link.
|
128
|
+
- Some args are required for the API call to succeed, the API docs above are the source of truth regarding which params are required.
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
## Campaigns
|
134
|
+
|
135
|
+
|
136
|
+
#### [Cancel a Campaign](https://developers.klaviyo.com/en/reference/cancel-campaign)
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
Client::Campaigns.cancel_campaign(campaign_id)
|
140
|
+
```
|
141
|
+
|
142
|
+
#### Example:
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
campaign_id = 'CAMPAIGN_ID'
|
146
|
+
response = Client::Campaigns.cancel_campaign(campaign_id)
|
147
|
+
```
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
#### [Clone a Campaign](https://developers.klaviyo.com/en/reference/clone-campaign)
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
Client::Campaigns.clone_campaign(campaign_id, name, list_id)
|
157
|
+
```
|
158
|
+
|
159
|
+
#### Example:
|
160
|
+
```ruby
|
161
|
+
campaign_id = 'CAMPAIGN_ID'
|
162
|
+
name = 'CLONED_CAMPAIGN'
|
163
|
+
list_id = 'LIST_ID'
|
164
|
+
|
165
|
+
response = Client::Campaigns.clone_campaign(campaign_id, name, list_id)
|
166
|
+
```
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
#### [Create New Campaign](https://developers.klaviyo.com/en/reference/create-campaign)
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
Client::Campaigns.create_campaign(list_id, template_id, from_email, from_name, subject, opts)
|
176
|
+
```
|
177
|
+
|
178
|
+
#### Example:
|
179
|
+
```ruby
|
180
|
+
list_id = 'LIST_ID'
|
181
|
+
template_id = 'TEMPLATE_ID'
|
182
|
+
from_email = 'george.washington@klaviyo.com'
|
183
|
+
from_name = 'George Washington'
|
184
|
+
subject = 'Happy Fourth!'
|
185
|
+
|
186
|
+
opts = {
|
187
|
+
'use_smart_sending': true,
|
188
|
+
'add_google_analytics': false,
|
189
|
+
'name': 'Campaign Name',
|
190
|
+
}
|
191
|
+
|
192
|
+
response = Client::Campaigns.create_campaign(list_id, template_id, from_email, from_name, subject, opts)
|
193
|
+
```
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
#### [Get Campaign Info](https://developers.klaviyo.com/en/reference/get-campaign-info)
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
Client::Campaigns.get_campaign_info(campaign_id)
|
202
|
+
```
|
203
|
+
|
204
|
+
#### Example:
|
205
|
+
```ruby
|
206
|
+
campaign_id = 'CAMPAIGN_ID'
|
207
|
+
|
208
|
+
response = Client::Campaigns.get_campaign_info(campaign_id)
|
209
|
+
```
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
#### [Get Campaign Recipients](https://developers.klaviyo.com/en/reference/get-campaign-recipients)
|
215
|
+
|
216
|
+
```ruby
|
217
|
+
Client::Campaigns.get_campaign_recipients(campaign_id, opts)
|
218
|
+
```
|
219
|
+
|
220
|
+
#### Example:
|
221
|
+
```ruby
|
222
|
+
campaign_id = 'CAMPAIGN_ID'
|
223
|
+
|
224
|
+
# optional parameters
|
225
|
+
opts = {
|
226
|
+
'count': 1,
|
227
|
+
'sort': 'desc',
|
228
|
+
# offset: 'offset'
|
229
|
+
}
|
230
|
+
|
231
|
+
response = Client::Campaigns.get_campaign_recipients(campaign_id, opts)
|
232
|
+
```
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
#### [Get Campaigns](https://developers.klaviyo.com/en/reference/get-campaigns)
|
238
|
+
|
239
|
+
```ruby
|
240
|
+
Client::Campaigns.get_campaigns(opts)
|
241
|
+
```
|
242
|
+
|
243
|
+
#### Example:
|
244
|
+
```ruby
|
245
|
+
opts = {
|
246
|
+
'page': 1,
|
247
|
+
'count': 1
|
248
|
+
}
|
249
|
+
|
250
|
+
response = Client::Campaigns.get_campaigns(opts)
|
251
|
+
```
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
#### [Schedule a Campaign](https://developers.klaviyo.com/en/reference/schedule-campaign)
|
257
|
+
|
258
|
+
```ruby
|
259
|
+
Client::Campaigns.schedule_campaign(campaign_id, send_time)
|
260
|
+
```
|
261
|
+
|
262
|
+
#### Example:
|
263
|
+
```ruby
|
264
|
+
campaign_id = 'CAMPAIGN_ID'
|
265
|
+
send_time = '2030-01-13 00:00:00'
|
266
|
+
|
267
|
+
response = Client::Campaigns.schedule_campaign(campaign_id, send_time)
|
268
|
+
```
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
#### [Send a Campaign Immediately](https://developers.klaviyo.com/en/reference/send-campaign)
|
274
|
+
|
275
|
+
```ruby
|
276
|
+
Client::Campaigns.send_campaign(campaign_id)
|
277
|
+
```
|
278
|
+
|
279
|
+
#### Example:
|
280
|
+
```ruby
|
281
|
+
campaign_id = 'CAMPAIGN_ID'
|
282
|
+
|
283
|
+
response = Client::Campaigns.send_campaign(campaign_id)
|
284
|
+
|
285
|
+
```
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
|
290
|
+
#### [Update Campaign](https://developers.klaviyo.com/en/reference/update-campaign)
|
291
|
+
|
292
|
+
```ruby
|
293
|
+
Client::Campaigns.update_campaign(campaign_id, opts)
|
294
|
+
```
|
295
|
+
|
296
|
+
#### Example:
|
297
|
+
```ruby
|
298
|
+
campaign_id = 'CAMPAIGN_ID'
|
299
|
+
|
300
|
+
opts = {
|
301
|
+
'list_id': 'LIST_ID',
|
302
|
+
'template_id': 'TEMPLATE_ID',
|
303
|
+
'from_email': 'george.washington@klaviyo.com',
|
304
|
+
'from_name': 'George Washington',
|
305
|
+
'subject': 'Happy Fourth!',
|
306
|
+
'name': 'Campaign Name',
|
307
|
+
'use_smart_sending': true,
|
308
|
+
'add_google_analytics': false
|
309
|
+
}
|
310
|
+
|
311
|
+
response = Client::Campaigns.update_campaign(campaign_id, opts)
|
312
|
+
|
313
|
+
```
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
## DataPrivacy
|
320
|
+
|
321
|
+
|
322
|
+
#### [Request a Deletion](https://developers.klaviyo.com/en/reference/request-deletion)
|
323
|
+
|
324
|
+
```ruby
|
325
|
+
Client::DataPrivacy.request_deletion(opts)
|
326
|
+
```
|
327
|
+
|
328
|
+
#### Example:
|
329
|
+
```ruby
|
330
|
+
opts = {
|
331
|
+
body: {
|
332
|
+
'email': 'abraham.lincoln@klaviyo.com'
|
333
|
+
}
|
334
|
+
}
|
335
|
+
|
336
|
+
response = Client::DataPrivacy.request_deletion(opts)
|
337
|
+
```
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
## ListsSegments
|
344
|
+
|
345
|
+
|
346
|
+
#### [Add Members to a List](https://developers.klaviyo.com/en/reference/add-members)
|
347
|
+
|
348
|
+
```ruby
|
349
|
+
Client::ListsSegments.add_members(list_id, opts)
|
350
|
+
```
|
351
|
+
|
352
|
+
#### Example:
|
353
|
+
```ruby
|
354
|
+
list_id = 'LIST_ID'
|
355
|
+
opts = {
|
356
|
+
body: {
|
357
|
+
profiles: [
|
358
|
+
{
|
359
|
+
'email': 'george.washington@klaviyo.com'
|
360
|
+
}
|
361
|
+
]
|
362
|
+
}
|
363
|
+
}
|
364
|
+
|
365
|
+
response = Client::ListsSegments.add_members(list_id, opts)
|
366
|
+
```
|
367
|
+
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
#### [Create List](https://developers.klaviyo.com/en/reference/create-list)
|
372
|
+
|
373
|
+
```ruby
|
374
|
+
Client::ListsSegments.create_list(list_name)
|
375
|
+
```
|
376
|
+
|
377
|
+
#### Example:
|
378
|
+
```ruby
|
379
|
+
list_name = 'MyNewList'
|
380
|
+
|
381
|
+
response = Client::ListsSegments.create_list(list_name)
|
382
|
+
```
|
383
|
+
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
#### [Delete List](https://developers.klaviyo.com/en/reference/delete-list)
|
388
|
+
|
389
|
+
```ruby
|
390
|
+
Client::ListsSegments.delete_list(list_id)
|
391
|
+
```
|
392
|
+
|
393
|
+
#### Example:
|
394
|
+
```ruby
|
395
|
+
list_id = 'LIST_ID'
|
396
|
+
|
397
|
+
response = Client::ListsSegments.delete_list(list_id)
|
398
|
+
```
|
399
|
+
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
#### [Exclude Profile From All Email](https://developers.klaviyo.com/en/reference/exclude-globally)
|
404
|
+
|
405
|
+
```ruby
|
406
|
+
Client::ListsSegments.exclude_globally(email)
|
407
|
+
```
|
408
|
+
|
409
|
+
#### Example:
|
410
|
+
```ruby
|
411
|
+
email = 'george.washington@klaviyo.com'
|
412
|
+
|
413
|
+
response = Client::ListsSegments.exclude_globally(email)
|
414
|
+
```
|
415
|
+
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
#### [Get Global Exclusions & Unsubscribes](https://developers.klaviyo.com/en/reference/get-global-exclusions)
|
420
|
+
|
421
|
+
```ruby
|
422
|
+
Client::ListsSegments.get_global_exclusions(opts)
|
423
|
+
```
|
424
|
+
|
425
|
+
#### Example:
|
426
|
+
```ruby
|
427
|
+
opts = {
|
428
|
+
query_params: {
|
429
|
+
reason: 'manually_excluded',
|
430
|
+
sort: 'desc',
|
431
|
+
count: 2,
|
432
|
+
page: 1
|
433
|
+
}
|
434
|
+
}
|
435
|
+
|
436
|
+
response = Client::ListsSegments.get_global_exclusions(opts)
|
437
|
+
```
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
|
442
|
+
#### [Get All Exclusions for a List](https://developers.klaviyo.com/en/reference/get-list-exclusions)
|
443
|
+
|
444
|
+
```ruby
|
445
|
+
Client::ListsSegments.get_list_exclusions(list_id, opts)
|
446
|
+
```
|
447
|
+
|
448
|
+
#### Example:
|
449
|
+
```ruby
|
450
|
+
list_id = 'LIST_ID'
|
451
|
+
|
452
|
+
opts = {
|
453
|
+
query_params: {
|
454
|
+
# marker: 12345
|
455
|
+
}
|
456
|
+
}
|
457
|
+
|
458
|
+
response = Client::ListsSegments.get_list_exclusions(list_id, opts)
|
459
|
+
```
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
|
464
|
+
#### [Get List Info](https://developers.klaviyo.com/en/reference/get-list-info)
|
465
|
+
|
466
|
+
```ruby
|
467
|
+
Client::ListsSegments.get_list_info(list_id)
|
468
|
+
```
|
469
|
+
|
470
|
+
#### Example:
|
471
|
+
```ruby
|
472
|
+
list_id = 'LIST_ID'
|
473
|
+
|
474
|
+
response = Client::ListsSegments.get_list_info(list_id)
|
475
|
+
```
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
|
480
|
+
#### [Check if Profiles Are in a List](https://developers.klaviyo.com/en/reference/get-list-members)
|
481
|
+
|
482
|
+
```ruby
|
483
|
+
Client::ListsSegments.get_list_members(list_id, opts)
|
484
|
+
```
|
485
|
+
|
486
|
+
#### Example:
|
487
|
+
```ruby
|
488
|
+
list_id = 'LIST_ID'
|
489
|
+
|
490
|
+
opts = {
|
491
|
+
body: {
|
492
|
+
'emails': [
|
493
|
+
'george.washington@klaviyo.com'
|
494
|
+
]
|
495
|
+
}
|
496
|
+
}
|
497
|
+
|
498
|
+
response = Client::ListsSegments.get_list_members(list_id, opts)
|
499
|
+
```
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
|
504
|
+
#### [Check if Profiles Are in a List and not Suppressed](https://developers.klaviyo.com/en/reference/get-list-subscriptions)
|
505
|
+
|
506
|
+
```ruby
|
507
|
+
Client::ListsSegments.get_list_subscriptions(list_id, opts)
|
508
|
+
```
|
509
|
+
|
510
|
+
#### Example:
|
511
|
+
```ruby
|
512
|
+
list_id = 'LIST_ID'
|
513
|
+
|
514
|
+
opts = {
|
515
|
+
body: {'emails': ['george.washington@klaviyo.com']}
|
516
|
+
}
|
517
|
+
|
518
|
+
response = Client::ListsSegments.get_list_subscriptions(list_id, opts)
|
519
|
+
```
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
|
524
|
+
#### [Get Lists](https://developers.klaviyo.com/en/reference/get-lists)
|
525
|
+
|
526
|
+
```ruby
|
527
|
+
Client::ListsSegments.get_lists
|
528
|
+
```
|
529
|
+
|
530
|
+
#### Example:
|
531
|
+
```ruby
|
532
|
+
response = Client::ListsSegments.get_lists
|
533
|
+
```
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
|
538
|
+
#### [Get List and Segment Members](https://developers.klaviyo.com/en/reference/get-members)
|
539
|
+
|
540
|
+
```ruby
|
541
|
+
Client::ListsSegments.get_members(list_or_segment_id, opts)
|
542
|
+
```
|
543
|
+
|
544
|
+
#### Example:
|
545
|
+
```ruby
|
546
|
+
list_id = 'LIST_ID'
|
547
|
+
|
548
|
+
opts = {
|
549
|
+
query_params: {
|
550
|
+
# marker: 12345
|
551
|
+
}
|
552
|
+
}
|
553
|
+
response = Client::ListsSegments.get_members(list_id)
|
554
|
+
```
|
555
|
+
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
#### [Check if Profiles Are in a Segment](https://developers.klaviyo.com/en/reference/get-segment-members)
|
560
|
+
|
561
|
+
```ruby
|
562
|
+
Client::ListsSegments.get_segment_members(segment_id, opts)
|
563
|
+
```
|
564
|
+
|
565
|
+
#### Example:
|
566
|
+
```ruby
|
567
|
+
segment_id = 'SEGMENT_ID'
|
568
|
+
|
569
|
+
opts = {
|
570
|
+
body: {'emails': ['george.washington@klaviyo.com']}
|
571
|
+
}
|
572
|
+
response = Client::ListsSegments.get_segment_members(segment_id, opts)
|
573
|
+
```
|
574
|
+
|
575
|
+
|
576
|
+
|
577
|
+
|
578
|
+
#### [Remove Profiles From List](https://developers.klaviyo.com/en/reference/remove-members)
|
579
|
+
|
580
|
+
```ruby
|
581
|
+
Client::ListsSegments.remove_members(list_id, opts)
|
582
|
+
```
|
583
|
+
|
584
|
+
#### Example:
|
585
|
+
```ruby
|
586
|
+
list_id = 'LIST_ID'
|
587
|
+
|
588
|
+
opts = {
|
589
|
+
body: {'emails': ['george.washington@klaviyo.com']}
|
590
|
+
}
|
591
|
+
|
592
|
+
response = Client::ListsSegments.remove_members(list_id, opts)
|
593
|
+
```
|
594
|
+
|
595
|
+
|
596
|
+
|
597
|
+
|
598
|
+
#### [Subscribe Profiles to List](https://developers.klaviyo.com/en/reference/subscribe)
|
599
|
+
|
600
|
+
```ruby
|
601
|
+
Client::ListsSegments.subscribe(list_id, opts)
|
602
|
+
```
|
603
|
+
|
604
|
+
#### Example:
|
605
|
+
```ruby
|
606
|
+
list_id = 'LIST_ID'
|
607
|
+
|
608
|
+
opts = {
|
609
|
+
body: {
|
610
|
+
profiles: [
|
611
|
+
{
|
612
|
+
'email': 'george.washington@klaviyo.com'
|
613
|
+
}
|
614
|
+
]
|
615
|
+
}
|
616
|
+
}
|
617
|
+
|
618
|
+
response = Client::ListsSegmentsApi.new.subscribe(list_id, opts)
|
619
|
+
```
|
620
|
+
|
621
|
+
|
622
|
+
|
623
|
+
|
624
|
+
#### [Unsubscribe Profiles From List](https://developers.klaviyo.com/en/reference/unsubscribe)
|
625
|
+
|
626
|
+
```ruby
|
627
|
+
Client::ListsSegments.unsubscribe(list_id, opts)
|
628
|
+
```
|
629
|
+
|
630
|
+
#### Example:
|
631
|
+
```ruby
|
632
|
+
list_id = 'LIST_ID'
|
633
|
+
|
634
|
+
opts = {
|
635
|
+
body: {
|
636
|
+
'emails': [
|
637
|
+
'george.washington@klaviyo.com'
|
638
|
+
]
|
639
|
+
}
|
640
|
+
}
|
641
|
+
response = Client::ListsSegments.unsubscribe(list_id, opts)
|
642
|
+
```
|
643
|
+
|
644
|
+
|
645
|
+
|
646
|
+
|
647
|
+
#### [Update List Name](https://developers.klaviyo.com/en/reference/update-list-name)
|
648
|
+
|
649
|
+
```ruby
|
650
|
+
Client::ListsSegments.update_list_name(list_id, list_name)
|
651
|
+
```
|
652
|
+
|
653
|
+
#### Example:
|
654
|
+
```ruby
|
655
|
+
list_id = 'LIST_ID'
|
656
|
+
list_name = 'MyRenamedList'
|
657
|
+
|
658
|
+
response = Client::ListsSegments.update_list_name(list_id, list_name)
|
659
|
+
```
|
660
|
+
|
661
|
+
|
662
|
+
|
663
|
+
|
664
|
+
|
665
|
+
## Metrics
|
666
|
+
|
667
|
+
|
668
|
+
#### [Get Metrics Info](https://developers.klaviyo.com/en/reference/get-metrics)
|
669
|
+
|
670
|
+
```ruby
|
671
|
+
Client::Metrics.get_metrics(opts)
|
672
|
+
```
|
673
|
+
|
674
|
+
#### Example:
|
675
|
+
```ruby
|
676
|
+
opts = {
|
677
|
+
query_params: {
|
678
|
+
page: 0,
|
679
|
+
count: 50
|
680
|
+
}
|
681
|
+
}
|
682
|
+
|
683
|
+
response = Client::Metrics.get_metrics(opts)
|
684
|
+
```
|
685
|
+
|
686
|
+
|
687
|
+
|
688
|
+
|
689
|
+
#### [Query Event Data](https://developers.klaviyo.com/en/reference/metric-export)
|
690
|
+
|
691
|
+
```ruby
|
692
|
+
Client::Metrics.metric_export(metric_id, opts)
|
693
|
+
```
|
694
|
+
|
695
|
+
#### Example:
|
696
|
+
```ruby
|
697
|
+
metric_id = 'METRIC_ID'
|
698
|
+
opts = {
|
699
|
+
query_params: {
|
700
|
+
unit: 'week',
|
701
|
+
measurement: 'sum',
|
702
|
+
count: 2
|
703
|
+
}
|
704
|
+
}
|
705
|
+
|
706
|
+
response = Client::Metrics.metric_export(metric_id, opts)
|
707
|
+
```
|
708
|
+
|
709
|
+
|
710
|
+
|
711
|
+
|
712
|
+
#### [Get Events for a Specific Metric](https://developers.klaviyo.com/en/reference/metric-timeline)
|
713
|
+
|
714
|
+
```ruby
|
715
|
+
Client::Metrics.metric_timeline(metric_id, opts)
|
716
|
+
```
|
717
|
+
|
718
|
+
#### Example:
|
719
|
+
```ruby
|
720
|
+
metric_id = 'METRIC_ID'
|
721
|
+
|
722
|
+
opts = {
|
723
|
+
query_params: {
|
724
|
+
since: '0000000000',
|
725
|
+
count: 2,
|
726
|
+
sort: 'asc'
|
727
|
+
}
|
728
|
+
}
|
729
|
+
|
730
|
+
response = Client::Metrics.metric_timeline(metric_id, opts)
|
731
|
+
```
|
732
|
+
|
733
|
+
|
734
|
+
|
735
|
+
|
736
|
+
#### [Get Events for All Metrics](https://developers.klaviyo.com/en/reference/metrics-timeline)
|
737
|
+
|
738
|
+
```ruby
|
739
|
+
Client::Metrics.metrics_timeline(opts)
|
740
|
+
```
|
741
|
+
|
742
|
+
#### Example:
|
743
|
+
```ruby
|
744
|
+
opts = {
|
745
|
+
query_params: {
|
746
|
+
since: '0000000000',
|
747
|
+
count: 2,
|
748
|
+
sort: 'asc'
|
749
|
+
}
|
750
|
+
}
|
751
|
+
response = Client::Metrics.metrics_timeline(opts)
|
752
|
+
```
|
753
|
+
|
754
|
+
|
755
|
+
|
756
|
+
|
757
|
+
|
758
|
+
## Profiles
|
759
|
+
|
760
|
+
|
761
|
+
#### [Exchange ID for Profile ID](https://developers.klaviyo.com/en/reference/exchange)
|
762
|
+
|
763
|
+
```ruby
|
764
|
+
Client::Profiles.exchange(opts)
|
765
|
+
```
|
766
|
+
|
767
|
+
#### Example:
|
768
|
+
```ruby
|
769
|
+
opts = {
|
770
|
+
body: {'exchange_id': 'EXCHANGE_ID'}
|
771
|
+
}
|
772
|
+
|
773
|
+
response = Client::Profiles.exchange(opts)
|
774
|
+
```
|
775
|
+
|
776
|
+
|
777
|
+
|
778
|
+
|
779
|
+
#### [Get Profile](https://developers.klaviyo.com/en/reference/get-profile)
|
780
|
+
|
781
|
+
```ruby
|
782
|
+
Client::Profiles.get_profile(person_id)
|
783
|
+
```
|
784
|
+
|
785
|
+
#### Example:
|
786
|
+
```ruby
|
787
|
+
person_id = 'PERSON_ID'
|
788
|
+
|
789
|
+
response = Client::Profiles.get_profile(person_id)
|
790
|
+
```
|
791
|
+
|
792
|
+
|
793
|
+
|
794
|
+
|
795
|
+
#### [Get Profile's Events for a Specific Metric](https://developers.klaviyo.com/en/reference/profile-metric-timeline)
|
796
|
+
|
797
|
+
```ruby
|
798
|
+
Client::Profiles.profile_metric_timeline(person_id, metric_id, opts)
|
799
|
+
```
|
800
|
+
|
801
|
+
#### Example:
|
802
|
+
```ruby
|
803
|
+
person_id = 'PERSON_ID'
|
804
|
+
metric_id = 'METRIC_ID'
|
805
|
+
|
806
|
+
opts = {
|
807
|
+
query_params: {
|
808
|
+
since: '0000000000',
|
809
|
+
count: 2,
|
810
|
+
sort: 'asc'
|
811
|
+
}
|
812
|
+
}
|
813
|
+
|
814
|
+
response = Client::Profiles.profile_metric_timeline(person_id, metric_id, opts)
|
815
|
+
```
|
816
|
+
|
817
|
+
|
818
|
+
|
819
|
+
|
820
|
+
#### [Get Profile's Events for all Metrics](https://developers.klaviyo.com/en/reference/profile-metrics-timeline)
|
821
|
+
|
822
|
+
```ruby
|
823
|
+
Client::Profiles.profile_metrics_timeline(person_id, opts)
|
824
|
+
```
|
825
|
+
|
826
|
+
#### Example:
|
827
|
+
```ruby
|
828
|
+
person_id = 'PERSON_ID'
|
829
|
+
|
830
|
+
opts = {
|
831
|
+
query_params: {
|
832
|
+
since: '0000000000',
|
833
|
+
count: 2,
|
834
|
+
sort: 'asc'
|
835
|
+
}
|
836
|
+
}
|
837
|
+
|
838
|
+
response = Client::Profiles.profile_metrics_timeline(person_id, opts)
|
839
|
+
```
|
840
|
+
|
841
|
+
|
842
|
+
|
843
|
+
|
844
|
+
#### [Update Profile](https://developers.klaviyo.com/en/reference/update-profile)
|
845
|
+
|
846
|
+
```ruby
|
847
|
+
Client::Profiles.update_profile(person_id, opts)
|
848
|
+
```
|
849
|
+
|
850
|
+
#### Example:
|
851
|
+
```ruby
|
852
|
+
person_id = 'PERSON_ID'
|
853
|
+
|
854
|
+
opts = {
|
855
|
+
query_params: {'$email': 'george.washington@klaviyo.com'}
|
856
|
+
}
|
857
|
+
|
858
|
+
response = Client::Profiles.update_profile(person_id, opts)
|
859
|
+
```
|
860
|
+
|
861
|
+
|
862
|
+
|
863
|
+
|
864
|
+
|
865
|
+
## Templates
|
866
|
+
|
867
|
+
|
868
|
+
#### [Clone Template](https://developers.klaviyo.com/en/reference/clone-template)
|
869
|
+
|
870
|
+
```ruby
|
871
|
+
Client::Templates.clone_template(template_id, name)
|
872
|
+
```
|
873
|
+
|
874
|
+
#### Example:
|
875
|
+
```ruby
|
876
|
+
template_id = 'TEMPLATE_ID'
|
877
|
+
name = 'My Cloned Template'
|
878
|
+
|
879
|
+
response = Client::Templates.clone_template(template_id, name)
|
880
|
+
```
|
881
|
+
|
882
|
+
|
883
|
+
|
884
|
+
|
885
|
+
#### [Create New Template](https://developers.klaviyo.com/en/reference/create-template)
|
886
|
+
|
887
|
+
```ruby
|
888
|
+
Client::Templates.create_template(name, html)
|
889
|
+
```
|
890
|
+
|
891
|
+
#### Example:
|
892
|
+
```ruby
|
893
|
+
name = 'New Template Name'
|
894
|
+
html = '<html><body><p>This is an email for {{ email }}.</p></body></html>'
|
895
|
+
|
896
|
+
response = Client::Templates.create_template(name, html)
|
897
|
+
```
|
898
|
+
|
899
|
+
|
900
|
+
|
901
|
+
|
902
|
+
#### [Delete Template](https://developers.klaviyo.com/en/reference/delete-template)
|
903
|
+
|
904
|
+
```ruby
|
905
|
+
Client::Templates.delete_template(template_id)
|
906
|
+
```
|
907
|
+
|
908
|
+
#### Example:
|
909
|
+
```ruby
|
910
|
+
template_id = 'TEMPLATE_ID'
|
911
|
+
|
912
|
+
response = Client::Templates.delete_template(template_id)
|
913
|
+
```
|
914
|
+
|
915
|
+
|
916
|
+
|
917
|
+
|
918
|
+
#### [Get All Templates](https://developers.klaviyo.com/en/reference/get-templates)
|
919
|
+
|
920
|
+
```ruby
|
921
|
+
Client::Templates.get_templates
|
922
|
+
```
|
923
|
+
|
924
|
+
#### Example:
|
925
|
+
```ruby
|
926
|
+
response = Client::Templates.get_templates
|
927
|
+
```
|
928
|
+
|
929
|
+
|
930
|
+
|
931
|
+
|
932
|
+
#### [Render Template](https://developers.klaviyo.com/en/reference/render-template)
|
933
|
+
|
934
|
+
```ruby
|
935
|
+
Client::Templates.render_template(template_id, opts)
|
936
|
+
```
|
937
|
+
|
938
|
+
#### Example:
|
939
|
+
```ruby
|
940
|
+
template_id = 'TEMPLATE_ID'
|
941
|
+
context = {'name': 'George Washington', 'state': 'VA'}
|
942
|
+
|
943
|
+
opts = {
|
944
|
+
form_params: {
|
945
|
+
context: context.to_json
|
946
|
+
}
|
947
|
+
}
|
948
|
+
|
949
|
+
response = Client::Templates.render_template(template_id, opts)
|
950
|
+
```
|
951
|
+
|
952
|
+
|
953
|
+
|
954
|
+
|
955
|
+
#### [Render and Send Template](https://developers.klaviyo.com/en/reference/send-template)
|
956
|
+
|
957
|
+
```ruby
|
958
|
+
Client::Templates.send_template(template_id, from_email, from_name, subject, to, opts)
|
959
|
+
```
|
960
|
+
|
961
|
+
#### Example:
|
962
|
+
```ruby
|
963
|
+
template_id = 'TEMPLATE_ID'
|
964
|
+
from_email = 'george.washington@klaviyo.com'
|
965
|
+
from_name = 'George Washington'
|
966
|
+
subject = 'Happy Fourth!'
|
967
|
+
to = 'george.washington@klaviyo.com'
|
968
|
+
context = {'name': 'George Washington', 'state': 'VA'}
|
969
|
+
|
970
|
+
opts = {
|
971
|
+
form_params: {
|
972
|
+
context: context.to_json
|
973
|
+
}
|
974
|
+
}
|
975
|
+
|
976
|
+
response = Client::Templates.send_template(template_id, from_email, from_name, subject, to, opts)
|
977
|
+
```
|
978
|
+
|
979
|
+
|
980
|
+
|
981
|
+
|
982
|
+
#### [Update Template](https://developers.klaviyo.com/en/reference/update-template)
|
983
|
+
|
984
|
+
```ruby
|
985
|
+
Client::Templates.update_template(template_id, opts)
|
986
|
+
```
|
987
|
+
|
988
|
+
#### Example:
|
989
|
+
```ruby
|
990
|
+
template_id = 'TEMPLATE_ID'
|
991
|
+
opts = {
|
992
|
+
form_params: {
|
993
|
+
name: 'New Template Name',
|
994
|
+
html: '<html><body><p>This is an email for {{ email }}.</p></body></html>'
|
995
|
+
}
|
996
|
+
}
|
997
|
+
|
998
|
+
response = Client::Templates.update_template(template_id, opts)
|
999
|
+
```
|
1000
|
+
|
1001
|
+
|
1002
|
+
|
1003
|
+
|
1004
|
+
|
1005
|
+
## TrackIdentify
|
1006
|
+
|
1007
|
+
|
1008
|
+
#### [Identify Profile (Legacy)](https://developers.klaviyo.com/en/reference/identify-get)
|
1009
|
+
|
1010
|
+
```ruby
|
1011
|
+
Client::TrackIdentify.identify_get(data)
|
1012
|
+
```
|
1013
|
+
|
1014
|
+
#### Example:
|
1015
|
+
```ruby
|
1016
|
+
require 'base64'
|
1017
|
+
identify_payload = {
|
1018
|
+
'token': 'PUBLIC_KEY',
|
1019
|
+
'properties': {
|
1020
|
+
'$email': 'abraham.lincoln@klaviyo.com',
|
1021
|
+
'$first_name': 'Abraham',
|
1022
|
+
'$last_name': 'Lincoln',
|
1023
|
+
'$city': 'Springfield',
|
1024
|
+
'$region': 'Illinois'
|
1025
|
+
}
|
1026
|
+
}
|
1027
|
+
|
1028
|
+
encoded_payload = Base64.encode64(identify_payload.to_json).encode(Encoding::UTF_8)
|
1029
|
+
response = Client::TrackIdentify.identify_get(encoded_payload)
|
1030
|
+
```
|
1031
|
+
|
1032
|
+
|
1033
|
+
|
1034
|
+
|
1035
|
+
#### [Identify Profile](https://developers.klaviyo.com/en/reference/identify-post)
|
1036
|
+
|
1037
|
+
```ruby
|
1038
|
+
Client::TrackIdentify.identify_post(data)
|
1039
|
+
```
|
1040
|
+
|
1041
|
+
#### Example:
|
1042
|
+
```ruby
|
1043
|
+
identify_payload = {
|
1044
|
+
'token': 'PUBLIC_KEY',
|
1045
|
+
'properties': {
|
1046
|
+
'$email': 'abraham.lincoln@klaviyo.com',
|
1047
|
+
'$first_name': 'Abraham',
|
1048
|
+
'$last_name': 'Lincoln',
|
1049
|
+
'$city': 'Springfield',
|
1050
|
+
'$region': 'Illinois'
|
1051
|
+
}
|
1052
|
+
}
|
1053
|
+
|
1054
|
+
data = identify_payload.to_json
|
1055
|
+
response = Client::TrackIdentify.identify_post(data)
|
1056
|
+
```
|
1057
|
+
|
1058
|
+
|
1059
|
+
|
1060
|
+
|
1061
|
+
#### [Track Profile Activity (Legacy)](https://developers.klaviyo.com/en/reference/track-get)
|
1062
|
+
|
1063
|
+
```ruby
|
1064
|
+
Client::TrackIdentify.track_get(data)
|
1065
|
+
```
|
1066
|
+
|
1067
|
+
#### Example:
|
1068
|
+
```ruby
|
1069
|
+
require 'base64'
|
1070
|
+
track_payload = {
|
1071
|
+
'token': 'PUBLIC_KEY',
|
1072
|
+
'event': 'Ordered Product',
|
1073
|
+
'customer_properties': {
|
1074
|
+
'$email': 'abraham.lincoln@klaviyo.com'
|
1075
|
+
},
|
1076
|
+
'properties': {
|
1077
|
+
'item_name': 'Boots',
|
1078
|
+
'$value': 100
|
1079
|
+
}
|
1080
|
+
}
|
1081
|
+
|
1082
|
+
encoded_payload = Base64.encode64(track_payload.to_json).encode(Encoding::UTF_8)
|
1083
|
+
response = Client::TrackIdentify.track_get(encoded_payload)
|
1084
|
+
```
|
1085
|
+
|
1086
|
+
|
1087
|
+
|
1088
|
+
|
1089
|
+
#### [Track Profile Activity](https://developers.klaviyo.com/en/reference/track-post)
|
1090
|
+
|
1091
|
+
```ruby
|
1092
|
+
Client::TrackIdentify.track_post(data)
|
1093
|
+
```
|
1094
|
+
|
1095
|
+
#### Example:
|
1096
|
+
```ruby
|
1097
|
+
|
1098
|
+
track_payload = {
|
1099
|
+
'token': 'PUBLIC_KEY',
|
1100
|
+
'event': 'Ordered Product',
|
1101
|
+
'customer_properties': {
|
1102
|
+
'$email': 'abraham.lincoln@klaviyo.com'
|
1103
|
+
},
|
1104
|
+
'properties': {
|
1105
|
+
'item_name': 'Boots',
|
1106
|
+
'$value': 100
|
1107
|
+
}
|
1108
|
+
}
|
1109
|
+
|
1110
|
+
data = track_payload.to_json
|
1111
|
+
response = Client::TrackIdentify.track_post(data)
|
1112
|
+
```
|
1113
|
+
|
1114
|
+
|
1115
|
+
|
1116
|
+
|
1117
|
+
# Appendix
|
1118
|
+
|
1119
|
+
## Limitations
|
1120
|
+
|
1121
|
+
- The `api_key` is set at the global level: this means that if you manage multiple stores, you will need to run the code for each store in a different environment.
|