sendgrid_api/contacts_api_recipients.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct ContactsApiRecipients {
5 pub client: Client,
6}
7
8impl ContactsApiRecipients {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 ContactsApiRecipients { client }
12 }
13
14 /**
15 * Retrieve recipients.
16 *
17 * This function performs a `GET` to the `/contactdb/recipients` endpoint.
18 *
19 * **This endpoint allows you to retrieve all of your Marketing Campaigns recipients.**
20 *
21 * Batch deletion of a page makes it possible to receive an empty page of recipients before reaching the end of
22 * the list of recipients. To avoid this issue; iterate over pages until a 404 is retrieved.
23 *
24 * **Parameters:**
25 *
26 * * `page: i64` -- Page index of first recipients to return (must be a positive integer).
27 * * `page_size: i64` -- Number of recipients to return at a time (must be a positive integer between 1 and 1000).
28 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
29 */
30 pub async fn get_contactdb_recipients(
31 &self,
32 page: i64,
33 page_size: i64,
34 ) -> ClientResult<crate::Response<crate::types::ListRecipientsResponse>> {
35 let mut query_args: Vec<(String, String)> = Default::default();
36 if page > 0 {
37 query_args.push(("page".to_string(), page.to_string()));
38 }
39 if page_size > 0 {
40 query_args.push(("page_size".to_string(), page_size.to_string()));
41 }
42 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
43 let url = self
44 .client
45 .url(&format!("/contactdb/recipients?{}", query_), None);
46 self.client
47 .get(
48 &url,
49 crate::Message {
50 body: None,
51 content_type: None,
52 },
53 )
54 .await
55 }
56 /**
57 * Add recipients.
58 *
59 * This function performs a `POST` to the `/contactdb/recipients` endpoint.
60 *
61 * **This endpoint allows you to add a Marketing Campaigns recipient.**
62 *
63 * You can add custom field data as a parameter on this endpoint. We have provided an example using some of the default custom fields SendGrid provides.
64 *
65 * The rate limit is three requests every 2 seconds. You can upload 1000 contacts per request. So the maximum upload rate is 1500 recipients per second.
66 *
67 * **Parameters:**
68 *
69 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
70 */
71 pub async fn post_contactdb_recipient(
72 &self,
73 body: &[crate::types::PostContactdbRecipientsRequest],
74 ) -> ClientResult<crate::Response<crate::types::ContactDbRecipientResponse>> {
75 let url = self.client.url("/contactdb/recipients", None);
76 self.client
77 .post(
78 &url,
79 crate::Message {
80 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
81 content_type: Some("application/json".to_string()),
82 },
83 )
84 .await
85 }
86 /**
87 * Delete Recipients.
88 *
89 * This function performs a `DELETE` to the `/contactdb/recipients` endpoint.
90 *
91 * **This endpoint allows you to deletes one or more recipients.**
92 *
93 * The body of an API call to this endpoint must include an array of recipient IDs of the recipients you want to delete.
94 *
95 * **Parameters:**
96 *
97 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
98 */
99 pub async fn delete_contactdb_recipients(
100 &self,
101 body: &[String],
102 ) -> ClientResult<crate::Response<crate::types::Help>> {
103 let url = self.client.url("/contactdb/recipients", None);
104 self.client
105 .delete(
106 &url,
107 crate::Message {
108 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
109 content_type: Some("application/json".to_string()),
110 },
111 )
112 .await
113 }
114 /**
115 * Update Recipient.
116 *
117 * This function performs a `PATCH` to the `/contactdb/recipients` endpoint.
118 *
119 * **This endpoint allows you to update one or more recipients.**
120 *
121 * The body of an API call to this endpoint must include an array of one or more recipient objects.
122 *
123 * It is of note that you can add custom field data as parameters on recipient objects. We have provided an example using some of the default custom fields SendGrid provides.
124 *
125 * **Parameters:**
126 *
127 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
128 */
129 pub async fn patch_contactdb_recipients(
130 &self,
131 body: &[crate::types::PatchContactdbRecipientsRequest],
132 ) -> ClientResult<crate::Response<crate::types::ContactDbRecipientResponse>> {
133 let url = self.client.url("/contactdb/recipients", None);
134 self.client
135 .patch(
136 &url,
137 crate::Message {
138 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
139 content_type: Some("application/json".to_string()),
140 },
141 )
142 .await
143 }
144 /**
145 * Get Recipient Upload Status.
146 *
147 * This function performs a `GET` to the `/contactdb/status` endpoint.
148 *
149 * **This endpoint allows you to check the upload status of a Marketing Campaigns recipient.**
150 *
151 * **Parameters:**
152 *
153 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
154 */
155 pub async fn get_contactdb_statu(
156 &self,
157 ) -> ClientResult<crate::Response<crate::types::GetContactdbStatusResponseData>> {
158 let url = self.client.url("/contactdb/status", None);
159 self.client
160 .get(
161 &url,
162 crate::Message {
163 body: None,
164 content_type: None,
165 },
166 )
167 .await
168 }
169 /**
170 * Retrieve a single recipient.
171 *
172 * This function performs a `GET` to the `/contactdb/recipients/{recipient_id}` endpoint.
173 *
174 * **This endpoint allows you to retrieve a single recipient by ID from your contact database.**
175 *
176 * **Parameters:**
177 *
178 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
179 */
180 pub async fn get_contactdb_recipients_recipient(
181 &self,
182 recipient_id: &str,
183 ) -> ClientResult<crate::Response<crate::types::ContactdbRecipient>> {
184 let url = self.client.url(
185 &format!(
186 "/contactdb/recipients/{}",
187 crate::progenitor_support::encode_path(recipient_id),
188 ),
189 None,
190 );
191 self.client
192 .get(
193 &url,
194 crate::Message {
195 body: None,
196 content_type: None,
197 },
198 )
199 .await
200 }
201 /**
202 * Delete a Recipient.
203 *
204 * This function performs a `DELETE` to the `/contactdb/recipients/{recipient_id}` endpoint.
205 *
206 * **This endpoint allows you to delete a single recipient with the given ID from your contact database.**
207 *
208 * > Use this to permanently delete your recipients from all of your contact lists and all segments if required by applicable law.
209 *
210 * **Parameters:**
211 *
212 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
213 */
214 pub async fn delete_contactdb_recipients_recipient(
215 &self,
216 recipient_id: &str,
217 ) -> ClientResult<crate::Response<crate::types::Help>> {
218 let url = self.client.url(
219 &format!(
220 "/contactdb/recipients/{}",
221 crate::progenitor_support::encode_path(recipient_id),
222 ),
223 None,
224 );
225 self.client
226 .delete(
227 &url,
228 crate::Message {
229 body: None,
230 content_type: None,
231 },
232 )
233 .await
234 }
235 /**
236 * Retrieve the lists that a recipient is on.
237 *
238 * This function performs a `GET` to the `/contactdb/recipients/{recipient_id}/lists` endpoint.
239 *
240 * **This endpoint allows you to retrieve the lists that a given recipient belongs to.**
241 *
242 * Each recipient can be on many lists. This endpoint gives you all of the lists that any one recipient has been added to.
243 *
244 * **Parameters:**
245 *
246 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
247 */
248 pub async fn get_contactdb_recipients_recipient_lists(
249 &self,
250 recipient_id: &str,
251 ) -> ClientResult<crate::Response<crate::types::GetContactdbRecipientsRecipientListsResponse>>
252 {
253 let url = self.client.url(
254 &format!(
255 "/contactdb/recipients/{}/lists",
256 crate::progenitor_support::encode_path(recipient_id),
257 ),
258 None,
259 );
260 self.client
261 .get(
262 &url,
263 crate::Message {
264 body: None,
265 content_type: None,
266 },
267 )
268 .await
269 }
270 /**
271 * Retrieve the count of billable recipients.
272 *
273 * This function performs a `GET` to the `/contactdb/recipients/billable_count` endpoint.
274 *
275 * **This endpoint allows you to retrieve the number of Marketing Campaigns recipients that you will be billed for.**
276 *
277 * You are billed for marketing campaigns based on the highest number of recipients you have had in your account at one time. This endpoint will allow you to know the current billable count value.
278 *
279 * **Parameters:**
280 *
281 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
282 */
283 pub async fn get_contactdb_recipients_billable_count(
284 &self,
285 ) -> ClientResult<crate::Response<crate::types::ContactdbRecipientCount>> {
286 let url = self
287 .client
288 .url("/contactdb/recipients/billable_count", None);
289 self.client
290 .get(
291 &url,
292 crate::Message {
293 body: None,
294 content_type: None,
295 },
296 )
297 .await
298 }
299 /**
300 * Retrieve a Count of Recipients.
301 *
302 * This function performs a `GET` to the `/contactdb/recipients/count` endpoint.
303 *
304 * **This endpoint allows you to retrieve the total number of Marketing Campaigns recipients.**
305 *
306 * **Parameters:**
307 *
308 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
309 */
310 pub async fn get_contactdb_recipients_count(
311 &self,
312 ) -> ClientResult<crate::Response<crate::types::ContactdbRecipientCount>> {
313 let url = self.client.url("/contactdb/recipients/count", None);
314 self.client
315 .get(
316 &url,
317 crate::Message {
318 body: None,
319 content_type: None,
320 },
321 )
322 .await
323 }
324 /**
325 * Search recipients.
326 *
327 * This function performs a `GET` to the `/contactdb/recipients/search` endpoint.
328 *
329 * **This endpoint allows you to perform a search on all of your Marketing Campaigns recipients.**
330 *
331 * field_name:
332 *
333 * * is a variable that is substituted for your actual custom field name from your recipient.
334 * * Text fields must be url-encoded. Date fields are searchable only by unix timestamp (e.g. 2/2/2015 becomes 1422835200)
335 * * If field_name is a 'reserved' date field, such as created_at or updated_at, the system will internally convert
336 * your epoch time to a date range encompassing the entire day. For example, an epoch time of 1422835600 converts to
337 * Mon, 02 Feb 2015 00:06:40 GMT, but internally the system will search from Mon, 02 Feb 2015 00:00:00 GMT through
338 * Mon, 02 Feb 2015 23:59:59 GMT.
339 *
340 * **Parameters:**
341 *
342 * * `field_name: &str` -- The license key provided with your New Relic account.
343 * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
344 */
345 pub async fn get_contactdb_recipients_search(
346 &self,
347 field_name: &str,
348 ) -> ClientResult<crate::Response<crate::types::GetContactdbRecipientsSearchResponse>> {
349 let mut query_args: Vec<(String, String)> = Default::default();
350 if !field_name.is_empty() {
351 query_args.push(("{field_name}".to_string(), field_name.to_string()));
352 }
353 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
354 let url = self
355 .client
356 .url(&format!("/contactdb/recipients/search?{}", query_), None);
357 self.client
358 .get(
359 &url,
360 crate::Message {
361 body: None,
362 content_type: None,
363 },
364 )
365 .await
366 }
367 /**
368 * Search recipients.
369 *
370 * This function performs a `POST` to the `/contactdb/recipients/search` endpoint.
371 *
372 * <p>
373 * Search using segment conditions without actually creating a segment.
374 * Body contains a JSON object with <code>conditions</code>, a list of conditions as described below, and an optional <code>list_id</code>, which is a valid list ID for a list to limit the search on.
375 * </p>
376 *
377 * <p>
378 * Valid operators for create and update depend on the type of the field for which you are searching.
379 * </p>
380 *
381 * <ul>
382 * <li>Dates:
383 * <ul>
384 * <li>"eq", "ne", "lt" (before), "gt" (after)
385 * <ul>
386 * <li>You may use MM/DD/YYYY for day granularity or an epoch for second granularity.</li>
387 * </ul>
388 * </li>
389 * <li>"empty", "not_empty"</li>
390 * <li>"is within"
391 * <ul>
392 * <li>You may use an <a href="https://en.wikipedia.org/wiki/ISO_8601">ISO 8601 date format</a> or the # of days.</li>
393 * </ul>
394 * </li>
395 * </ul>
396 * </li>
397 * <li>Text: "contains", "eq" (is - matches the full field), "ne" (is not - matches any field where the entire field is not the condition value), "empty", "not_empty"</li>
398 * <li>Numbers: "eq", "lt", "gt", "empty", "not_empty"</li>
399 * <li>Email Clicks and Opens: "eq" (opened), "ne" (not opened)</li>
400 * </ul>
401 *
402 * <p>
403 * Field values must all be a string.
404 * </p>
405 *
406 * <p>
407 * Search conditions using "eq" or "ne" for email clicks and opens should provide a "field" of either <code>clicks.campaign_identifier</code> or <code>opens.campaign_identifier</code>.
408 * The condition value should be a string containing the id of a completed campaign.
409 * </p>
410 *
411 * <p>
412 * Search conditions list may contain multiple conditions, joined by an "and" or "or" in the "and_or" field.
413 * The first condition in the conditions list must have an empty "and_or", and subsequent conditions must all specify an "and_or".
414 * </p>
415 */
416 pub async fn post_contactdb_recipients_search(
417 &self,
418 body: &crate::types::PostContactdbRecipientsSearchRequest,
419 ) -> ClientResult<crate::Response<crate::types::PostContactdbRecipientsSearchResponseData>>
420 {
421 let url = self.client.url("/contactdb/recipients/search", None);
422 self.client
423 .post(
424 &url,
425 crate::Message {
426 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
427 content_type: Some("application/json".to_string()),
428 },
429 )
430 .await
431 }
432}