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
use crate::api::*;
use crate::{ApiError, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
use reqwest::Method;
pub struct EventClient {
pub http_client: HttpClient,
}
impl EventClient {
pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
Ok(Self {
http_client: HttpClient::new(config.clone())?,
})
}
/// <Note>
/// This endpoint currently only supports custom events.
/// </Note>
///
/// Retrieve a list of events filtered by various criteria.
///
/// # Arguments
///
/// * `contact_id` - Filter by contact ID (repeatable)
/// * `event_name` - Filter by event name (repeatable)
/// * `object_type` - Filter by object type (repeatable)
/// * `start_date` - Mandatory if endDate is used. Start of date range (YYYY-MM-DD or RFC3339). Defaults to 6 months ago when omitted alongside endDate. Must be ≤ endDate.
/// * `end_date` - Mandatory if startDate is used. End of date range (YYYY-MM-DD or RFC3339). Must be ≥ startDate.
/// * `limit` - Max events to return. Default 100, min 1, max 10000.
/// * `offset` - Events to skip for pagination. Default 0, min 0.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use brevo_rust::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<value>".to_string()),
/// ..Default::default()
/// };
/// let client = BrevoClient::new(config).expect("Failed to build client");
/// client
/// .event
/// .get_events(
/// &GetEventsQueryRequest {
/// contact_id: vec![],
/// event_name: vec![],
/// object_type: vec![],
/// start_date: None,
/// end_date: None,
/// limit: None,
/// offset: None,
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn get_events(
&self,
request: &GetEventsQueryRequest,
options: Option<RequestOptions>,
) -> Result<GetEventsList, ApiError> {
self.http_client
.execute_request(
Method::GET,
"events",
None,
QueryBuilder::new()
.int_array("contact_id", request.contact_id.clone())
.string_array("event_name", request.event_name.clone())
.string_array("object_type", request.object_type.clone())
.string("startDate", request.start_date.clone())
.string("endDate", request.end_date.clone())
.int("limit", request.limit.clone())
.int("offset", request.offset.clone())
.build(),
options,
)
.await
}
/// Create an event to track a contact's interaction. Events created with this endpoint are stored as custom events, including events named `cart_updated`, `cart_deleted` or `order_completed`, so they don't trigger ecommerce automations such as abandoned cart. To send ecommerce cart events, activate the ecommerce app and use the Brevo tracker or the [trackEvent endpoint](/docs/track-custom-events-rest).
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// Empty response
///
/// # Examples
///
/// ```no_run
/// use brevo_rust::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<value>".to_string()),
/// ..Default::default()
/// };
/// let client = BrevoClient::new(config).expect("Failed to build client");
/// client
/// .event
/// .create_event(
/// &CreateEventRequest {
/// event_name: "video_played".to_string(),
/// identifiers: CreateEventRequestIdentifiers {
/// ..Default::default()
/// },
/// contact_properties: None,
/// event_date: None,
/// event_properties: None,
/// object: None,
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn create_event(
&self,
request: &CreateEventRequest,
options: Option<RequestOptions>,
) -> Result<(), ApiError> {
self.http_client
.execute_request(
Method::POST,
"events",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Create multiple events to track contacts' interactions in a single request. Events created with this endpoint are stored as custom events, including events named `cart_updated`, `cart_deleted` or `order_completed`, so they don't trigger ecommerce automations such as abandoned cart. To send ecommerce cart events, activate the ecommerce app and use the Brevo tracker or the [trackEvent endpoint](/docs/track-custom-events-rest).
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use brevo_rust::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<value>".to_string()),
/// ..Default::default()
/// };
/// let client = BrevoClient::new(config).expect("Failed to build client");
/// client
/// .event
/// .create_batch_events(
/// &CreateBatchEventsRequest {
/// events: vec![CreateBatchEventsRequestEventsItem {
/// event_name: "order_created".to_string(),
/// identifiers: CreateBatchEventsRequestEventsItemIdentifiers {
/// ..Default::default()
/// },
/// ..Default::default()
/// }],
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn create_batch_events(
&self,
request: &CreateBatchEventsRequest,
options: Option<RequestOptions>,
) -> Result<BatchAcceptedResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"events/batch",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
}