# KlaviyoAPI::EventsApi All URIs are relative to *https://a.klaviyo.com* | Method | HTTP request | Description | | ------ | ------------ | ----------- | | [**create_event**](EventsApi.md#create_event) | **POST** /api/events/ | Create Event | | [**get_event**](EventsApi.md#get_event) | **GET** /api/events/{id}/ | Get Event | | [**get_event_metrics**](EventsApi.md#get_event_metrics) | **GET** /api/events/{id}/metrics/ | Get Event Metrics | | [**get_event_profiles**](EventsApi.md#get_event_profiles) | **GET** /api/events/{id}/profiles/ | Get Event Profiles | | [**get_event_relationships**](EventsApi.md#get_event_relationships) | **GET** /api/events/{id}/relationships/{related_resource}/ | Get Event Relationships | | [**get_events**](EventsApi.md#get_events) | **GET** /api/events/ | Get Events | ## create_event > create_event(event_create_query) Create Event Create an event. Events are created asynchronously. Successful response indicates that the event was validated and submitted for processing, but does not guarantee that processing is complete.

*Rate limits*:
Burst: `350/s`
Steady: `3500/m` **Scopes:** `Events Write` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::EventsApi.new event_create_query = KlaviyoAPI::EventCreateQuery.new({data: KlaviyoAPI::EventCreateQueryAsSubResource.new({type: 'event', attributes: KlaviyoAPI::EventCreateQueryAsSubResourceAttributes.new({profile: {"$email":"matt.kemp@klaviyo-demo.com"}, metric: KlaviyoAPI::MetricCreateQuery.new({name: 'Viewed Product'}), properties: {"Brand":"Kids Book","Categories":["Fiction","Children"],"ProductID":1111,"ProductName":"Winnie the Pooh","$extra":{"URL":"http://www.example.com/path/to/product","ImageURL":"http://www.example.com/path/to/product/image.png"}}})})}) # EventCreateQuery | Event to create. begin # Create Event api_instance.create_event(event_create_query) rescue KlaviyoAPI::ApiError => e puts "Error when calling EventsApi->create_event: #{e}" end ``` #### Using the create_event_with_http_info variant This returns an Array which contains the response data (`nil` in this case), status code and headers. > create_event_with_http_info(event_create_query) ```ruby begin # Create Event data, status_code, headers = api_instance.create_event_with_http_info(event_create_query) p status_code # => 2xx p headers # => { ... } p data # => nil rescue KlaviyoAPI::ApiError => e puts "Error when calling EventsApi->create_event_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **event_create_query** | [**EventCreateQuery**](EventCreateQuery.md) | Event to create. | | ### Return type nil (empty response body) ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: application/json - **Accept**: application/json ## get_event > Hash<String, Object> get_event(id, opts) Get Event Get an event with the given event ID. Include parameters can be provided to get the following related resource data: `metrics`, `profiles`

*Rate limits*:
Burst: `10/s`
Steady: `150/m` **Scopes:** `Events Read` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::EventsApi.new id = 'id_example' # String | ID of the event opts = { fields_event: ['metric_id'], # Array | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets fields_metric: ['name'], # Array | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets fields_profile: ['email'], # Array | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets include: ['metrics'] # Array | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#relationships } begin # Get Event result = api_instance.get_event(id, opts) p result rescue KlaviyoAPI::ApiError => e puts "Error when calling EventsApi->get_event: #{e}" end ``` #### Using the get_event_with_http_info variant This returns an Array which contains the response data, status code and headers. > get_event_with_http_info(id, opts) ```ruby begin # Get Event data, status_code, headers = api_instance.get_event_with_http_info(id, opts) p status_code # => 2xx p headers # => { ... } p data # => Hash<String, Object> rescue KlaviyoAPI::ApiError => e puts "Error when calling EventsApi->get_event_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **id** | **String** | ID of the event | | | **fields_event** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets | [optional] | | **fields_metric** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets | [optional] | | **fields_profile** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets | [optional] | | **include** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#relationships | [optional] | ### Return type **Hash<String, Object>** ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/json ## get_event_metrics > Hash<String, Object> get_event_metrics(id, opts) Get Event Metrics Get the metric for an event with the given event ID.

*Rate limits*:
Burst: `350/s`
Steady: `3500/m` **Scopes:** `Events Read` `Metrics Read` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::EventsApi.new id = 'id_example' # String | ID of the event opts = { fields_metric: ['name'] # Array | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets } begin # Get Event Metrics result = api_instance.get_event_metrics(id, opts) p result rescue KlaviyoAPI::ApiError => e puts "Error when calling EventsApi->get_event_metrics: #{e}" end ``` #### Using the get_event_metrics_with_http_info variant This returns an Array which contains the response data, status code and headers. > get_event_metrics_with_http_info(id, opts) ```ruby begin # Get Event Metrics data, status_code, headers = api_instance.get_event_metrics_with_http_info(id, opts) p status_code # => 2xx p headers # => { ... } p data # => Hash<String, Object> rescue KlaviyoAPI::ApiError => e puts "Error when calling EventsApi->get_event_metrics_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **id** | **String** | ID of the event | | | **fields_metric** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets | [optional] | ### Return type **Hash<String, Object>** ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/json ## get_event_profiles > Hash<String, Object> get_event_profiles(id, opts) Get Event Profiles Get the profile associated with an event with the given event ID.

