sendgrid_api/
cancel_scheduled_sends.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct CancelScheduledSends {
5    pub client: Client,
6}
7
8impl CancelScheduledSends {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        CancelScheduledSends { client }
12    }
13
14    /**
15     * Create a batch ID.
16     *
17     * This function performs a `POST` to the `/mail/batch` endpoint.
18     *
19     * **This endpoint allows you to generate a new batch ID.**
20     *
21     * Once a `batch_id` is created, you can associate it with a scheduled send using the `/mail/send` endpoint. Passing the `batch_id` as a field in the `/mail/send` request body will assign the ID to the send you are creating.
22     *
23     * Once an ID is associated with a scheduled send, the send can be accessed and its send status can be modified using the `batch_id`.
24     *
25     * **Parameters:**
26     *
27     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
28     */
29    pub async fn post_mail_batch(
30        &self,
31    ) -> ClientResult<crate::Response<crate::types::MailBatchId>> {
32        let url = self.client.url("/mail/batch", None);
33        self.client
34            .post(
35                &url,
36                crate::Message {
37                    body: None,
38                    content_type: None,
39                },
40            )
41            .await
42    }
43    /**
44     * Retrieve all scheduled sends.
45     *
46     * This function performs a `GET` to the `/user/scheduled_sends` endpoint.
47     *
48     * **This endpoint allows you to retrieve all cancelled and paused scheduled send information.**
49     *
50     * This endpoint will return only the scheduled sends that are associated with a `batch_id`. If you have scheduled a send using the `/mail/send` endpoint and the `send_at` field but no `batch_id`, the send will be scheduled for delivery; however, it will not be returned by this endpoint. For this reason, you should assign a `batch_id` to any scheduled send you may need to pause or cancel in the future.
51     *
52     * **Parameters:**
53     *
54     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
55     */
56    pub async fn get_user_scheduled_sends(
57        &self,
58    ) -> ClientResult<crate::Response<Vec<crate::types::UserScheduledSendStatusAllOf>>> {
59        let url = self.client.url("/user/scheduled_sends", None);
60        self.client
61            .get(
62                &url,
63                crate::Message {
64                    body: None,
65                    content_type: None,
66                },
67            )
68            .await
69    }
70    /**
71     * Retrieve all scheduled sends.
72     *
73     * This function performs a `GET` to the `/user/scheduled_sends` endpoint.
74     *
75     * As opposed to `get_user_scheduled_sends`, this function returns all the pages of the request at once.
76     *
77     * **This endpoint allows you to retrieve all cancelled and paused scheduled send information.**
78     *
79     * This endpoint will return only the scheduled sends that are associated with a `batch_id`. If you have scheduled a send using the `/mail/send` endpoint and the `send_at` field but no `batch_id`, the send will be scheduled for delivery; however, it will not be returned by this endpoint. For this reason, you should assign a `batch_id` to any scheduled send you may need to pause or cancel in the future.
80     */
81    pub async fn get_all_user_scheduled_sends(
82        &self,
83    ) -> ClientResult<crate::Response<Vec<crate::types::UserScheduledSendStatusAllOf>>> {
84        let url = self.client.url("/user/scheduled_sends", None);
85        self.client
86            .get_all_pages(
87                &url,
88                crate::Message {
89                    body: None,
90                    content_type: None,
91                },
92            )
93            .await
94    }
95    /**
96     * Cancel or pause a scheduled send.
97     *
98     * This function performs a `POST` to the `/user/scheduled_sends` endpoint.
99     *
100     * **This endpoint allows you to cancel or pause a scheduled send associated with a `batch_id`.**
101     *
102     * Passing this endpoint a `batch_id` and status will cancel or pause the scheduled send.
103     *
104     * Once a scheduled send is set to `pause` or `cancel` you must use the "Update a scheduled send" endpoint to change its status or the "Delete a cancellation or pause from a scheduled send" endpoint to remove the status. Passing a status change to a scheduled send that has already been paused or cancelled will result in a `400` level status code.
105     *
106     * If the maximum number of cancellations/pauses are added to a send, a `400` level status code will be returned.
107     *
108     * **Parameters:**
109     *
110     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
111     */
112    pub async fn post_user_scheduled_send(
113        &self,
114        body: &crate::types::CancelPauseAScheduledSendRequest,
115    ) -> ClientResult<crate::Response<crate::types::UserScheduledSendStatusAllOf>> {
116        let url = self.client.url("/user/scheduled_sends", None);
117        self.client
118            .post(
119                &url,
120                crate::Message {
121                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
122                    content_type: Some("application/json".to_string()),
123                },
124            )
125            .await
126    }
127    /**
128     * Validate batch ID.
129     *
130     * This function performs a `GET` to the `/mail/batch/{batch_id}` endpoint.
131     *
132     * **This endpoint allows you to validate a batch ID.**
133     *
134     * When you pass a valid `batch_id` to this endpoint, it will return a `200` status code and the batch ID itself.
135     *
136     * If you pass an invalid `batch_id` to the endpoint, you will receive a `400` level status code and an error message.
137     *
138     * A `batch_id` does not need to be assigned to a scheduled send to be considered valid. A successful response means only that the `batch_id` has been created, but it does not indicate that it has been associated with a send.
139     *
140     * **Parameters:**
141     *
142     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
143     */
144    pub async fn get_mail_batch(
145        &self,
146        batch_id: &str,
147    ) -> ClientResult<crate::Response<crate::types::MailBatchId>> {
148        let url = self.client.url(
149            &format!(
150                "/mail/batch/{}",
151                crate::progenitor_support::encode_path(batch_id),
152            ),
153            None,
154        );
155        self.client
156            .get(
157                &url,
158                crate::Message {
159                    body: None,
160                    content_type: None,
161                },
162            )
163            .await
164    }
165    /**
166     * Retrieve scheduled send.
167     *
168     * This function performs a `GET` to the `/user/scheduled_sends/{batch_id}` endpoint.
169     *
170     * **This endpoint allows you to retrieve the cancel/paused scheduled send information for a specific `batch_id`.**
171     *
172     * **Parameters:**
173     *
174     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
175     */
176    pub async fn get_user_scheduled_sends_batch(
177        &self,
178        batch_id: &str,
179    ) -> ClientResult<crate::Response<Vec<crate::types::UserScheduledSendStatusAllOf>>> {
180        let url = self.client.url(
181            &format!(
182                "/user/scheduled_sends/{}",
183                crate::progenitor_support::encode_path(batch_id),
184            ),
185            None,
186        );
187        self.client
188            .get(
189                &url,
190                crate::Message {
191                    body: None,
192                    content_type: None,
193                },
194            )
195            .await
196    }
197    /**
198     * Retrieve scheduled send.
199     *
200     * This function performs a `GET` to the `/user/scheduled_sends/{batch_id}` endpoint.
201     *
202     * As opposed to `get_user_scheduled_sends_batch`, this function returns all the pages of the request at once.
203     *
204     * **This endpoint allows you to retrieve the cancel/paused scheduled send information for a specific `batch_id`.**
205     */
206    pub async fn get_all_user_scheduled_sends_batch(
207        &self,
208        batch_id: &str,
209    ) -> ClientResult<crate::Response<Vec<crate::types::UserScheduledSendStatusAllOf>>> {
210        let url = self.client.url(
211            &format!(
212                "/user/scheduled_sends/{}",
213                crate::progenitor_support::encode_path(batch_id),
214            ),
215            None,
216        );
217        self.client
218            .get_all_pages(
219                &url,
220                crate::Message {
221                    body: None,
222                    content_type: None,
223                },
224            )
225            .await
226    }
227    /**
228     * Delete a cancellation or pause from a scheduled send.
229     *
230     * This function performs a `DELETE` to the `/user/scheduled_sends/{batch_id}` endpoint.
231     *
232     * **This endpoint allows you to delete the cancellation/pause of a scheduled send.**
233     *
234     * Scheduled sends cancelled less than 10 minutes before the scheduled time are not guaranteed to be cancelled.
235     *
236     * **Parameters:**
237     *
238     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
239     */
240    pub async fn delete_user_scheduled_sends_batch(
241        &self,
242        batch_id: &str,
243    ) -> ClientResult<crate::Response<()>> {
244        let url = self.client.url(
245            &format!(
246                "/user/scheduled_sends/{}",
247                crate::progenitor_support::encode_path(batch_id),
248            ),
249            None,
250        );
251        self.client
252            .delete(
253                &url,
254                crate::Message {
255                    body: None,
256                    content_type: None,
257                },
258            )
259            .await
260    }
261    /**
262     * Update a scheduled send.
263     *
264     * This function performs a `PATCH` to the `/user/scheduled_sends/{batch_id}` endpoint.
265     *
266     * **This endpoint allows you to update the status of a scheduled send for the given `batch_id`.**
267     *
268     * If you have already set a `cancel` or `pause` status on a scheduled send using the "Cancel or pause a scheduled send" endpoint, you can update it's status using this endpoint. Attempting to update a status once it has been set with the "Cancel or pause a scheduled send" endpoint will result in a `400` error.
269     *
270     * **Parameters:**
271     *
272     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
273     */
274    pub async fn patch_user_scheduled_sends_batch(
275        &self,
276        batch_id: &str,
277        body: &crate::types::UserScheduledSendStatus,
278    ) -> ClientResult<crate::Response<()>> {
279        let url = self.client.url(
280            &format!(
281                "/user/scheduled_sends/{}",
282                crate::progenitor_support::encode_path(batch_id),
283            ),
284            None,
285        );
286        self.client
287            .patch(
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}