Skip to main content

loops_so/generated/
client.rs

1//!
2//! AUTO-GENERATED CODE - DO NOT EDIT!
3//!
4//! Loops OpenAPI Spec
5//! Source: target/openapi.normalized.json
6//! Version: 1.22.6
7//! Generated by `oas3-gen v0.28.0`
8//!
9//! This is the OpenAPI Spec for the [Loops API](https://loops.so/docs/api).
10
11use super::types::*;
12use anyhow::Context;
13use reqwest::{Client, Url};
14use validator::Validate;
15pub const BASE_URL: &str = "https://app.loops.so/api";
16#[derive(Debug, Clone)]
17pub struct LoopsOpenApiSpecClient {
18    pub client: Client,
19    pub base_url: Url,
20}
21impl Default for LoopsOpenApiSpecClient {
22    fn default() -> Self {
23        Self::new()
24    }
25}
26impl LoopsOpenApiSpecClient {
27    /// Create a client using the OpenAPI `servers[0]` URL.
28    #[must_use]
29    #[track_caller]
30    pub fn new() -> Self {
31        Self {
32            client: Client::builder().build().expect("client"),
33            base_url: Url::parse(BASE_URL).expect("valid base url"),
34        }
35    }
36    /// Create a client with a custom base URL.
37    pub fn with_base_url(base_url: impl AsRef<str>) -> anyhow::Result<Self> {
38        Ok(Self {
39            client: Client::builder()
40                .build()
41                .context("building reqwest client")?,
42            base_url: Url::parse(base_url.as_ref()).context("parsing base url")?,
43        })
44    }
45    /// Create a client from an existing `reqwest::Client`.
46    pub fn with_client(base_url: impl AsRef<str>, client: Client) -> anyhow::Result<Self> {
47        let url = Url::parse(base_url.as_ref()).context("parsing base url")?;
48        Ok(Self {
49            client,
50            base_url: url,
51        })
52    }
53    /// API key
54    ///
55    /// Test your API key and get team context.
56    ///
57    /// * Path: `GET /v1/api-key`
58    pub async fn test_api_key(
59        &self,
60        request: TestApiKeyRequest,
61    ) -> anyhow::Result<TestApiKeyResponse> {
62        request.validate().context("parameter validation")?;
63        let mut url = self.base_url.clone();
64        url.path_segments_mut()
65            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
66            .push("v1")
67            .push("api-key");
68        let response = self.client.get(url).send().await?;
69        Ok(TestApiKeyRequest::parse_response(response).await?)
70    }
71    /// Get an audience segment
72    ///
73    /// Retrieve a single audience segment by ID.
74    ///
75    /// * Path: `GET /v1/audience-segments/{audienceSegmentId}`
76    pub async fn get_audience_segment(
77        &self,
78        request: GetAudienceSegmentRequest,
79    ) -> anyhow::Result<GetAudienceSegmentResponse> {
80        request.validate().context("parameter validation")?;
81        let mut url = self.base_url.clone();
82        url.path_segments_mut()
83            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
84            .push("v1")
85            .push("audience-segments")
86            .push(&request.path.audience_segment_id.to_string());
87        let response = self.client.get(url).send().await?;
88        Ok(GetAudienceSegmentRequest::parse_response(response).await?)
89    }
90    /// List audience segments
91    ///
92    /// Retrieve a paginated list of audience segments, most recently created first.
93    ///
94    /// * Path: `GET /v1/audience-segments`
95    pub async fn list_audience_segments(
96        &self,
97        request: ListAudienceSegmentsRequest,
98    ) -> anyhow::Result<ListAudienceSegmentsResponseEnum> {
99        request.validate().context("parameter validation")?;
100        let mut url = self.base_url.clone();
101        url.path_segments_mut()
102            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
103            .push("v1")
104            .push("audience-segments");
105        let response = self.client.get(url).query(&request.query).send().await?;
106        Ok(ListAudienceSegmentsRequest::parse_response(response).await?)
107    }
108    /// Create an audience segment
109    ///
110    /// Create a new audience segment.
111    ///
112    /// * Path: `POST /v1/audience-segments`
113    pub async fn create_audience_segment(
114        &self,
115        request: CreateAudienceSegmentRequestParams,
116    ) -> anyhow::Result<GetAudienceSegmentResponse> {
117        request.validate().context("parameter validation")?;
118        let mut url = self.base_url.clone();
119        url.path_segments_mut()
120            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
121            .push("v1")
122            .push("audience-segments");
123        let response = self.client.post(url).json(&request.body).send().await?;
124        Ok(CreateAudienceSegmentRequestParams::parse_response(response).await?)
125    }
126    /// List campaigns
127    ///
128    /// Retrieve a paginated list of campaigns.
129    ///
130    /// * Path: `GET /v1/campaigns`
131    pub async fn list_campaigns(
132        &self,
133        request: ListCampaignsRequest,
134    ) -> anyhow::Result<ListCampaignsResponseEnum> {
135        request.validate().context("parameter validation")?;
136        let mut url = self.base_url.clone();
137        url.path_segments_mut()
138            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
139            .push("v1")
140            .push("campaigns");
141        let response = self.client.get(url).query(&request.query).send().await?;
142        Ok(ListCampaignsRequest::parse_response(response).await?)
143    }
144    /// Create a campaign
145    ///
146    /// Create a new draft campaign. An empty email message is created automatically and its `emailMessageId` is returned. Use the `/email-messages/{emailMessageId}` endpoint to set subject, sender, preview text, and LMX content. The audience (mailing list, segment, or filter), group, and scheduling can be set on create or later via update.
147    ///
148    /// * Path: `POST /v1/campaigns`
149    pub async fn create_campaign(
150        &self,
151        request: CreateCampaignRequestParams,
152    ) -> anyhow::Result<CreateCampaignResponseEnum> {
153        request.validate().context("parameter validation")?;
154        let mut url = self.base_url.clone();
155        url.path_segments_mut()
156            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
157            .push("v1")
158            .push("campaigns");
159        let response = self.client.post(url).json(&request.body).send().await?;
160        Ok(CreateCampaignRequestParams::parse_response(response).await?)
161    }
162    /// Get a campaign
163    ///
164    /// Retrieve a single campaign by ID.
165    ///
166    /// * Path: `GET /v1/campaigns/{campaignId}`
167    pub async fn get_campaign(
168        &self,
169        request: GetCampaignRequest,
170    ) -> anyhow::Result<GetCampaignResponse> {
171        request.validate().context("parameter validation")?;
172        let mut url = self.base_url.clone();
173        url.path_segments_mut()
174            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
175            .push("v1")
176            .push("campaigns")
177            .push(&request.path.campaign_id.to_string());
178        let response = self.client.get(url).send().await?;
179        Ok(GetCampaignRequest::parse_response(response).await?)
180    }
181    /// Update a campaign
182    ///
183    /// Update a draft campaign's name, group, audience (mailing list, segment, or filter), or scheduling. At least one field must be provided. Once a campaign has been sent, only its `name` and `campaignGroupId` can be updated.
184    ///
185    /// * Path: `POST /v1/campaigns/{campaignId}`
186    pub async fn update_campaign(
187        &self,
188        request: UpdateCampaignRequestParams,
189    ) -> anyhow::Result<UpdateCampaignResponse> {
190        request.validate().context("parameter validation")?;
191        let mut url = self.base_url.clone();
192        url.path_segments_mut()
193            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
194            .push("v1")
195            .push("campaigns")
196            .push(&request.path.campaign_id.to_string());
197        let response = self.client.post(url).json(&request.body).send().await?;
198        Ok(UpdateCampaignRequestParams::parse_response(response).await?)
199    }
200    /// Get campaign metrics
201    ///
202    /// Retrieve all-time email engagement metrics for a campaign.
203    ///
204    /// * Path: `GET /v1/campaigns/{campaignId}/metrics`
205    pub async fn get_campaign_metrics(
206        &self,
207        request: GetCampaignMetricsRequest,
208    ) -> anyhow::Result<GetCampaignMetricsResponse> {
209        request.validate().context("parameter validation")?;
210        let mut url = self.base_url.clone();
211        url.path_segments_mut()
212            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
213            .push("v1")
214            .push("campaigns")
215            .push(&request.path.campaign_id.to_string())
216            .push("metrics");
217        let response = self.client.get(url).send().await?;
218        Ok(GetCampaignMetricsRequest::parse_response(response).await?)
219    }
220    /// List campaign groups
221    ///
222    /// Retrieve a paginated list of campaign groups, most recently created first.
223    ///
224    /// * Path: `GET /v1/campaign-groups`
225    pub async fn list_campaign_groups(
226        &self,
227        request: ListCampaignGroupsRequest,
228    ) -> anyhow::Result<ListCampaignGroupsResponse> {
229        request.validate().context("parameter validation")?;
230        let mut url = self.base_url.clone();
231        url.path_segments_mut()
232            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
233            .push("v1")
234            .push("campaign-groups");
235        let response = self.client.get(url).query(&request.query).send().await?;
236        Ok(ListCampaignGroupsRequest::parse_response(response).await?)
237    }
238    /// Create a campaign group
239    ///
240    /// Create a new campaign group.
241    ///
242    /// * Path: `POST /v1/campaign-groups`
243    pub async fn create_campaign_group(
244        &self,
245        request: CreateCampaignGroupRequest,
246    ) -> anyhow::Result<CreateCampaignGroupResponse> {
247        request.validate().context("parameter validation")?;
248        let mut url = self.base_url.clone();
249        url.path_segments_mut()
250            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
251            .push("v1")
252            .push("campaign-groups");
253        let response = self.client.post(url).json(&request.body).send().await?;
254        Ok(CreateCampaignGroupRequest::parse_response(response).await?)
255    }
256    /// Get a campaign group
257    ///
258    /// Retrieve a single campaign group by ID.
259    ///
260    /// * Path: `GET /v1/campaign-groups/{campaignGroupId}`
261    pub async fn get_campaign_group(
262        &self,
263        request: GetCampaignGroupRequest,
264    ) -> anyhow::Result<GetCampaignGroupResponse> {
265        request.validate().context("parameter validation")?;
266        let mut url = self.base_url.clone();
267        url.path_segments_mut()
268            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
269            .push("v1")
270            .push("campaign-groups")
271            .push(&request.path.campaign_group_id.to_string());
272        let response = self.client.get(url).send().await?;
273        Ok(GetCampaignGroupRequest::parse_response(response).await?)
274    }
275    /// Update a campaign group
276    ///
277    /// Update a campaign group's name or description. At least one field must be provided. The reserved "Unsorted" group cannot be edited.
278    ///
279    /// * Path: `POST /v1/campaign-groups/{campaignGroupId}`
280    pub async fn update_campaign_group(
281        &self,
282        request: UpdateCampaignGroupRequest,
283    ) -> anyhow::Result<GetCampaignGroupResponse> {
284        request.validate().context("parameter validation")?;
285        let mut url = self.base_url.clone();
286        url.path_segments_mut()
287            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
288            .push("v1")
289            .push("campaign-groups")
290            .push(&request.path.campaign_group_id.to_string());
291        let response = self.client.post(url).json(&request.body).send().await?;
292        Ok(UpdateCampaignGroupRequest::parse_response(response).await?)
293    }
294    /// List dedicated sending IP addresses
295    ///
296    /// Retrieve a list of Loops' dedicated sending IP addresses.
297    ///
298    /// This endpoint is provided for the rare instances where you may need to whitelist our sending IPs. Please note that this list is subject to change and will not include shared IPs used for sending mail.
299    ///
300    /// Unless you are sure you need this and are comfortable watching for changes, we strongly recommend you _do not_ whitelist these IPs.
301    ///
302    /// * Path: `GET /v1/dedicated-sending-ips`
303    pub async fn list_dedicated_sending_ips(
304        &self,
305        request: ListDedicatedSendingIpsRequest,
306    ) -> anyhow::Result<ListDedicatedSendingIpsResponse> {
307        request.validate().context("parameter validation")?;
308        let mut url = self.base_url.clone();
309        url.path_segments_mut()
310            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
311            .push("v1")
312            .push("dedicated-sending-ips");
313        let response = self.client.get(url).send().await?;
314        Ok(ListDedicatedSendingIpsRequest::parse_response(response).await?)
315    }
316    /// Create a contact
317    ///
318    /// Add a contact to your audience.
319    ///
320    /// * Path: `POST /v1/contacts/create`
321    pub async fn create_contact(
322        &self,
323        request: CreateContactRequest,
324    ) -> anyhow::Result<CreateContactResponse> {
325        request.validate().context("parameter validation")?;
326        let mut url = self.base_url.clone();
327        url.path_segments_mut()
328            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
329            .push("v1")
330            .push("contacts")
331            .push("create");
332        let response = self.client.post(url).json(&request.body).send().await?;
333        Ok(CreateContactRequest::parse_response(response).await?)
334    }
335    /// Update a contact
336    ///
337    /// Update a contact by `email` or `userId`. You must provide one of these parameters.
338    ///
339    /// If you want to update a contact's email address, the contact will first need a `userId` value. You can then make a request containing the `userId` field along with an updated email address.
340    ///
341    /// This endpoint will create a contact if a matching contact does not already exist in your audience.
342    ///
343    /// Provide either `email` or `userId` to identify the contact you want to update. If both are provided, the system will look for a contact with either a matching `email` or `userId` value. If a contact is found for one of the values (e.g. `email`), the other value (e.g. `userId`) will be updated. If a contact is not found, a new contact will be created using both `email` and `userId` values.
344    ///
345    /// * Path: `PUT /v1/contacts/update`
346    pub async fn update_contact(
347        &self,
348        request: UpdateContactRequest,
349    ) -> anyhow::Result<UpdateContactResponse> {
350        request.validate().context("parameter validation")?;
351        let mut url = self.base_url.clone();
352        url.path_segments_mut()
353            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
354            .push("v1")
355            .push("contacts")
356            .push("update");
357        let response = self.client.put(url).json(&request.body).send().await?;
358        Ok(UpdateContactRequest::parse_response(response).await?)
359    }
360    /// Find a contact
361    ///
362    /// Search for a contact by `email` or `userId`. Only one parameter is allowed.
363    ///
364    /// * Path: `GET /v1/contacts/find`
365    pub async fn find_contact(
366        &self,
367        request: FindContactRequest,
368    ) -> anyhow::Result<FindContactResponse> {
369        request.validate().context("parameter validation")?;
370        let mut url = self.base_url.clone();
371        url.path_segments_mut()
372            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
373            .push("v1")
374            .push("contacts")
375            .push("find");
376        let response = self.client.get(url).query(&request.query).send().await?;
377        Ok(FindContactRequest::parse_response(response).await?)
378    }
379    /// Delete a contact
380    ///
381    /// Delete a contact by `email` or `userId`.
382    ///
383    /// * Path: `POST /v1/contacts/delete`
384    pub async fn delete_contact(
385        &self,
386        request: DeleteContactRequest,
387    ) -> anyhow::Result<DeleteContactResponse> {
388        request.validate().context("parameter validation")?;
389        let mut url = self.base_url.clone();
390        url.path_segments_mut()
391            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
392            .push("v1")
393            .push("contacts")
394            .push("delete");
395        let response = self.client.post(url).json(&request.body).send().await?;
396        Ok(DeleteContactRequest::parse_response(response).await?)
397    }
398    /// Get suppression status for a contact
399    ///
400    /// Retrieve suppression status and removal quota for a contact by `email` or `userId`. Include only one query parameter.
401    ///
402    /// * Path: `GET /v1/contacts/suppression`
403    pub async fn get_contact_suppression(
404        &self,
405        request: GetContactSuppressionRequest,
406    ) -> anyhow::Result<GetContactSuppressionResponse> {
407        request.validate().context("parameter validation")?;
408        let mut url = self.base_url.clone();
409        url.path_segments_mut()
410            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
411            .push("v1")
412            .push("contacts")
413            .push("suppression");
414        let response = self.client.get(url).query(&request.query).send().await?;
415        Ok(GetContactSuppressionRequest::parse_response(response).await?)
416    }
417    /// Remove a contact from suppression list
418    ///
419    /// Remove a suppressed contact from the suppression list by `email` or `userId`. Include only one query parameter.
420    ///
421    /// * Path: `DELETE /v1/contacts/suppression`
422    pub async fn remove_contact_suppression(
423        &self,
424        request: RemoveContactSuppressionRequest,
425    ) -> anyhow::Result<RemoveContactSuppressionResponse> {
426        request.validate().context("parameter validation")?;
427        let mut url = self.base_url.clone();
428        url.path_segments_mut()
429            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
430            .push("v1")
431            .push("contacts")
432            .push("suppression");
433        let response = self.client.delete(url).query(&request.query).send().await?;
434        Ok(RemoveContactSuppressionRequest::parse_response(response).await?)
435    }
436    /// List contact properties
437    ///
438    /// Retrieve a list of your account's contact properties.<br>Use the `list` parameter to query "all" or "custom" properties.
439    ///
440    /// * Path: `GET /v1/contacts/properties`
441    pub async fn list_contact_properties(
442        &self,
443        request: ListContactPropertiesRequest,
444    ) -> anyhow::Result<ListContactPropertiesResponse> {
445        request.validate().context("parameter validation")?;
446        let mut url = self.base_url.clone();
447        url.path_segments_mut()
448            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
449            .push("v1")
450            .push("contacts")
451            .push("properties");
452        let response = self.client.get(url).query(&request.query).send().await?;
453        Ok(ListContactPropertiesRequest::parse_response(response).await?)
454    }
455    /// Create a contact property
456    ///
457    /// Create a custom contact property.
458    ///
459    /// * Path: `POST /v1/contacts/properties`
460    pub async fn create_contact_property(
461        &self,
462        request: CreateContactPropertyRequest,
463    ) -> anyhow::Result<CreateContactPropertyResponse> {
464        request.validate().context("parameter validation")?;
465        let mut url = self.base_url.clone();
466        url.path_segments_mut()
467            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
468            .push("v1")
469            .push("contacts")
470            .push("properties");
471        let response = self.client.post(url).json(&request.body).send().await?;
472        Ok(CreateContactPropertyRequest::parse_response(response).await?)
473    }
474    /// Get a component
475    ///
476    /// Retrieve a single component by ID.
477    ///
478    /// * Path: `GET /v1/components/{componentId}`
479    pub async fn get_component(
480        &self,
481        request: GetComponentRequest,
482    ) -> anyhow::Result<GetComponentResponse> {
483        request.validate().context("parameter validation")?;
484        let mut url = self.base_url.clone();
485        url.path_segments_mut()
486            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
487            .push("v1")
488            .push("components")
489            .push(&request.path.component_id.to_string());
490        let response = self.client.get(url).send().await?;
491        Ok(GetComponentRequest::parse_response(response).await?)
492    }
493    /// Update a component
494    ///
495    /// Update a component's name and/or body. When the `lmx` body changes, the update cascades to every email using this component, and `affectedEmailCount` reports how many were affected. A change that would introduce a dynamic variable an email using the component cannot use is rejected.
496    ///
497    /// * Path: `POST /v1/components/{componentId}`
498    pub async fn update_component(
499        &self,
500        request: UpdateComponentRequest,
501    ) -> anyhow::Result<UpdateComponentResponseEnum> {
502        request.validate().context("parameter validation")?;
503        let mut url = self.base_url.clone();
504        url.path_segments_mut()
505            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
506            .push("v1")
507            .push("components")
508            .push(&request.path.component_id.to_string());
509        let response = self.client.post(url).json(&request.body).send().await?;
510        Ok(UpdateComponentRequest::parse_response(response).await?)
511    }
512    /// List components
513    ///
514    /// Retrieve a paginated list of email components.
515    ///
516    /// * Path: `GET /v1/components`
517    pub async fn list_components(
518        &self,
519        request: ListComponentsRequest,
520    ) -> anyhow::Result<ListComponentsResponseEnum> {
521        request.validate().context("parameter validation")?;
522        let mut url = self.base_url.clone();
523        url.path_segments_mut()
524            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
525            .push("v1")
526            .push("components");
527        let response = self.client.get(url).query(&request.query).send().await?;
528        Ok(ListComponentsRequest::parse_response(response).await?)
529    }
530    /// Create a component
531    ///
532    /// Create a new email component from an LMX body.
533    ///
534    /// * Path: `POST /v1/components`
535    pub async fn create_component(
536        &self,
537        request: CreateComponentRequest,
538    ) -> anyhow::Result<CreateComponentResponse> {
539        request.validate().context("parameter validation")?;
540        let mut url = self.base_url.clone();
541        url.path_segments_mut()
542            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
543            .push("v1")
544            .push("components");
545        let response = self.client.post(url).json(&request.body).send().await?;
546        Ok(CreateComponentRequest::parse_response(response).await?)
547    }
548    /// Get an email message
549    ///
550    /// Retrieve an email message, including its compiled LMX content.
551    ///
552    /// * Path: `GET /v1/email-messages/{emailMessageId}`
553    pub async fn get_email_message(
554        &self,
555        request: GetEmailMessageRequest,
556    ) -> anyhow::Result<GetEmailMessageResponse> {
557        request.validate().context("parameter validation")?;
558        let mut url = self.base_url.clone();
559        url.path_segments_mut()
560            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
561            .push("v1")
562            .push("email-messages")
563            .push(&request.path.email_message_id.to_string());
564        let response = self.client.get(url).send().await?;
565        Ok(GetEmailMessageRequest::parse_response(response).await?)
566    }
567    /// Update an email message
568    ///
569    /// Update fields on an email message (subject, preview text, sender, LMX content). The campaign must be in draft status. Supply `expectedRevisionId` matching the current `contentRevisionId` — the server rejects mismatched revisions with 409.
570    ///
571    /// * Path: `POST /v1/email-messages/{emailMessageId}`
572    pub async fn update_email_message(
573        &self,
574        request: UpdateEmailMessageRequestParams,
575    ) -> anyhow::Result<UpdateEmailMessageResponse> {
576        request.validate().context("parameter validation")?;
577        let mut url = self.base_url.clone();
578        url.path_segments_mut()
579            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
580            .push("v1")
581            .push("email-messages")
582            .push(&request.path.email_message_id.to_string());
583        let response = self.client.post(url).json(&request.body).send().await?;
584        Ok(UpdateEmailMessageRequestParams::parse_response(response).await?)
585    }
586    /// Send a preview of an email message
587    ///
588    /// Send a test preview of an email message to one or more addresses. The accepted variable fields depend on the parent's type - campaign previews accept `contactProperties`, workflow previews accept `contactProperties` and `eventProperties`, and transactional previews accept `dataVariables`. Supplying a field the parent cannot reference is rejected with 400.
589    ///
590    /// * Path: `POST /v1/email-messages/{emailMessageId}/preview`
591    pub async fn preview_email_message(
592        &self,
593        request: PreviewEmailMessageRequest,
594    ) -> anyhow::Result<PreviewEmailMessageResponse> {
595        request.validate().context("parameter validation")?;
596        let mut url = self.base_url.clone();
597        url.path_segments_mut()
598            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
599            .push("v1")
600            .push("email-messages")
601            .push(&request.path.email_message_id.to_string())
602            .push("preview");
603        let response = self.client.post(url).json(&request.body).send().await?;
604        Ok(PreviewEmailMessageRequest::parse_response(response).await?)
605    }
606    /// Run Guardian checks on an email message
607    ///
608    /// Validate an email message's content against Guardian rules and return any errors and warnings. Errors must be resolved before the email can be published, warnings are advisory.
609    ///
610    /// * Path: `GET /v1/email-messages/{emailMessageId}/guardian`
611    pub async fn get_email_message_guardian(
612        &self,
613        request: GetEmailMessageGuardianRequest,
614    ) -> anyhow::Result<GetEmailMessageGuardianResponse> {
615        request.validate().context("parameter validation")?;
616        let mut url = self.base_url.clone();
617        url.path_segments_mut()
618            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
619            .push("v1")
620            .push("email-messages")
621            .push(&request.path.email_message_id.to_string())
622            .push("guardian");
623        let response = self.client.get(url).send().await?;
624        Ok(GetEmailMessageGuardianRequest::parse_response(response).await?)
625    }
626    /// Send an event
627    ///
628    /// Send events to trigger workflows.
629    ///
630    /// * Path: `POST /v1/events/send`
631    pub async fn send_event(&self, request: SendEventRequest) -> anyhow::Result<SendEventResponse> {
632        request.validate().context("parameter validation")?;
633        let mut url = self.base_url.clone();
634        url.path_segments_mut()
635            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
636            .push("v1")
637            .push("events")
638            .push("send");
639        let response = self
640            .client
641            .post(url)
642            .headers(
643                http::HeaderMap::try_from(&request.header).context("building request headers")?,
644            )
645            .json(&request.body)
646            .send()
647            .await?;
648        Ok(SendEventRequest::parse_response(response).await?)
649    }
650    /// List event patterns
651    ///
652    /// Retrieve a paginated list of event patterns available to workflow event trigger nodes.
653    ///
654    /// * Path: `GET /v1/event-patterns`
655    pub async fn list_event_patterns(
656        &self,
657        request: ListEventPatternsRequest,
658    ) -> anyhow::Result<ListEventPatternsResponseEnum> {
659        request.validate().context("parameter validation")?;
660        let mut url = self.base_url.clone();
661        url.path_segments_mut()
662            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
663            .push("v1")
664            .push("event-patterns");
665        let response = self.client.get(url).query(&request.query).send().await?;
666        Ok(ListEventPatternsRequest::parse_response(response).await?)
667    }
668    /// Get an event pattern by name
669    ///
670    /// Retrieve event pattern details by event name for a workflow event trigger. Event names are case-sensitive, so `PaymentReceived` and `paymentReceived` are different events.
671    ///
672    /// * Path: `GET /v1/event-patterns/by-name/{eventName}`
673    pub async fn get_event_pattern_by_name(
674        &self,
675        request: GetEventPatternByNameRequest,
676    ) -> anyhow::Result<GetEventPatternResponse> {
677        request.validate().context("parameter validation")?;
678        let mut url = self.base_url.clone();
679        url.path_segments_mut()
680            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
681            .push("v1")
682            .push("event-patterns")
683            .push("by-name")
684            .push(&request.path.event_name.to_string());
685        let response = self.client.get(url).send().await?;
686        Ok(GetEventPatternByNameRequest::parse_response(response).await?)
687    }
688    /// Get an event pattern by ID
689    ///
690    /// Retrieve event pattern details for a workflow event trigger.
691    ///
692    /// * Path: `GET /v1/event-patterns/{eventPatternId}`
693    pub async fn get_event_pattern(
694        &self,
695        request: GetEventPatternRequest,
696    ) -> anyhow::Result<GetEventPatternResponse> {
697        request.validate().context("parameter validation")?;
698        let mut url = self.base_url.clone();
699        url.path_segments_mut()
700            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
701            .push("v1")
702            .push("event-patterns")
703            .push(&request.path.event_pattern_id.to_string());
704        let response = self.client.get(url).send().await?;
705        Ok(GetEventPatternRequest::parse_response(response).await?)
706    }
707    /// List mailing lists
708    ///
709    /// Retrieve a list of your account's mailing lists.
710    ///
711    /// * Path: `GET /v1/lists`
712    pub async fn list_mailing_lists(
713        &self,
714        request: ListMailingListsRequest,
715    ) -> anyhow::Result<ListMailingListsResponse> {
716        request.validate().context("parameter validation")?;
717        let mut url = self.base_url.clone();
718        url.path_segments_mut()
719            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
720            .push("v1")
721            .push("lists");
722        let response = self.client.get(url).send().await?;
723        Ok(ListMailingListsRequest::parse_response(response).await?)
724    }
725    /// Get a theme
726    ///
727    /// Retrieve a single theme by ID.
728    ///
729    /// * Path: `GET /v1/themes/{themeId}`
730    pub async fn get_theme(&self, request: GetThemeRequest) -> anyhow::Result<GetThemeResponse> {
731        request.validate().context("parameter validation")?;
732        let mut url = self.base_url.clone();
733        url.path_segments_mut()
734            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
735            .push("v1")
736            .push("themes")
737            .push(&request.path.theme_id.to_string());
738        let response = self.client.get(url).send().await?;
739        Ok(GetThemeRequest::parse_response(response).await?)
740    }
741    /// Update a theme
742    ///
743    /// Update a theme's name and/or styles. When `styles` change, the update cascades to every email using this theme, and `affectedEmailCount` in the response reports how many emails were affected. Manual style edits made on individual emails are preserved: the cascade only changes properties an email has not overridden. A per-email override is removed only when it becomes identical to the theme's new value, after which that email follows the theme for that property.
744    ///
745    /// * Path: `POST /v1/themes/{themeId}`
746    pub async fn update_theme(
747        &self,
748        request: UpdateThemeRequest,
749    ) -> anyhow::Result<UpdateThemeResponseEnum> {
750        request.validate().context("parameter validation")?;
751        let mut url = self.base_url.clone();
752        url.path_segments_mut()
753            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
754            .push("v1")
755            .push("themes")
756            .push(&request.path.theme_id.to_string());
757        let response = self.client.post(url).json(&request.body).send().await?;
758        Ok(UpdateThemeRequest::parse_response(response).await?)
759    }
760    /// List themes
761    ///
762    /// Retrieve a paginated list of email themes, most recently created first.
763    ///
764    /// * Path: `GET /v1/themes`
765    pub async fn list_themes(
766        &self,
767        request: ListThemesRequest,
768    ) -> anyhow::Result<ListThemesResponseEnum> {
769        request.validate().context("parameter validation")?;
770        let mut url = self.base_url.clone();
771        url.path_segments_mut()
772            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
773            .push("v1")
774            .push("themes");
775        let response = self.client.get(url).query(&request.query).send().await?;
776        Ok(ListThemesRequest::parse_response(response).await?)
777    }
778    /// Create a theme
779    ///
780    /// Create a new email theme for use across Loops emails.
781    ///
782    /// * Path: `POST /v1/themes`
783    pub async fn create_theme(
784        &self,
785        request: CreateThemeRequest,
786    ) -> anyhow::Result<CreateThemeResponse> {
787        request.validate().context("parameter validation")?;
788        let mut url = self.base_url.clone();
789        url.path_segments_mut()
790            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
791            .push("v1")
792            .push("themes");
793        let response = self.client.post(url).json(&request.body).send().await?;
794        Ok(CreateThemeRequest::parse_response(response).await?)
795    }
796    /// List transactional emails (legacy)
797    ///
798    /// Get a list of published transactional emails.
799    ///
800    /// * Path: `GET /v1/transactional`
801    pub async fn list_published_transactional_emails(
802        &self,
803        request: ListPublishedTransactionalEmailsRequest,
804    ) -> anyhow::Result<ListPublishedTransactionalEmailsResponse> {
805        request.validate().context("parameter validation")?;
806        let mut url = self.base_url.clone();
807        url.path_segments_mut()
808            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
809            .push("v1")
810            .push("transactional");
811        let response = self.client.get(url).query(&request.query).send().await?;
812        Ok(ListPublishedTransactionalEmailsRequest::parse_response(response).await?)
813    }
814    /// Send a transactional email
815    ///
816    /// Send a transactional email to a contact.<br>Please [email us](mailto:help@loops.so) to enable attachments on your account before using them with the API.
817    ///
818    /// To set dynamic Subject, From, Reply to, CC, BCC email header fields, add data variables to those fields in the editor, then include data for each variable in the API request. Read our transactional email guide for more details.
819    ///
820    /// * Path: `POST /v1/transactional`
821    pub async fn send_transactional_email(
822        &self,
823        request: SendTransactionalEmailRequest,
824    ) -> anyhow::Result<SendTransactionalEmailResponse> {
825        request.validate().context("parameter validation")?;
826        let mut url = self.base_url.clone();
827        url.path_segments_mut()
828            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
829            .push("v1")
830            .push("transactional");
831        let response = self
832            .client
833            .post(url)
834            .headers(
835                http::HeaderMap::try_from(&request.header).context("building request headers")?,
836            )
837            .json(&request.body)
838            .send()
839            .await?;
840        Ok(SendTransactionalEmailRequest::parse_response(response).await?)
841    }
842    /// List transactional emails
843    ///
844    /// Retrieve a paginated list of transactional emails, most recently created first.
845    ///
846    /// * Path: `GET /v1/transactional-emails`
847    pub async fn list_transactional_emails(
848        &self,
849        request: ListTransactionalEmailsRequest,
850    ) -> anyhow::Result<ListTransactionalEmailsResponse> {
851        request.validate().context("parameter validation")?;
852        let mut url = self.base_url.clone();
853        url.path_segments_mut()
854            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
855            .push("v1")
856            .push("transactional-emails");
857        let response = self.client.get(url).query(&request.query).send().await?;
858        Ok(ListTransactionalEmailsRequest::parse_response(response).await?)
859    }
860    /// Create a transactional email
861    ///
862    /// Create a new transactional email. An empty draft email message is created automatically and its `draftEmailMessageId` is returned. Use the `POST /v1/email-messages/{emailMessageId}` endpoint along with the returned `draftEmailMessageContentRevisionId` to set subject, sender, preview text, and LMX content, then call `POST /v1/transactional-emails/{transactionalId}/publish` to publish the draft.
863    ///
864    /// * Path: `POST /v1/transactional-emails`
865    pub async fn create_transactional_email(
866        &self,
867        request: CreateTransactionalEmailRequest,
868    ) -> anyhow::Result<CreateTransactionalEmailResponse> {
869        request.validate().context("parameter validation")?;
870        let mut url = self.base_url.clone();
871        url.path_segments_mut()
872            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
873            .push("v1")
874            .push("transactional-emails");
875        let response = self.client.post(url).json(&request.body).send().await?;
876        Ok(CreateTransactionalEmailRequest::parse_response(response).await?)
877    }
878    /// Get a transactional email
879    ///
880    /// Retrieve a single transactional email by ID.
881    ///
882    /// * Path: `GET /v1/transactional-emails/{transactionalId}`
883    pub async fn get_transactional_email(
884        &self,
885        request: GetTransactionalEmailRequest,
886    ) -> anyhow::Result<GetTransactionalEmailResponse> {
887        request.validate().context("parameter validation")?;
888        let mut url = self.base_url.clone();
889        url.path_segments_mut()
890            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
891            .push("v1")
892            .push("transactional-emails")
893            .push(&request.path.transactional_id.to_string());
894        let response = self.client.get(url).send().await?;
895        Ok(GetTransactionalEmailRequest::parse_response(response).await?)
896    }
897    /// Update a transactional email
898    ///
899    /// Update a transactional email's name or group. At least one field must be provided.
900    ///
901    /// * Path: `POST /v1/transactional-emails/{transactionalId}`
902    pub async fn update_transactional_email(
903        &self,
904        request: UpdateTransactionalEmailRequest,
905    ) -> anyhow::Result<GetTransactionalEmailResponse> {
906        request.validate().context("parameter validation")?;
907        let mut url = self.base_url.clone();
908        url.path_segments_mut()
909            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
910            .push("v1")
911            .push("transactional-emails")
912            .push(&request.path.transactional_id.to_string());
913        let response = self.client.post(url).json(&request.body).send().await?;
914        Ok(UpdateTransactionalEmailRequest::parse_response(response).await?)
915    }
916    /// Get transactional email metrics
917    ///
918    /// Retrieve all-time delivery metrics for a transactional email, totalled across every published version.
919    ///
920    /// * Path: `GET /v1/transactional-emails/{transactionalId}/metrics`
921    pub async fn get_transactional_email_metrics(
922        &self,
923        request: GetTransactionalEmailMetricsRequest,
924    ) -> anyhow::Result<GetTransactionalEmailMetricsResponse> {
925        request.validate().context("parameter validation")?;
926        let mut url = self.base_url.clone();
927        url.path_segments_mut()
928            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
929            .push("v1")
930            .push("transactional-emails")
931            .push(&request.path.transactional_id.to_string())
932            .push("metrics");
933        let response = self.client.get(url).send().await?;
934        Ok(GetTransactionalEmailMetricsRequest::parse_response(response).await?)
935    }
936    /// Ensure a draft email message
937    ///
938    /// Ensure the transactional email has a draft email message. If a draft already exists it is returned unchanged; otherwise a new empty draft is created (seeded from the most recent published version when present). Use `POST /v1/email-messages/{emailMessageId}` to edit the draft's content.
939    ///
940    /// * Path: `POST /v1/transactional-emails/{transactionalId}/draft`
941    pub async fn ensure_transactional_draft(
942        &self,
943        request: EnsureTransactionalDraftRequest,
944    ) -> anyhow::Result<EnsureTransactionalDraftResponse> {
945        request.validate().context("parameter validation")?;
946        let mut url = self.base_url.clone();
947        url.path_segments_mut()
948            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
949            .push("v1")
950            .push("transactional-emails")
951            .push(&request.path.transactional_id.to_string())
952            .push("draft");
953        let response = self.client.post(url).send().await?;
954        Ok(EnsureTransactionalDraftRequest::parse_response(response).await?)
955    }
956    /// Publish a transactional email draft
957    ///
958    /// Publish the transactional email's current draft email message. The draft becomes the published version and the draft is cleared.
959    ///
960    /// * Path: `POST /v1/transactional-emails/{transactionalId}/publish`
961    pub async fn publish_transactional_email(
962        &self,
963        request: PublishTransactionalEmailRequest,
964    ) -> anyhow::Result<PublishTransactionalEmailResponse> {
965        request.validate().context("parameter validation")?;
966        let mut url = self.base_url.clone();
967        url.path_segments_mut()
968            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
969            .push("v1")
970            .push("transactional-emails")
971            .push(&request.path.transactional_id.to_string())
972            .push("publish");
973        let response = self.client.post(url).send().await?;
974        Ok(PublishTransactionalEmailRequest::parse_response(response).await?)
975    }
976    /// List transactional groups
977    ///
978    /// Retrieve a paginated list of transactional groups, most recently created first.
979    ///
980    /// * Path: `GET /v1/transactional-groups`
981    pub async fn list_transactional_groups(
982        &self,
983        request: ListTransactionalGroupsRequest,
984    ) -> anyhow::Result<ListCampaignGroupsResponse> {
985        request.validate().context("parameter validation")?;
986        let mut url = self.base_url.clone();
987        url.path_segments_mut()
988            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
989            .push("v1")
990            .push("transactional-groups");
991        let response = self.client.get(url).query(&request.query).send().await?;
992        Ok(ListTransactionalGroupsRequest::parse_response(response).await?)
993    }
994    /// Create a transactional group
995    ///
996    /// Create a new transactional group.
997    ///
998    /// * Path: `POST /v1/transactional-groups`
999    pub async fn create_transactional_group(
1000        &self,
1001        request: CreateTransactionalGroupRequest,
1002    ) -> anyhow::Result<CreateCampaignGroupResponse> {
1003        request.validate().context("parameter validation")?;
1004        let mut url = self.base_url.clone();
1005        url.path_segments_mut()
1006            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1007            .push("v1")
1008            .push("transactional-groups");
1009        let response = self.client.post(url).json(&request.body).send().await?;
1010        Ok(CreateTransactionalGroupRequest::parse_response(response).await?)
1011    }
1012    /// Get a transactional group
1013    ///
1014    /// Retrieve a single transactional group by ID.
1015    ///
1016    /// * Path: `GET /v1/transactional-groups/{transactionalGroupId}`
1017    pub async fn get_transactional_group(
1018        &self,
1019        request: GetTransactionalGroupRequest,
1020    ) -> anyhow::Result<GetCampaignGroupResponse> {
1021        request.validate().context("parameter validation")?;
1022        let mut url = self.base_url.clone();
1023        url.path_segments_mut()
1024            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1025            .push("v1")
1026            .push("transactional-groups")
1027            .push(&request.path.transactional_group_id.to_string());
1028        let response = self.client.get(url).send().await?;
1029        Ok(GetTransactionalGroupRequest::parse_response(response).await?)
1030    }
1031    /// Update a transactional group
1032    ///
1033    /// Update a transactional group's name or description. At least one field must be provided. The reserved "Unsorted" group cannot be edited.
1034    ///
1035    /// * Path: `POST /v1/transactional-groups/{transactionalGroupId}`
1036    pub async fn update_transactional_group(
1037        &self,
1038        request: UpdateTransactionalGroupRequest,
1039    ) -> anyhow::Result<GetCampaignGroupResponse> {
1040        request.validate().context("parameter validation")?;
1041        let mut url = self.base_url.clone();
1042        url.path_segments_mut()
1043            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1044            .push("v1")
1045            .push("transactional-groups")
1046            .push(&request.path.transactional_group_id.to_string());
1047        let response = self.client.post(url).json(&request.body).send().await?;
1048        Ok(UpdateTransactionalGroupRequest::parse_response(response).await?)
1049    }
1050    /// Create an upload
1051    ///
1052    /// Request a pre-signed URL to upload an image asset. Upload the file with an HTTP `PUT` to the returned `presignedUrl` (sending the same `Content-Type` and `Content-Length`), then call `/uploads/{emailAssetId}/complete` to finalize the asset.
1053    ///
1054    /// * Path: `POST /v1/uploads`
1055    pub async fn create_upload(
1056        &self,
1057        request: CreateUploadRequestParams,
1058    ) -> anyhow::Result<CreateUploadResponseEnum> {
1059        request.validate().context("parameter validation")?;
1060        let mut url = self.base_url.clone();
1061        url.path_segments_mut()
1062            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1063            .push("v1")
1064            .push("uploads");
1065        let response = self.client.post(url).json(&request.body).send().await?;
1066        Ok(CreateUploadRequestParams::parse_response(response).await?)
1067    }
1068    /// Complete an upload
1069    ///
1070    /// Finalize an image upload after the file has been uploaded to the pre-signed URL. Returns the public URL of the uploaded image asset.
1071    ///
1072    /// * Path: `POST /v1/uploads/{emailAssetId}/complete`
1073    pub async fn complete_upload(
1074        &self,
1075        request: CompleteUploadRequest,
1076    ) -> anyhow::Result<CompleteUploadResponseEnum> {
1077        request.validate().context("parameter validation")?;
1078        let mut url = self.base_url.clone();
1079        url.path_segments_mut()
1080            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1081            .push("v1")
1082            .push("uploads")
1083            .push(&request.path.email_asset_id.to_string())
1084            .push("complete");
1085        let response = self.client.post(url).send().await?;
1086        Ok(CompleteUploadRequest::parse_response(response).await?)
1087    }
1088    /// List workflow groups
1089    ///
1090    /// Retrieve a paginated list of workflow groups, most recently created first.
1091    ///
1092    /// * Path: `GET /v1/workflow-groups`
1093    pub async fn list_workflow_groups(
1094        &self,
1095        request: ListWorkflowGroupsRequest,
1096    ) -> anyhow::Result<ListCampaignGroupsResponse> {
1097        request.validate().context("parameter validation")?;
1098        let mut url = self.base_url.clone();
1099        url.path_segments_mut()
1100            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1101            .push("v1")
1102            .push("workflow-groups");
1103        let response = self.client.get(url).query(&request.query).send().await?;
1104        Ok(ListWorkflowGroupsRequest::parse_response(response).await?)
1105    }
1106    /// Create a workflow group
1107    ///
1108    /// Create a new workflow group.
1109    ///
1110    /// * Path: `POST /v1/workflow-groups`
1111    pub async fn create_workflow_group(
1112        &self,
1113        request: CreateWorkflowGroupRequest,
1114    ) -> anyhow::Result<CreateCampaignGroupResponse> {
1115        request.validate().context("parameter validation")?;
1116        let mut url = self.base_url.clone();
1117        url.path_segments_mut()
1118            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1119            .push("v1")
1120            .push("workflow-groups");
1121        let response = self.client.post(url).json(&request.body).send().await?;
1122        Ok(CreateWorkflowGroupRequest::parse_response(response).await?)
1123    }
1124    /// Get a workflow group
1125    ///
1126    /// Retrieve a single workflow group by ID.
1127    ///
1128    /// * Path: `GET /v1/workflow-groups/{workflowGroupId}`
1129    pub async fn get_workflow_group(
1130        &self,
1131        request: GetWorkflowGroupRequest,
1132    ) -> anyhow::Result<GetCampaignGroupResponse> {
1133        request.validate().context("parameter validation")?;
1134        let mut url = self.base_url.clone();
1135        url.path_segments_mut()
1136            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1137            .push("v1")
1138            .push("workflow-groups")
1139            .push(&request.path.workflow_group_id.to_string());
1140        let response = self.client.get(url).send().await?;
1141        Ok(GetWorkflowGroupRequest::parse_response(response).await?)
1142    }
1143    /// Update a workflow group
1144    ///
1145    /// Update a workflow group's name or description. At least one field must be provided. The reserved "Unsorted" group cannot be edited.
1146    ///
1147    /// * Path: `POST /v1/workflow-groups/{workflowGroupId}`
1148    pub async fn update_workflow_group(
1149        &self,
1150        request: UpdateWorkflowGroupRequest,
1151    ) -> anyhow::Result<GetCampaignGroupResponse> {
1152        request.validate().context("parameter validation")?;
1153        let mut url = self.base_url.clone();
1154        url.path_segments_mut()
1155            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1156            .push("v1")
1157            .push("workflow-groups")
1158            .push(&request.path.workflow_group_id.to_string());
1159        let response = self.client.post(url).json(&request.body).send().await?;
1160        Ok(UpdateWorkflowGroupRequest::parse_response(response).await?)
1161    }
1162    /// List workflows
1163    ///
1164    /// Retrieve a paginated list of workflows.
1165    ///
1166    /// * Path: `GET /v1/workflows`
1167    pub async fn list_workflows(
1168        &self,
1169        request: ListWorkflowsRequest,
1170    ) -> anyhow::Result<ListWorkflowsResponseEnum> {
1171        request.validate().context("parameter validation")?;
1172        let mut url = self.base_url.clone();
1173        url.path_segments_mut()
1174            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1175            .push("v1")
1176            .push("workflows");
1177        let response = self.client.get(url).query(&request.query).send().await?;
1178        Ok(ListWorkflowsRequest::parse_response(response).await?)
1179    }
1180    /// Create a workflow
1181    ///
1182    /// Create a draft workflow with a blank trigger and exit node. When `workflowGroupId` is omitted, the workflow is added to the team's Unsorted group.
1183    ///
1184    /// * Path: `POST /v1/workflows`
1185    pub async fn create_workflow(
1186        &self,
1187        request: CreateWorkflowRequestParams,
1188    ) -> anyhow::Result<CreateWorkflowResponse> {
1189        request.validate().context("parameter validation")?;
1190        let mut url = self.base_url.clone();
1191        url.path_segments_mut()
1192            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1193            .push("v1")
1194            .push("workflows");
1195        let response = self.client.post(url).json(&request.body).send().await?;
1196        Ok(CreateWorkflowRequestParams::parse_response(response).await?)
1197    }
1198    /// Get a workflow
1199    ///
1200    /// Retrieve a workflow graph with node type names, connections, and selected display fields.
1201    ///
1202    /// * Path: `GET /v1/workflows/{workflowId}`
1203    pub async fn get_workflow(
1204        &self,
1205        request: GetWorkflowRequest,
1206    ) -> anyhow::Result<GetWorkflowResponse> {
1207        request.validate().context("parameter validation")?;
1208        let mut url = self.base_url.clone();
1209        url.path_segments_mut()
1210            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1211            .push("v1")
1212            .push("workflows")
1213            .push(&request.path.workflow_id.to_string());
1214        let response = self.client.get(url).send().await?;
1215        Ok(GetWorkflowRequest::parse_response(response).await?)
1216    }
1217    /// Update a workflow
1218    ///
1219    /// Update a workflow's name, description, or group. At least one field must be provided. To change the workflow's mailing list, use the `POST /v1/workflows/{workflowId}/mailing-list` endpoint instead.
1220    ///
1221    /// * Path: `POST /v1/workflows/{workflowId}`
1222    pub async fn update_workflow_properties(
1223        &self,
1224        request: UpdateWorkflowPropertiesRequestParams,
1225    ) -> anyhow::Result<UpdateWorkflowPropertiesResponse> {
1226        request.validate().context("parameter validation")?;
1227        let mut url = self.base_url.clone();
1228        url.path_segments_mut()
1229            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1230            .push("v1")
1231            .push("workflows")
1232            .push(&request.path.workflow_id.to_string());
1233        let response = self.client.post(url).json(&request.body).send().await?;
1234        Ok(UpdateWorkflowPropertiesRequestParams::parse_response(response).await?)
1235    }
1236    /// Delete a workflow
1237    ///
1238    /// Delete a workflow. Successful deletion returns `204 No Content`. If the workflow is currently sending or has queued contacts, Loops returns `409 Conflict` with a message instead of deleting. Retry with `confirmDelete: true` to delete the workflow, stop sending, and cancel queued contacts.
1239    ///
1240    /// * Path: `DELETE /v1/workflows/{workflowId}`
1241    pub async fn delete_workflow(
1242        &self,
1243        request: DeleteWorkflowRequestParams,
1244    ) -> anyhow::Result<DeleteWorkflowResponse> {
1245        request.validate().context("parameter validation")?;
1246        let mut url = self.base_url.clone();
1247        url.path_segments_mut()
1248            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1249            .push("v1")
1250            .push("workflows")
1251            .push(&request.path.workflow_id.to_string());
1252        let response = self.client.delete(url).json(&request.body).send().await?;
1253        Ok(DeleteWorkflowRequestParams::parse_response(response).await?)
1254    }
1255    /// Change workflow mailing list
1256    ///
1257    /// Dry run or apply a workflow mailing list change. If queued contacts would be removed from the workflow due to the change of mailing list, Loops returns with `"status": "queuedContactsFound"` instead of applying the change. Retry with `queuedContactPolicy: "discard"` to apply the change and discard those contacts. Confirmed update responses include the simplified workflow after the mailing list changes.
1258    ///
1259    /// * Path: `POST /v1/workflows/{workflowId}/mailing-list`
1260    pub async fn change_workflow_mailing_list(
1261        &self,
1262        request: ChangeWorkflowMailingListRequestParams,
1263    ) -> anyhow::Result<ChangeWorkflowMailingListResponseEnum> {
1264        request.validate().context("parameter validation")?;
1265        let mut url = self.base_url.clone();
1266        url.path_segments_mut()
1267            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1268            .push("v1")
1269            .push("workflows")
1270            .push(&request.path.workflow_id.to_string())
1271            .push("mailing-list");
1272        let response = self.client.post(url).json(&request.body).send().await?;
1273        Ok(ChangeWorkflowMailingListRequestParams::parse_response(response).await?)
1274    }
1275    /// Create a workflow node
1276    ///
1277    /// Create a new default workflow node and return it with the latest workflow.
1278    ///
1279    /// Choose where the node goes with `insertMode`: `between` places it between an existing `fromNodeId` -> `toNodeId` connection, `before` places it before `toNodeId`, and `after` places it after `fromNodeId` when that node has exactly one outgoing connection. `after` is a convenience for simple linear paths, so callers do not need to fetch and pass the current child node ID. It is invalid when `fromNodeId` has no outgoing nodes, multiple outgoing nodes, or is an exit node. When the source has multiple outgoing nodes, use `between` with the exact `toNodeId` instead. For `before`, deprecated `beforeNodeId` requests are still accepted for compatibility, but new callers should use `toNodeId`.
1280    ///
1281    /// New nodes start with default settings; update the node after creation to configure it. Branch nodes create their default paths too: `BranchNode` creates two `AudienceFilter` children, and `ExperimentBranchNode` creates two regular `VariantNode` children plus one control `VariantNode`. Public workflows can have up to 400 nodes. Generated children count toward that limit, so a normal create adds 1 node, `BranchNode` adds 3, and `ExperimentBranchNode` adds 4. To add a sibling child path to a branch or experiment branch, use the `POST /v1/workflows/{workflowId}/nodes/{nodeId}/add-branch` endpoint. Branch paths can be edited with create-node, but a workflow cannot be started unless each direct `BranchNode` child is an `AudienceFilter`. For experiments, use create-node only to insert a missing `VariantNode` before non-variant content; use add-branch for another variant path.
1282    ///
1283    /// * Path: `POST /v1/workflows/{workflowId}/nodes`
1284    pub async fn create_workflow_node(
1285        &self,
1286        request: CreateWorkflowNodeRequestParams,
1287    ) -> anyhow::Result<CreateWorkflowNodeResponseEnum> {
1288        request.validate().context("parameter validation")?;
1289        let mut url = self.base_url.clone();
1290        url.path_segments_mut()
1291            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1292            .push("v1")
1293            .push("workflows")
1294            .push(&request.path.workflow_id.to_string())
1295            .push("nodes");
1296        let response = self.client.post(url).json(&request.body).send().await?;
1297        Ok(CreateWorkflowNodeRequestParams::parse_response(response).await?)
1298    }
1299    /// Add a branch
1300    ///
1301    /// Add a branch and a child node under an existing Branch or Experiment node. Returns the created child node plus the latest workflow.
1302    ///
1303    /// - Adding a branch to a `BranchNode` creates one `AudienceFilter` child node.
1304    /// - Adding a branch to an `ExperimentBranchNode` creates one `VariantNode` child node.
1305    ///
1306    /// This endpoint does not accept node configuration fields; update the child node with `POST /v1/workflows/{workflowId}/nodes/{nodeId}` after creation. Public workflows are limited to 400 nodes, and this endpoint adds 1 node.
1307    ///
1308    /// * Path: `POST /v1/workflows/{workflowId}/nodes/{nodeId}/add-branch`
1309    pub async fn add_workflow_branch(
1310        &self,
1311        request: AddWorkflowBranchRequestParams,
1312    ) -> anyhow::Result<AddWorkflowBranchResponseEnum> {
1313        request.validate().context("parameter validation")?;
1314        let mut url = self.base_url.clone();
1315        url.path_segments_mut()
1316            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1317            .push("v1")
1318            .push("workflows")
1319            .push(&request.path.workflow_id.to_string())
1320            .push("nodes")
1321            .push(&request.path.node_id.to_string())
1322            .push("add-branch");
1323        let response = self.client.post(url).json(&request.body).send().await?;
1324        Ok(AddWorkflowBranchRequestParams::parse_response(response).await?)
1325    }
1326    /// Get a workflow node
1327    ///
1328    /// Retrieve detailed data for a single workflow node.
1329    ///
1330    /// * Path: `GET /v1/workflows/{workflowId}/nodes/{nodeId}`
1331    pub async fn get_workflow_node(
1332        &self,
1333        request: GetWorkflowNodeRequest,
1334    ) -> anyhow::Result<GetWorkflowNodeResponse> {
1335        request.validate().context("parameter validation")?;
1336        let mut url = self.base_url.clone();
1337        url.path_segments_mut()
1338            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1339            .push("v1")
1340            .push("workflows")
1341            .push(&request.path.workflow_id.to_string())
1342            .push("nodes")
1343            .push(&request.path.node_id.to_string());
1344        let response = self.client.get(url).send().await?;
1345        Ok(GetWorkflowNodeRequest::parse_response(response).await?)
1346    }
1347    /// Update a workflow node
1348    ///
1349    /// Update workflow-node-owned fields for a single node. Shared resources such as email messages and audience segments should be updated through their own APIs.
1350    ///
1351    /// * Path: `POST /v1/workflows/{workflowId}/nodes/{nodeId}`
1352    pub async fn update_workflow_node(
1353        &self,
1354        request: UpdateWorkflowNodeRequestParams,
1355    ) -> anyhow::Result<UpdateWorkflowNodeResponseEnum> {
1356        request.validate().context("parameter validation")?;
1357        let mut url = self.base_url.clone();
1358        url.path_segments_mut()
1359            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1360            .push("v1")
1361            .push("workflows")
1362            .push(&request.path.workflow_id.to_string())
1363            .push("nodes")
1364            .push(&request.path.node_id.to_string());
1365        let response = self.client.post(url).json(&request.body).send().await?;
1366        Ok(UpdateWorkflowNodeRequestParams::parse_response(response).await?)
1367    }
1368    /// Delete a workflow node
1369    ///
1370    /// Delete a single workflow node. If contacts are queued at the node, Loops returns with `"status": "queuedContactsFound"` instead of deleting. Retry with `queuedContactPolicy: "discard"` to delete the node and discard those queued contacts. Confirmed deletion responses include the simplified workflow after the node is removed.
1371    ///
1372    /// * Path: `DELETE /v1/workflows/{workflowId}/nodes/{nodeId}`
1373    pub async fn delete_workflow_node(
1374        &self,
1375        request: DeleteWorkflowNodeRequestParams,
1376    ) -> anyhow::Result<DeleteWorkflowNodeResponseEnum> {
1377        request.validate().context("parameter validation")?;
1378        let mut url = self.base_url.clone();
1379        url.path_segments_mut()
1380            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1381            .push("v1")
1382            .push("workflows")
1383            .push(&request.path.workflow_id.to_string())
1384            .push("nodes")
1385            .push(&request.path.node_id.to_string());
1386        let response = self.client.delete(url).json(&request.body).send().await?;
1387        Ok(DeleteWorkflowNodeRequestParams::parse_response(response).await?)
1388    }
1389    /// Get workflow node metrics
1390    ///
1391    /// Retrieve all-time email engagement metrics for a workflow `SendEmailAction` node. Nodes of any other type return a `400` response. A `SendEmailAction` node with an email that has not sent anything yet reports every counter as `0`.
1392    ///
1393    /// * Path: `GET /v1/workflows/{workflowId}/nodes/{nodeId}/metrics`
1394    pub async fn get_workflow_node_metrics(
1395        &self,
1396        request: GetWorkflowNodeMetricsRequest,
1397    ) -> anyhow::Result<GetWorkflowNodeMetricsResponse> {
1398        request.validate().context("parameter validation")?;
1399        let mut url = self.base_url.clone();
1400        url.path_segments_mut()
1401            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1402            .push("v1")
1403            .push("workflows")
1404            .push(&request.path.workflow_id.to_string())
1405            .push("nodes")
1406            .push(&request.path.node_id.to_string())
1407            .push("metrics");
1408        let response = self.client.get(url).send().await?;
1409        Ok(GetWorkflowNodeMetricsRequest::parse_response(response).await?)
1410    }
1411    /// Reroute a node connection
1412    ///
1413    /// Reroute the source node's existing connection to another valid target node. Returns the updated source node and the latest workflow.
1414    ///
1415    /// * Path: `POST /v1/workflows/{workflowId}/nodes/{nodeId}/reroute`
1416    pub async fn reroute_node_connection(
1417        &self,
1418        request: RerouteNodeConnectionRequestParams,
1419    ) -> anyhow::Result<RerouteNodeConnectionResponseEnum> {
1420        request.validate().context("parameter validation")?;
1421        let mut url = self.base_url.clone();
1422        url.path_segments_mut()
1423            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1424            .push("v1")
1425            .push("workflows")
1426            .push(&request.path.workflow_id.to_string())
1427            .push("nodes")
1428            .push(&request.path.node_id.to_string())
1429            .push("reroute");
1430        let response = self.client.post(url).json(&request.body).send().await?;
1431        Ok(RerouteNodeConnectionRequestParams::parse_response(response).await?)
1432    }
1433    /// Delete workflow nodes recursively
1434    ///
1435    /// Delete a node and its downstream subtree. If contacts are queued at any node that would be deleted, Loops returns with `"status": "queuedContactsFound"` instead of deleting. Retry with `queuedContactPolicy: "discard"` to delete the nodes and discard those queued contacts. Confirmed deletion responses include the simplified workflow after the nodes are removed.
1436    ///
1437    /// * Path: `DELETE /v1/workflows/{workflowId}/nodes/{nodeId}/recursive`
1438    pub async fn delete_workflow_node_recursively(
1439        &self,
1440        request: DeleteWorkflowNodeRecursivelyRequest,
1441    ) -> anyhow::Result<DeleteWorkflowNodeResponseEnum> {
1442        request.validate().context("parameter validation")?;
1443        let mut url = self.base_url.clone();
1444        url.path_segments_mut()
1445            .map_err(|()| anyhow::anyhow!("URL cannot be a base"))?
1446            .push("v1")
1447            .push("workflows")
1448            .push(&request.path.workflow_id.to_string())
1449            .push("nodes")
1450            .push(&request.path.node_id.to_string())
1451            .push("recursive");
1452        let response = self.client.delete(url).json(&request.body).send().await?;
1453        Ok(DeleteWorkflowNodeRecursivelyRequest::parse_response(response).await?)
1454    }
1455}