Class: Klaviyo::ProfilesApi

Inherits:
Object
  • Object
show all
Defined in:
lib/klaviyo_sdk/api/profiles_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ ProfilesApi

Returns a new instance of ProfilesApi.



19
20
21
# File 'lib/klaviyo_sdk/api/profiles_api.rb', line 19

def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



17
18
19
# File 'lib/klaviyo_sdk/api/profiles_api.rb', line 17

def api_client
  @api_client
end

Instance Method Details

#exchange(opts = {}) ⇒ Hash<String, Object>

Exchange ID for Profile ID Klaviyo’s web tracking uses an encrypted identifier. However, there are many use cases that require developers to have access to a given profile’s email or phone number. In such cases, developers can use this operation to exchange an encrypted identifier for a profile ID, which they can then use to retrieve the full profile data (by making a subsequent request to the ‘get-profiles` operation). The `exchange_id` takes the following form: `<IDENTIFIER>.<COMPANY_ID>` The `exchange_id` appears in the url as follows: `?_kx=<IDENTIFIER>.<COMPANY_ID>`

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Hash<String, Object>)


27
28
29
30
# File 'lib/klaviyo_sdk/api/profiles_api.rb', line 27

def exchange(opts = {})
  data, _status_code, _headers = exchange_with_http_info(opts)
  data
end

#exchange_with_http_info(opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)>

Exchange ID for Profile ID Klaviyo&#39;s web tracking uses an encrypted identifier. However, there are many use cases that require developers to have access to a given profile&#39;s email or phone number. In such cases, developers can use this operation to exchange an encrypted identifier for a profile ID, which they can then use to retrieve the full profile data (by making a subsequent request to the &#x60;get-profiles&#x60; operation). The &#x60;exchange_id&#x60; takes the following form: &#x60;&lt;IDENTIFIER&gt;.&lt;COMPANY_ID&gt;&#x60; The &#x60;exchange_id&#x60; appears in the url as follows: &#x60;?_kx&#x3D;&lt;IDENTIFIER&gt;.&lt;COMPANY_ID&gt;&#x60;

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Array<(Hash<String, Object>, Integer, Hash)>)

    Hash<String, Object> data, response status code and response headers



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
# File 'lib/klaviyo_sdk/api/profiles_api.rb', line 37

def exchange_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: ProfilesApi.exchange ...'
  end
  # resource path
  local_var_path = '/v2/people/exchange'

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:body] || @api_client.object_to_http_body(opts[:'inline_object'])

  # return_type
  return_type = opts[:debug_return_type] || 'Hash<String, Object>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']

  new_options = opts.merge(
    :operation => :"ProfilesApi.exchange",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: ProfilesApi#exchange\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#get_profile(person_id, opts = {}) ⇒ Person

Get Profile Retrieves all the data attributes for a person, based on the Klaviyo Person ID.

Parameters:

  • person_id (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



91
92
93
94
# File 'lib/klaviyo_sdk/api/profiles_api.rb', line 91

def get_profile(person_id, opts = {})
  data, _status_code, _headers = get_profile_with_http_info(person_id, opts)
  data
end

#get_profile_with_http_info(person_id, opts = {}) ⇒ Array<(Person, Integer, Hash)>

Get Profile Retrieves all the data attributes for a person, based on the Klaviyo Person ID.

Parameters:

  • person_id (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(Person, Integer, Hash)>)

    Person data, response status code and response headers



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
# File 'lib/klaviyo_sdk/api/profiles_api.rb', line 101

def get_profile_with_http_info(person_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: ProfilesApi.get_profile ...'
  end
  # verify the required parameter 'person_id' is set
  if @api_client.config.client_side_validation && person_id.nil?
    fail ArgumentError, "Missing the required parameter 'person_id' when calling ProfilesApi.get_profile"
  end
  # resource path
  local_var_path = '/v1/person/{person_id}'.sub('{' + 'person_id' + '}', CGI.escape(person_id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:body]

  # return_type
  return_type = opts[:debug_return_type] || 'Person'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']

  new_options = opts.merge(
    :operation => :"ProfilesApi.get_profile",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: ProfilesApi#get_profile\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#profile_metric_timeline(person_id, metric_id, opts = {}) ⇒ MetricTimeline

Get Profile’s Events for a Specific Metric Returns a person’s batched timeline for one specific event type.

Parameters:

  • person_id (String)
  • metric_id (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :since (String)

    Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time.

  • :count (Integer)

    Number of events to return in a batch. (default to 50)

  • :sort (String)

    Sort order to apply to timeline, either descending or ascending. Valid values are &#x60;desc&#x60; or &#x60;asc&#x60;. Defaults to &#x60;desc&#x60;. (default to ‘desc’)

Returns:



158
159
160
161
# File 'lib/klaviyo_sdk/api/profiles_api.rb', line 158

def profile_metric_timeline(person_id, metric_id, opts = {})
  data, _status_code, _headers = profile_metric_timeline_with_http_info(person_id, metric_id, opts)
  data
end

#profile_metric_timeline_with_http_info(person_id, metric_id, opts = {}) ⇒ Array<(MetricTimeline, Integer, Hash)>

Get Profile&#39;s Events for a Specific Metric Returns a person&#39;s batched timeline for one specific event type.

Parameters:

  • person_id (String)
  • metric_id (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :since (String)

    Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time.

  • :count (Integer)

    Number of events to return in a batch.

  • :sort (String)

    Sort order to apply to timeline, either descending or ascending. Valid values are &#x60;desc&#x60; or &#x60;asc&#x60;. Defaults to &#x60;desc&#x60;.

Returns:

  • (Array<(MetricTimeline, Integer, Hash)>)

    MetricTimeline data, response status code and response headers



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
# File 'lib/klaviyo_sdk/api/profiles_api.rb', line 172

def profile_metric_timeline_with_http_info(person_id, metric_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: ProfilesApi.profile_metric_timeline ...'
  end
  # verify the required parameter 'person_id' is set
  if @api_client.config.client_side_validation && person_id.nil?
    fail ArgumentError, "Missing the required parameter 'person_id' when calling ProfilesApi.profile_metric_timeline"
  end
  # verify the required parameter 'metric_id' is set
  if @api_client.config.client_side_validation && metric_id.nil?
    fail ArgumentError, "Missing the required parameter 'metric_id' when calling ProfilesApi.profile_metric_timeline"
  end
  if @api_client.config.client_side_validation && !opts[:'count'].nil? && opts[:'count'] > 100
    fail ArgumentError, 'invalid value for "opts[:"count"]" when calling ProfilesApi.profile_metric_timeline, must be smaller than or equal to 100.'
  end

  if @api_client.config.client_side_validation && !opts[:'count'].nil? && opts[:'count'] < 1
    fail ArgumentError, 'invalid value for "opts[:"count"]" when calling ProfilesApi.profile_metric_timeline, must be greater than or equal to 1.'
  end

  # resource path
  local_var_path = '/v1/person/{person_id}/metric/{metric_id}/timeline'.sub('{' + 'person_id' + '}', CGI.escape(person_id.to_s)).sub('{' + 'metric_id' + '}', CGI.escape(metric_id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'since'] = opts[:'since'] if !opts[:'since'].nil?
  query_params[:'count'] = opts[:'count'] if !opts[:'count'].nil?
  query_params[:'sort'] = opts[:'sort'] if !opts[:'sort'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:body]

  # return_type
  return_type = opts[:debug_return_type] || 'MetricTimeline'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']

  new_options = opts.merge(
    :operation => :"ProfilesApi.profile_metric_timeline",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: ProfilesApi#profile_metric_timeline\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#profile_metrics_timeline(person_id, opts = {}) ⇒ MetricTimeline

Get Profile’s Events for all Metrics Returns a batched timeline of all events for a person.

Parameters:

  • person_id (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :since (String)

    Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time.

  • :count (Integer)

    Number of events to return in a batch. Default &#x3D; 50, Max &#x3D; 100 (default to 50)

  • :sort (String)

    Sort order to apply to timeline, either descending or ascending. Valid values are &#x60;desc&#x60; or &#x60;asc&#x60;. Defaults to &#x60;desc&#x60;. Always descending when &#x60;since&#x60; is not sent, as &#x60;since&#x60; defaults to current time. (default to ‘desc’)

Returns:



243
244
245
246
# File 'lib/klaviyo_sdk/api/profiles_api.rb', line 243

def profile_metrics_timeline(person_id, opts = {})
  data, _status_code, _headers = profile_metrics_timeline_with_http_info(person_id, opts)
  data
end

#profile_metrics_timeline_with_http_info(person_id, opts = {}) ⇒ Array<(MetricTimeline, Integer, Hash)>

Get Profile&#39;s Events for all Metrics Returns a batched timeline of all events for a person.

Parameters:

  • person_id (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :since (String)

    Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time.

  • :count (Integer)

    Number of events to return in a batch. Default &#x3D; 50, Max &#x3D; 100

  • :sort (String)

    Sort order to apply to timeline, either descending or ascending. Valid values are &#x60;desc&#x60; or &#x60;asc&#x60;. Defaults to &#x60;desc&#x60;. Always descending when &#x60;since&#x60; is not sent, as &#x60;since&#x60; defaults to current time.

Returns:

  • (Array<(MetricTimeline, Integer, Hash)>)

    MetricTimeline data, response status code and response headers



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
# File 'lib/klaviyo_sdk/api/profiles_api.rb', line 256

def profile_metrics_timeline_with_http_info(person_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: ProfilesApi.profile_metrics_timeline ...'
  end
  # verify the required parameter 'person_id' is set
  if @api_client.config.client_side_validation && person_id.nil?
    fail ArgumentError, "Missing the required parameter 'person_id' when calling ProfilesApi.profile_metrics_timeline"
  end
  if @api_client.config.client_side_validation && !opts[:'count'].nil? && opts[:'count'] > 100
    fail ArgumentError, 'invalid value for "opts[:"count"]" when calling ProfilesApi.profile_metrics_timeline, must be smaller than or equal to 100.'
  end

  if @api_client.config.client_side_validation && !opts[:'count'].nil? && opts[:'count'] < 1
    fail ArgumentError, 'invalid value for "opts[:"count"]" when calling ProfilesApi.profile_metrics_timeline, must be greater than or equal to 1.'
  end

  # resource path
  local_var_path = '/v1/person/{person_id}/metrics/timeline'.sub('{' + 'person_id' + '}', CGI.escape(person_id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'since'] = opts[:'since'] if !opts[:'since'].nil?
  query_params[:'count'] = opts[:'count'] if !opts[:'count'].nil?
  query_params[:'sort'] = opts[:'sort'] if !opts[:'sort'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:body]

  # return_type
  return_type = opts[:debug_return_type] || 'MetricTimeline'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']

  new_options = opts.merge(
    :operation => :"ProfilesApi.profile_metrics_timeline",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: ProfilesApi#profile_metrics_timeline\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#update_profile(person_id, opts = {}) ⇒ Person

Update Profile NOTE: If you are interested in creating or updating profiles in Klaviyo, you should be using the Identify API instead. The best use-case for this route is changing a profiles’s email address or other primary identifier after a profile already exists in Klaviyo. Add or update one more more attributes for a Person, based on the Klaviyo Person ID. If a property already exists, it will be updated. If a property is not set for that record, it will be created. You can update any attribute, by sending one or more attributes along their new values, as query parameters. Recommended attributes for this endpoint: ‘$email`, `$phone_number`, `$id`

Parameters:

  • person_id (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :params (Hash<String, Object>)

Returns:



321
322
323
324
# File 'lib/klaviyo_sdk/api/profiles_api.rb', line 321

def update_profile(person_id, opts = {})
  data, _status_code, _headers = update_profile_with_http_info(person_id, opts)
  data
end

#update_profile_with_http_info(person_id, opts = {}) ⇒ Array<(Person, Integer, Hash)>

Update Profile NOTE: If you are interested in creating or updating profiles in Klaviyo, you should be using the Identify API instead. The best use-case for this route is changing a profiles&#39;s email address or other primary identifier after a profile already exists in Klaviyo. Add or update one more more attributes for a Person, based on the Klaviyo Person ID. If a property already exists, it will be updated. If a property is not set for that record, it will be created. You can update any attribute, by sending one or more attributes along their new values, as query parameters. Recommended attributes for this endpoint: &#x60;$email&#x60;, &#x60;$phone_number&#x60;, &#x60;$id&#x60;

Parameters:

  • person_id (String)
  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :params (Hash<String, Object>)

Returns:

  • (Array<(Person, Integer, Hash)>)

    Person data, response status code and response headers



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
# File 'lib/klaviyo_sdk/api/profiles_api.rb', line 332

def update_profile_with_http_info(person_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: ProfilesApi.update_profile ...'
  end
  # verify the required parameter 'person_id' is set
  if @api_client.config.client_side_validation && person_id.nil?
    fail ArgumentError, "Missing the required parameter 'person_id' when calling ProfilesApi.update_profile"
  end
  # resource path
  local_var_path = '/v1/person/{person_id}'.sub('{' + 'person_id' + '}', CGI.escape(person_id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'params'] = opts[:'params'] if !opts[:'params'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json'])

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:body]

  # return_type
  return_type = opts[:debug_return_type] || 'Person'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['ApiKeyAuth']

  new_options = opts.merge(
    :operation => :"ProfilesApi.update_profile",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:PUT, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: ProfilesApi#update_profile\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end