sendgrid_api/
single_sends.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct SingleSends {
5    pub client: Client,
6}
7
8impl SingleSends {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        SingleSends { client }
12    }
13
14    /**
15     * Get All Single Sends.
16     *
17     * This function performs a `GET` to the `/marketing/singlesends` endpoint.
18     *
19     * **This endpoint allows you to retrieve all your Single Sends.**
20     *
21     * Returns all of your Single Sends with condensed details about each, including the Single Sends' IDs. For more details about an individual Single Send, pass the Single Send's ID to the `/marketing/singlesends/{id}` endpoint.
22     *
23     * **Parameters:**
24     *
25     * * `page_size: i64`
26     * * `page_token: &str` -- The license key provided with your New Relic account.
27     */
28    pub async fn get_marketing_singlesends(
29        &self,
30        page_size: i64,
31        page_token: &str,
32    ) -> ClientResult<crate::Response<crate::types::GetMarketingSinglesendsResponse>> {
33        let mut query_args: Vec<(String, String)> = Default::default();
34        if page_size > 0 {
35            query_args.push(("page_size".to_string(), page_size.to_string()));
36        }
37        if !page_token.is_empty() {
38            query_args.push(("page_token".to_string(), page_token.to_string()));
39        }
40        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
41        let url = self
42            .client
43            .url(&format!("/marketing/singlesends?{}", query_), None);
44        self.client
45            .get(
46                &url,
47                crate::Message {
48                    body: None,
49                    content_type: None,
50                },
51            )
52            .await
53    }
54    /**
55     * Create Single Send.
56     *
57     * This function performs a `POST` to the `/marketing/singlesends` endpoint.
58     *
59     * **This endpoint allows you to create a new Single Send.**
60     *
61     * Please note that if you are migrating from the previous version of Single Sends, you no longer need to pass a template ID with your request to this endpoint. Instead, you will pass all template data in the `email_config` object.
62     */
63    pub async fn post_marketing_singlesend(
64        &self,
65        body: &crate::types::SinglesendRequest,
66    ) -> ClientResult<crate::Response<crate::types::SinglesendResponseAllOf>> {
67        let url = self.client.url("/marketing/singlesends", None);
68        self.client
69            .post(
70                &url,
71                crate::Message {
72                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
73                    content_type: None,
74                },
75            )
76            .await
77    }
78    /**
79     * Bulk Delete Single Sends.
80     *
81     * This function performs a `DELETE` to the `/marketing/singlesends` endpoint.
82     *
83     * **This endpoint allows you to delete multiple Single Sends using an array of Single Sends IDs.**
84     *
85     * To first retrieve all your Single Sends' IDs, you can make a GET request to the `/marketing/singlensends` endpoint.
86     *
87     * Please note that a DELETE request is permanent, and your Single Sends will not be recoverable after deletion.
88     *
89     * **Parameters:**
90     *
91     * * `ids: &[String]` -- The recipient IDs of the recipients that already existed from this request.
92     */
93    pub async fn delete_marketing_singlesends(
94        &self,
95        ids: &[String],
96    ) -> ClientResult<crate::Response<()>> {
97        let mut query_args: Vec<(String, String)> = Default::default();
98        if !ids.is_empty() {
99            query_args.push(("ids".to_string(), ids.join(" ")));
100        }
101        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
102        let url = self
103            .client
104            .url(&format!("/marketing/singlesends?{}", query_), None);
105        self.client
106            .delete(
107                &url,
108                crate::Message {
109                    body: None,
110                    content_type: None,
111                },
112            )
113            .await
114    }
115    /**
116     * Get Single Send by ID.
117     *
118     * This function performs a `GET` to the `/marketing/singlesends/{id}` endpoint.
119     *
120     * **This endpoint allows you to retrieve details about one Single Send using a Single Send ID.**
121     *
122     * You can retrieve all of your Single Sends by making a GET request to the `/marketing/singlesends` endpoint.
123     */
124    pub async fn get_marketing_singlesend(
125        &self,
126        id: &str,
127    ) -> ClientResult<crate::Response<crate::types::SinglesendResponseAllOf>> {
128        let url = self.client.url(
129            &format!(
130                "/marketing/singlesends/{}",
131                crate::progenitor_support::encode_path(id),
132            ),
133            None,
134        );
135        self.client
136            .get(
137                &url,
138                crate::Message {
139                    body: None,
140                    content_type: None,
141                },
142            )
143            .await
144    }
145    /**
146     * Duplicate Single Send.
147     *
148     * This function performs a `POST` to the `/marketing/singlesends/{id}` endpoint.
149     *
150     * **This endpoint allows you to duplicate an existing Single Send using its Single Send ID.**
151     *
152     * Duplicating a Single Send is useful when you want to create a Single Send but don't want to start from scratch. Once duplicated, you can update or edit the Single Send by making a PATCH request to the `/marketing/singlesends/{id}` endpoint.
153     *  
154     * If you leave the `name` field blank, your duplicate will be assigned the name of the Single Send it was copied from with the text “Copy of ” prepended to it. The `name` field length is limited to 100 characters, so the end of the new Single Send name, including “Copy of ”, will be trimmed if the name exceeds this limit.
155     */
156    pub async fn post_marketing_singlesend_single_sends(
157        &self,
158        id: &str,
159        body: &crate::types::PostMarketingSinglesendsRequest,
160    ) -> ClientResult<crate::Response<crate::types::SinglesendResponseAllOf>> {
161        let url = self.client.url(
162            &format!(
163                "/marketing/singlesends/{}",
164                crate::progenitor_support::encode_path(id),
165            ),
166            None,
167        );
168        self.client
169            .post(
170                &url,
171                crate::Message {
172                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
173                    content_type: Some("application/json".to_string()),
174                },
175            )
176            .await
177    }
178    /**
179     * Delete Single Send by ID.
180     *
181     * This function performs a `DELETE` to the `/marketing/singlesends/{id}` endpoint.
182     *
183     * **This endpoint allows you to delete one Single Send using a Single Send ID.**
184     *
185     * To first retrieve all your Single Sends' IDs, you can make a GET request to the `/marketing/singlensends` endpoint.
186     *
187     * Please note that a `DELETE` request is permanent, and your Single Send will not be recoverable after deletion.
188     */
189    pub async fn delete_marketing_singlesends_single_sends(
190        &self,
191        id: &str,
192    ) -> ClientResult<crate::Response<()>> {
193        let url = self.client.url(
194            &format!(
195                "/marketing/singlesends/{}",
196                crate::progenitor_support::encode_path(id),
197            ),
198            None,
199        );
200        self.client
201            .delete(
202                &url,
203                crate::Message {
204                    body: None,
205                    content_type: None,
206                },
207            )
208            .await
209    }
210    /**
211     * Update Single Send.
212     *
213     * This function performs a `PATCH` to the `/marketing/singlesends/{id}` endpoint.
214     *
215     * **This endpoint allows you to update a Single Send using a Single Send ID.**
216     *
217     * You only need to pass the fields you want to update. Any blank/missing fields will remain unaltered.
218     */
219    pub async fn patch_marketing_singlesends(
220        &self,
221        id: &str,
222        body: &crate::types::SinglesendRequest,
223    ) -> ClientResult<crate::Response<crate::types::SinglesendResponseAllOf>> {
224        let url = self.client.url(
225            &format!(
226                "/marketing/singlesends/{}",
227                crate::progenitor_support::encode_path(id),
228            ),
229            None,
230        );
231        self.client
232            .patch(
233                &url,
234                crate::Message {
235                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
236                    content_type: None,
237                },
238            )
239            .await
240    }
241    /**
242     * Get Single Sends Search.
243     *
244     * This function performs a `POST` to the `/marketing/singlesends/search` endpoint.
245     *
246     * **This endpoint allows you to search for Single Sends based on specified criteria.**
247     *
248     * You can search for Single Sends by passing a combination of values using the `name`, `status`, and `categories` request body fields.
249     *
250     * For example, if you want to search for all Single Sends that are "drafts" or "scheduled" and also associated with the category "shoes," your request body may look like the example below.
251     *
252     * ```javascript
253     * {
254     *   "status": [
255     *     "draft",
256     *     "scheduled"
257     *   ],
258     *   "categories": [
259     *     "shoes"
260     *   ],
261     * }
262     * ```
263     *
264     * **Parameters:**
265     *
266     * * `page_size: i64`
267     * * `page_token: &str` -- The license key provided with your New Relic account.
268     */
269    pub async fn post_marketing_singlesends_search(
270        &self,
271        page_size: i64,
272        page_token: &str,
273        body: &crate::types::SinglesendSearch,
274    ) -> ClientResult<crate::Response<crate::types::GetMarketingSinglesendsResponse>> {
275        let mut query_args: Vec<(String, String)> = Default::default();
276        if page_size > 0 {
277            query_args.push(("page_size".to_string(), page_size.to_string()));
278        }
279        if !page_token.is_empty() {
280            query_args.push(("page_token".to_string(), page_token.to_string()));
281        }
282        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
283        let url = self
284            .client
285            .url(&format!("/marketing/singlesends/search?{}", query_), None);
286        self.client
287            .post(
288                &url,
289                crate::Message {
290                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
291                    content_type: Some("application/json".to_string()),
292                },
293            )
294            .await
295    }
296    /**
297     * Schedule Single Send.
298     *
299     * This function performs a `PUT` to the `/marketing/singlesends/{id}/schedule` endpoint.
300     *
301     * **This endpoint allows you to schedule a Single Send for future delivery using a Single Send ID.**
302     *
303     * To schedule a Single Send, you must pass a date string in ISO 8601 time format (yyyy-MM-ddTHH:mm:ssZ)  using the required `send_at` field. For example, the ISO 8601 format for 9:00 AM UTC on May 6, 2020 would be `2020-05-06T09:00:00Z`. You may also pass the string `"now"` to send the Single Send immediately.
304     */
305    pub async fn put_marketing_singlesends_schedule(
306        &self,
307        id: &str,
308        body: &crate::types::PutMarketingSinglesendsScheduleRequest,
309    ) -> ClientResult<crate::Response<crate::types::PutMarketingSinglesendsScheduleResponse>> {
310        let url = self.client.url(
311            &format!(
312                "/marketing/singlesends/{}/schedule",
313                crate::progenitor_support::encode_path(id),
314            ),
315            None,
316        );
317        self.client
318            .put(
319                &url,
320                crate::Message {
321                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
322                    content_type: Some("application/json".to_string()),
323                },
324            )
325            .await
326    }
327    /**
328     * Delete Single Send Schedule.
329     *
330     * This function performs a `DELETE` to the `/marketing/singlesends/{id}/schedule` endpoint.
331     *
332     * **This endpoint allows you to cancel a scheduled Single Send using a Single Send ID.**
333     *
334     * Making a DELETE request to this endpoint will cancel the scheduled sending of a Single Send. The request will not delete the Single Send itself. Deleting a Single Send can be done by passing a DELETE request to `/marketing/singlesends/{id}`.
335     */
336    pub async fn delete_marketing_singlesends_schedule(
337        &self,
338        id: &str,
339    ) -> ClientResult<crate::Response<crate::types::SinglesendSchedule>> {
340        let url = self.client.url(
341            &format!(
342                "/marketing/singlesends/{}/schedule",
343                crate::progenitor_support::encode_path(id),
344            ),
345            None,
346        );
347        self.client
348            .delete(
349                &url,
350                crate::Message {
351                    body: None,
352                    content_type: None,
353                },
354            )
355            .await
356    }
357    /**
358     * Get All Categories.
359     *
360     * This function performs a `GET` to the `/marketing/singlesends/categories` endpoint.
361     *
362     * **This endpoint allows you to retrieve all the categories associated with your Single Sends.**
363     *
364     * This endpoint will return your latest 1,000 categories.
365     */
366    pub async fn get_marketing_singlesends_categories(
367        &self,
368    ) -> ClientResult<crate::Response<crate::types::GetMarketingSinglesendsCategoriesResponse>>
369    {
370        let url = self.client.url("/marketing/singlesends/categories", None);
371        self.client
372            .get(
373                &url,
374                crate::Message {
375                    body: None,
376                    content_type: None,
377                },
378            )
379            .await
380    }
381}