Timeline event operations
Operations on individual properties
- class TimelineEventOperation
- __init__(event_type_id, strategy, event_id=None, source=None, date_time=None, identifier=None)
This class represents a
BlueConic timeline event operation
. Do note that the date_time is optional. When using SET, the date will be now when left empty. When using UPSERT/UPDATE and it’s left empty, all events with the given event ID and event type ID are updated, thus having an impact on the number of data operations.- Parameters:
event_type_id (str) – The event type ID
strategy (blueconic.domain.TimelineStrategy) – Strategy for this operation
event_id (Optional[str]) – The event ID
source (Optional[str]) – The source of the timeline event (only used when using SET, ignored otherwise)
date_time (Optional[Union[date, datetime, str]]) – Datetime of the event (if not passed, all events matching the ID and event type ID are affected)
identifier (Optional[str]) – An external identifier which can be passed along with timeline event operation and is returned in the response
- Usage:
>>> import blueconic >>> # Create a TimelineEventOperation which will be executed on an event with and id "abandoned_basket_2" >>> timeline_operation = blueconic.TimelineEventOperation( >>> "abandoned_basket", blueconic.TimelineStrategy.UPSERT, event_id="abandoned_basket_2" >>> )
- add_rule(property_id, values, strategy=None)
Add rule to apply on the timeline event.
- Parameters:
property_id (str) – The timeline event property ID to apply the rule on
values (Union[str, int, float, date, datetime, TimelineNestedItemOperation, Sequence]) – List of values or TimelineNestedItemOperation instances
strategy (Union[Strategy, TimelineStrategy]) – The strategy to apply (TimelineStrategy when using TimelineNestedItemOperation, Strategy otherwise)
- Usage:
>>> import blueconic >>> bc = blueconic.Client() >>> # Create ProfileOperation which will be executed on profile with given profile_id >>> profile_operation = blueconic.ProfileOperation(profile_id="29b138e2-9824-45c3-ace6-909ee308ceb1") >>> >>> # Create a TimelineEventOperation which will be executed on an event with and id "abandoned_basket_2" >>> timeline_operation = blueconic.TimelineEventOperation( >>> "abandoned_basket", blueconic.TimelineStrategy.UPSERT, event_id="abandoned_basket_2" >>> ) >>> >>> # Create TimelineNestedItemOperation where identifier property is "id" with value "987644321" >>> nested_property_operation = blueconic.TimelineNestedItemOperation("id", "987644321") >>> nested_property_operation.add_rule("quantity", 100, blueconic.Strategy.SET) >>> >>> # There is a root level property "product", add nested-properties to it >>> timeline_operation.add_rule("product", nested_property_operation, blueconic.TimelineStrategy.UPSERT) >>> >>> # There is a root level property "product", delete the product with id "567898" from it >>> delete_product_operation = blueconic.TimelineNestedItemOperation("id", "567898") >>> timeline_operation.add_rule("product", delete_product_operation, blueconic.TimelineStrategy.DELETE) >>> >>> # Add the timeline_operation to profile_operation >>> profile_operation.add_timeline_operation(timeline_operation) >>> >>> # Save the updated property through profile bulkhandler >>> with bc.get_profile_bulkhandler() as bh: >>> bh.write(profile_operation)
- property date_time
- Returns:
Returns the datetime of the event.
- Return type:
Optional[Date]
- property event_id
- Returns:
Returns the event id.
- Return type:
Optional[str]
- property event_type_id
- Returns:
Returns the event type id.
- Return type:
- property identifier
- Returns:
Returns the external identifier of the timeline event.
- Return type:
Optional[str]
- property rules
- Returns:
Returns the rules to apply on the timeline event.
- Return type:
List[Dict[str, Any]]
- property source
- Returns:
Returns the source of the timeline event.
- Return type:
Optional[str]
- property strategy
- Returns:
Returns the timeline event operation strategy.
- Return type:
Operation on nested items
- class TimelineNestedItemOperation
- __init__(identifier_property_id=None, value=None)
This class represents a
BlueConic timeline nested operation
.- Parameters:
- Usage:
>>> import blueconic >>> bc = blueconic.Client() >>> >>> # Create TimelineNestedItemOperation where identifier property is "id" with value "987644321" >>> blueconic.TimelineNestedItemOperation("id", "987644321")
- add_rule(property_id, values, strategy=None)
Add rule to apply on the timeline event.
- Parameters:
property_id (str) – The timeline event property ID to apply the rule on
values (Union[str, int, float, date, datetime, TimelineNestedItemOperation, Sequence]) – List of values or TimelineNestedItemOperation instances
strategy (Union[Strategy, TimelineStrategy]) – The strategy to apply (TimelineStrategy when using TimelineNestedItemOperation, Strategy otherwise)
- Usage:
>>> import blueconic >>> bc = blueconic.Client() >>> # Create ProfileOperation which will be executed on profile with given profile_id >>> profile_operation = blueconic.ProfileOperation(profile_id="29b138e2-9824-45c3-ace6-909ee308ceb1") >>> >>> # Create a TimelineEventOperation which will be executed on an event with and id "abandoned_basket_2" >>> timeline_operation = blueconic.TimelineEventOperation( >>> "abandoned_basket", blueconic.TimelineStrategy.UPSERT, event_id="abandoned_basket_2" >>> ) >>> >>> # Create TimelineNestedItemOperation where identifier property is "id" with value "987644321" >>> nested_property_operation = blueconic.TimelineNestedItemOperation("id", "987644321") >>> nested_property_operation.add_rule("quantity", 100, blueconic.Strategy.SET) >>> >>> # There is a root level property "product", add nested-properties to it >>> timeline_operation.add_rule("product", nested_property_operation, blueconic.TimelineStrategy.UPSERT) >>> >>> # There is a root level property "product", delete the product with id "567898" from it >>> delete_product_operation = blueconic.TimelineNestedItemOperation("id", "567898") >>> timeline_operation.add_rule("product", delete_product_operation, blueconic.TimelineStrategy.DELETE) >>> >>> # Add the timeline_operation to profile_operation >>> profile_operation.add_timeline_operation(timeline_operation) >>> >>> # Save the updated property through profile bulkhandler >>> with bc.get_profile_bulkhandler() as bh: >>> bh.write(profile_operation)
- property date_time
- Returns:
Returns the datetime of the event.
- Return type:
Optional[Date]
- property event_id
- Returns:
Returns the event id.
- Return type:
Optional[str]
- property event_type_id
- Returns:
Returns the event type id.
- Return type:
- property identifier
- Returns:
Returns the external identifier of the timeline event.
- Return type:
Optional[str]
- property identifier_property_id
- Returns:
Returns the identifier property for the nested timeline event (e.g. productID in products).
- Return type:
Optional[str]
- property rules
- Returns:
Returns the rules to apply on the nested timeline event operation.
- Return type:
List[Dict[str, Any]]
- property source
- Returns:
Returns the source of the timeline event.
- Return type:
Optional[str]
- property strategy
- Returns:
Returns the timeline event operation strategy.
- Return type:
TimelineStrategy
- class TimelineStrategy
This enumeration defines all possible strategies for timeline events. This defines the strategy for the entire event and nested properties of a timeline event (not for the individual timeline event properties).
- SET:
Default. Indicates an upsert for the timeline event. If the event already exists it is overwritten (updated), otherwise inserted. The strategy set on individual properties will be ignored.
- UPSERT:
Indicates a partial update (upsert). If the event is not found it is equal to a SET, otherwise the strategy set on individual properties will determine how the update is performed.
- UPDATE:
Indicates a partial update. If the event is not found, nothing will happen, otherwise the strategy set on individual properties will determine how the update is performed.
- DELETE:
Indicates a delete. Will delete the given event or item in a nested property.