*Rate limits*:
Burst: `350/s`
Steady: `3500/m` **Scopes:** `Events Read` `Profiles Read` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::EventsApi.new id = 'id_example' # String | ID of the event opts = { fields_profile: ['email'] # Array | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets } begin # Get Event Profiles result = api_instance.get_event_profiles(id, opts) p result rescue KlaviyoAPI::ApiError => e puts "Error when calling EventsApi->get_event_profiles: #{e}" end ``` #### Using the get_event_profiles_with_http_info variant This returns an Array which contains the response data, status code and headers. > get_event_profiles_with_http_info(id, opts) ```ruby begin # Get Event Profiles data, status_code, headers = api_instance.get_event_profiles_with_http_info(id, opts) p status_code # => 2xx p headers # => { ... } p data # => Hash<String, Object> rescue KlaviyoAPI::ApiError => e puts "Error when calling EventsApi->get_event_profiles_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **id** | **String** | ID of the event | | | **fields_profile** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets | [optional] | ### Return type **Hash<String, Object>** ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/json ## get_event_relationships > Hash<String, Object> get_event_relationships(id, related_resource) Get Event Relationships Get metrics or profile [relationships](https://developers.klaviyo.com/en/reference/api_overview#relationships) for an event with the given event ID.

*Rate limits*:
Burst: `350/s`
Steady: `3500/m` **Scopes:** `Events Read` `Metrics Read` `Profiles Read` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::EventsApi.new id = 'id_example' # String | related_resource = 'metrics' # String | begin # Get Event Relationships result = api_instance.get_event_relationships(id, related_resource) p result rescue KlaviyoAPI::ApiError => e puts "Error when calling EventsApi->get_event_relationships: #{e}" end ``` #### Using the get_event_relationships_with_http_info variant This returns an Array which contains the response data, status code and headers. > get_event_relationships_with_http_info(id, related_resource) ```ruby begin # Get Event Relationships data, status_code, headers = api_instance.get_event_relationships_with_http_info(id, related_resource) p status_code # => 2xx p headers # => { ... } p data # => Hash<String, Object> rescue KlaviyoAPI::ApiError => e puts "Error when calling EventsApi->get_event_relationships_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **id** | **String** | | | | **related_resource** | **String** | | | ### Return type **Hash<String, Object>** ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/json ## get_events > Hash<String, Object> get_events(opts) Get Events Get all events in an account Requests can be sorted by the following fields: `datetime`, `timestamp` Include parameters can be provided to get the following related resource data: `metrics`, `profiles` Returns a maximum of 200 events per page.

*Rate limits*:
Burst: `350/s`
Steady: `3500/m` **Scopes:** `Events Read` ### Examples ```ruby require 'time' require 'klaviyo-api-sdk' # setup authorization KlaviyoAPI.configure do |config| # Configure API key authorization: Klaviyo-API-Key config.api_key['Klaviyo-API-Key'] = 'YOUR API KEY' # Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil) # config.api_key_prefix['Klaviyo-API-Key'] = 'Bearer' end api_instance = KlaviyoAPI::EventsApi.new opts = { fields_event: ['metric_id'], # Array | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets fields_metric: ['name'], # Array | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets fields_profile: ['email'], # Array | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets filter: 'filter_example', # String | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#filtering
Allowed field(s)/operator(s):
`metric_id`: `equals`
`datetime`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`
`timestamp`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than` include: ['metrics'], # Array | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#relationships page_cursor: 'page_cursor_example', # String | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#pagination sort: 'datetime' # String | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sorting } begin # Get Events result = api_instance.get_events(opts) p result rescue KlaviyoAPI::ApiError => e puts "Error when calling EventsApi->get_events: #{e}" end ``` #### Using the get_events_with_http_info variant This returns an Array which contains the response data, status code and headers. > get_events_with_http_info(opts) ```ruby begin # Get Events data, status_code, headers = api_instance.get_events_with_http_info(opts) p status_code # => 2xx p headers # => { ... } p data # => Hash<String, Object> rescue KlaviyoAPI::ApiError => e puts "Error when calling EventsApi->get_events_with_http_info: #{e}" end ``` ### Parameters | Name | Type | Description | Notes | | ---- | ---- | ----------- | ----- | | **fields_event** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets | [optional] | | **fields_metric** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets | [optional] | | **fields_profile** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sparse-fieldsets | [optional] | | **filter** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#filtering<br>Allowed field(s)/operator(s):<br>`metric_id`: `equals`<br>`datetime`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than`<br>`timestamp`: `greater-or-equal`, `greater-than`, `less-or-equal`, `less-than` | [optional] | | **include** | [**Array<String>**](String.md) | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#relationships | [optional] | | **page_cursor** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#pagination | [optional] | | **sort** | **String** | For more information please visit https://developers.klaviyo.com/en/v2023-02-22/reference/api-overview#sorting | [optional] | ### Return type **Hash<String, Object>** ### Authorization [Klaviyo-API-Key](../README.md#Klaviyo-API-Key) ### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/json