Skip to main content

late/apis/
workflows_api.rs

1/*
2 * Zernio API
3 *
4 * API reference for Zernio. Authenticate with a Bearer API key. Base URL: https://zernio.com/api
5 *
6 * The version of the OpenAPI document: 1.0.4
7 * Contact: support@zernio.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`activate_workflow`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum ActivateWorkflowError {
20    Status400(),
21    Status401(models::InlineObject),
22    Status404(models::InlineObject1),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`create_workflow`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum CreateWorkflowError {
30    Status400(),
31    Status401(models::InlineObject),
32    UnknownValue(serde_json::Value),
33}
34
35/// struct for typed errors of method [`delete_workflow`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum DeleteWorkflowError {
39    Status401(models::InlineObject),
40    Status404(models::InlineObject1),
41    UnknownValue(serde_json::Value),
42}
43
44/// struct for typed errors of method [`duplicate_workflow`]
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum DuplicateWorkflowError {
48    Status401(models::InlineObject),
49    Status404(models::InlineObject1),
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`get_workflow`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetWorkflowError {
57    Status401(models::InlineObject),
58    Status404(models::InlineObject1),
59    UnknownValue(serde_json::Value),
60}
61
62/// struct for typed errors of method [`get_workflow_version`]
63#[derive(Debug, Clone, Serialize, Deserialize)]
64#[serde(untagged)]
65pub enum GetWorkflowVersionError {
66    Status401(models::InlineObject),
67    Status404(models::InlineObject1),
68    UnknownValue(serde_json::Value),
69}
70
71/// struct for typed errors of method [`list_workflow_execution_events`]
72#[derive(Debug, Clone, Serialize, Deserialize)]
73#[serde(untagged)]
74pub enum ListWorkflowExecutionEventsError {
75    Status401(models::InlineObject),
76    Status404(models::InlineObject1),
77    UnknownValue(serde_json::Value),
78}
79
80/// struct for typed errors of method [`list_workflow_executions`]
81#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(untagged)]
83pub enum ListWorkflowExecutionsError {
84    Status401(models::InlineObject),
85    Status404(models::InlineObject1),
86    UnknownValue(serde_json::Value),
87}
88
89/// struct for typed errors of method [`list_workflow_versions`]
90#[derive(Debug, Clone, Serialize, Deserialize)]
91#[serde(untagged)]
92pub enum ListWorkflowVersionsError {
93    Status401(models::InlineObject),
94    Status404(models::InlineObject1),
95    UnknownValue(serde_json::Value),
96}
97
98/// struct for typed errors of method [`list_workflows`]
99#[derive(Debug, Clone, Serialize, Deserialize)]
100#[serde(untagged)]
101pub enum ListWorkflowsError {
102    Status401(models::InlineObject),
103    UnknownValue(serde_json::Value),
104}
105
106/// struct for typed errors of method [`pause_workflow`]
107#[derive(Debug, Clone, Serialize, Deserialize)]
108#[serde(untagged)]
109pub enum PauseWorkflowError {
110    Status401(models::InlineObject),
111    Status404(models::InlineObject1),
112    UnknownValue(serde_json::Value),
113}
114
115/// struct for typed errors of method [`restore_workflow_version`]
116#[derive(Debug, Clone, Serialize, Deserialize)]
117#[serde(untagged)]
118pub enum RestoreWorkflowVersionError {
119    Status400(),
120    Status401(models::InlineObject),
121    Status404(models::InlineObject1),
122    UnknownValue(serde_json::Value),
123}
124
125/// struct for typed errors of method [`trigger_workflow`]
126#[derive(Debug, Clone, Serialize, Deserialize)]
127#[serde(untagged)]
128pub enum TriggerWorkflowError {
129    Status400(),
130    Status401(models::InlineObject),
131    Status404(models::InlineObject1),
132    UnknownValue(serde_json::Value),
133}
134
135/// struct for typed errors of method [`update_workflow`]
136#[derive(Debug, Clone, Serialize, Deserialize)]
137#[serde(untagged)]
138pub enum UpdateWorkflowError {
139    Status400(),
140    Status401(models::InlineObject),
141    Status404(models::InlineObject1),
142    UnknownValue(serde_json::Value),
143}
144
145/// Validate the graph is runnable and set the workflow live. Once active, matching inbound messages start executions. Idempotent.
146pub async fn activate_workflow(
147    configuration: &configuration::Configuration,
148    workflow_id: &str,
149) -> Result<models::ActivateWorkflow200Response, Error<ActivateWorkflowError>> {
150    // add a prefix to parameters to efficiently prevent name collisions
151    let p_path_workflow_id = workflow_id;
152
153    let uri_str = format!(
154        "{}/v1/workflows/{workflowId}/activate",
155        configuration.base_path,
156        workflowId = crate::apis::urlencode(p_path_workflow_id)
157    );
158    let mut req_builder = configuration
159        .client
160        .request(reqwest::Method::POST, &uri_str);
161
162    if let Some(ref user_agent) = configuration.user_agent {
163        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
164    }
165    if let Some(ref token) = configuration.bearer_access_token {
166        req_builder = req_builder.bearer_auth(token.to_owned());
167    };
168
169    let req = req_builder.build()?;
170    let resp = configuration.client.execute(req).await?;
171
172    let status = resp.status();
173    let content_type = resp
174        .headers()
175        .get("content-type")
176        .and_then(|v| v.to_str().ok())
177        .unwrap_or("application/octet-stream");
178    let content_type = super::ContentType::from(content_type);
179
180    if !status.is_client_error() && !status.is_server_error() {
181        let content = resp.text().await?;
182        match content_type {
183            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
184            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ActivateWorkflow200Response`"))),
185            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ActivateWorkflow200Response`")))),
186        }
187    } else {
188        let content = resp.text().await?;
189        let entity: Option<ActivateWorkflowError> = serde_json::from_str(&content).ok();
190        Err(Error::ResponseError(ResponseContent {
191            status,
192            content,
193            entity,
194        }))
195    }
196}
197
198/// Create a branching conversation workflow (draft) from a node/edge graph. Created in `draft` status; activate it to start matching inbound messages. The graph is validated structurally; completeness (a trigger node + reachable entry) is required at activation.
199pub async fn create_workflow(
200    configuration: &configuration::Configuration,
201    create_workflow_request: models::CreateWorkflowRequest,
202) -> Result<models::CreateWorkflow200Response, Error<CreateWorkflowError>> {
203    // add a prefix to parameters to efficiently prevent name collisions
204    let p_body_create_workflow_request = create_workflow_request;
205
206    let uri_str = format!("{}/v1/workflows", configuration.base_path);
207    let mut req_builder = configuration
208        .client
209        .request(reqwest::Method::POST, &uri_str);
210
211    if let Some(ref user_agent) = configuration.user_agent {
212        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
213    }
214    if let Some(ref token) = configuration.bearer_access_token {
215        req_builder = req_builder.bearer_auth(token.to_owned());
216    };
217    req_builder = req_builder.json(&p_body_create_workflow_request);
218
219    let req = req_builder.build()?;
220    let resp = configuration.client.execute(req).await?;
221
222    let status = resp.status();
223    let content_type = resp
224        .headers()
225        .get("content-type")
226        .and_then(|v| v.to_str().ok())
227        .unwrap_or("application/octet-stream");
228    let content_type = super::ContentType::from(content_type);
229
230    if !status.is_client_error() && !status.is_server_error() {
231        let content = resp.text().await?;
232        match content_type {
233            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
234            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateWorkflow200Response`"))),
235            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CreateWorkflow200Response`")))),
236        }
237    } else {
238        let content = resp.text().await?;
239        let entity: Option<CreateWorkflowError> = serde_json::from_str(&content).ok();
240        Err(Error::ResponseError(ResponseContent {
241            status,
242            content,
243            entity,
244        }))
245    }
246}
247
248/// Permanently delete a workflow and all of its executions.
249pub async fn delete_workflow(
250    configuration: &configuration::Configuration,
251    workflow_id: &str,
252) -> Result<(), Error<DeleteWorkflowError>> {
253    // add a prefix to parameters to efficiently prevent name collisions
254    let p_path_workflow_id = workflow_id;
255
256    let uri_str = format!(
257        "{}/v1/workflows/{workflowId}",
258        configuration.base_path,
259        workflowId = crate::apis::urlencode(p_path_workflow_id)
260    );
261    let mut req_builder = configuration
262        .client
263        .request(reqwest::Method::DELETE, &uri_str);
264
265    if let Some(ref user_agent) = configuration.user_agent {
266        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
267    }
268    if let Some(ref token) = configuration.bearer_access_token {
269        req_builder = req_builder.bearer_auth(token.to_owned());
270    };
271
272    let req = req_builder.build()?;
273    let resp = configuration.client.execute(req).await?;
274
275    let status = resp.status();
276
277    if !status.is_client_error() && !status.is_server_error() {
278        Ok(())
279    } else {
280        let content = resp.text().await?;
281        let entity: Option<DeleteWorkflowError> = serde_json::from_str(&content).ok();
282        Err(Error::ResponseError(ResponseContent {
283            status,
284            content,
285            entity,
286        }))
287    }
288}
289
290/// Create an independent copy of a workflow's graph, name, description, and account binding. The copy is created in `draft` status with fresh execution counters and a new id — execution history is NOT copied. Useful for branching off a known-good workflow before making experimental edits.
291pub async fn duplicate_workflow(
292    configuration: &configuration::Configuration,
293    workflow_id: &str,
294) -> Result<models::DuplicateWorkflow201Response, Error<DuplicateWorkflowError>> {
295    // add a prefix to parameters to efficiently prevent name collisions
296    let p_path_workflow_id = workflow_id;
297
298    let uri_str = format!(
299        "{}/v1/workflows/{workflowId}/duplicate",
300        configuration.base_path,
301        workflowId = crate::apis::urlencode(p_path_workflow_id)
302    );
303    let mut req_builder = configuration
304        .client
305        .request(reqwest::Method::POST, &uri_str);
306
307    if let Some(ref user_agent) = configuration.user_agent {
308        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
309    }
310    if let Some(ref token) = configuration.bearer_access_token {
311        req_builder = req_builder.bearer_auth(token.to_owned());
312    };
313
314    let req = req_builder.build()?;
315    let resp = configuration.client.execute(req).await?;
316
317    let status = resp.status();
318    let content_type = resp
319        .headers()
320        .get("content-type")
321        .and_then(|v| v.to_str().ok())
322        .unwrap_or("application/octet-stream");
323    let content_type = super::ContentType::from(content_type);
324
325    if !status.is_client_error() && !status.is_server_error() {
326        let content = resp.text().await?;
327        match content_type {
328            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
329            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DuplicateWorkflow201Response`"))),
330            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DuplicateWorkflow201Response`")))),
331        }
332    } else {
333        let content = resp.text().await?;
334        let entity: Option<DuplicateWorkflowError> = serde_json::from_str(&content).ok();
335        Err(Error::ResponseError(ResponseContent {
336            status,
337            content,
338            entity,
339        }))
340    }
341}
342
343/// Returns a workflow including its full node/edge graph and run stats.
344pub async fn get_workflow(
345    configuration: &configuration::Configuration,
346    workflow_id: &str,
347) -> Result<models::GetWorkflow200Response, Error<GetWorkflowError>> {
348    // add a prefix to parameters to efficiently prevent name collisions
349    let p_path_workflow_id = workflow_id;
350
351    let uri_str = format!(
352        "{}/v1/workflows/{workflowId}",
353        configuration.base_path,
354        workflowId = crate::apis::urlencode(p_path_workflow_id)
355    );
356    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
357
358    if let Some(ref user_agent) = configuration.user_agent {
359        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
360    }
361    if let Some(ref token) = configuration.bearer_access_token {
362        req_builder = req_builder.bearer_auth(token.to_owned());
363    };
364
365    let req = req_builder.build()?;
366    let resp = configuration.client.execute(req).await?;
367
368    let status = resp.status();
369    let content_type = resp
370        .headers()
371        .get("content-type")
372        .and_then(|v| v.to_str().ok())
373        .unwrap_or("application/octet-stream");
374    let content_type = super::ContentType::from(content_type);
375
376    if !status.is_client_error() && !status.is_server_error() {
377        let content = resp.text().await?;
378        match content_type {
379            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
380            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetWorkflow200Response`"))),
381            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetWorkflow200Response`")))),
382        }
383    } else {
384        let content = resp.text().await?;
385        let entity: Option<GetWorkflowError> = serde_json::from_str(&content).ok();
386        Err(Error::ResponseError(ResponseContent {
387            status,
388            content,
389            entity,
390        }))
391    }
392}
393
394/// Returns the full snapshot for a single historical version, including the graph.
395pub async fn get_workflow_version(
396    configuration: &configuration::Configuration,
397    workflow_id: &str,
398    version: i32,
399) -> Result<models::GetWorkflowVersion200Response, Error<GetWorkflowVersionError>> {
400    // add a prefix to parameters to efficiently prevent name collisions
401    let p_path_workflow_id = workflow_id;
402    let p_path_version = version;
403
404    let uri_str = format!(
405        "{}/v1/workflows/{workflowId}/versions/{version}",
406        configuration.base_path,
407        workflowId = crate::apis::urlencode(p_path_workflow_id),
408        version = p_path_version
409    );
410    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
411
412    if let Some(ref user_agent) = configuration.user_agent {
413        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
414    }
415    if let Some(ref token) = configuration.bearer_access_token {
416        req_builder = req_builder.bearer_auth(token.to_owned());
417    };
418
419    let req = req_builder.build()?;
420    let resp = configuration.client.execute(req).await?;
421
422    let status = resp.status();
423    let content_type = resp
424        .headers()
425        .get("content-type")
426        .and_then(|v| v.to_str().ok())
427        .unwrap_or("application/octet-stream");
428    let content_type = super::ContentType::from(content_type);
429
430    if !status.is_client_error() && !status.is_server_error() {
431        let content = resp.text().await?;
432        match content_type {
433            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
434            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetWorkflowVersion200Response`"))),
435            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetWorkflowVersion200Response`")))),
436        }
437    } else {
438        let content = resp.text().await?;
439        let entity: Option<GetWorkflowVersionError> = serde_json::from_str(&content).ok();
440        Err(Error::ResponseError(ResponseContent {
441            status,
442            content,
443            entity,
444        }))
445    }
446}
447
448/// Returns the per-step run-log for a single workflow execution: trigger fired, each node visited, edge handles taken, errors, and durations. Backed by Tinybird (90-day retention). Used by the Runs UI drawer to render the timeline.
449pub async fn list_workflow_execution_events(
450    configuration: &configuration::Configuration,
451    workflow_id: &str,
452    execution_id: &str,
453) -> Result<models::ListWorkflowExecutionEvents200Response, Error<ListWorkflowExecutionEventsError>>
454{
455    // add a prefix to parameters to efficiently prevent name collisions
456    let p_path_workflow_id = workflow_id;
457    let p_path_execution_id = execution_id;
458
459    let uri_str = format!(
460        "{}/v1/workflows/{workflowId}/executions/{executionId}/events",
461        configuration.base_path,
462        workflowId = crate::apis::urlencode(p_path_workflow_id),
463        executionId = crate::apis::urlencode(p_path_execution_id)
464    );
465    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
466
467    if let Some(ref user_agent) = configuration.user_agent {
468        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
469    }
470    if let Some(ref token) = configuration.bearer_access_token {
471        req_builder = req_builder.bearer_auth(token.to_owned());
472    };
473
474    let req = req_builder.build()?;
475    let resp = configuration.client.execute(req).await?;
476
477    let status = resp.status();
478    let content_type = resp
479        .headers()
480        .get("content-type")
481        .and_then(|v| v.to_str().ok())
482        .unwrap_or("application/octet-stream");
483    let content_type = super::ContentType::from(content_type);
484
485    if !status.is_client_error() && !status.is_server_error() {
486        let content = resp.text().await?;
487        match content_type {
488            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
489            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListWorkflowExecutionEvents200Response`"))),
490            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListWorkflowExecutionEvents200Response`")))),
491        }
492    } else {
493        let content = resp.text().await?;
494        let entity: Option<ListWorkflowExecutionEventsError> = serde_json::from_str(&content).ok();
495        Err(Error::ResponseError(ResponseContent {
496            status,
497            content,
498            entity,
499        }))
500    }
501}
502
503/// Returns recent executions (runs) with their status, current node, and accumulated variables.
504pub async fn list_workflow_executions(
505    configuration: &configuration::Configuration,
506    workflow_id: &str,
507    status: Option<&str>,
508    limit: Option<i32>,
509    skip: Option<i32>,
510) -> Result<models::ListWorkflowExecutions200Response, Error<ListWorkflowExecutionsError>> {
511    // add a prefix to parameters to efficiently prevent name collisions
512    let p_path_workflow_id = workflow_id;
513    let p_query_status = status;
514    let p_query_limit = limit;
515    let p_query_skip = skip;
516
517    let uri_str = format!(
518        "{}/v1/workflows/{workflowId}/executions",
519        configuration.base_path,
520        workflowId = crate::apis::urlencode(p_path_workflow_id)
521    );
522    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
523
524    if let Some(ref param_value) = p_query_status {
525        req_builder = req_builder.query(&[("status", &param_value.to_string())]);
526    }
527    if let Some(ref param_value) = p_query_limit {
528        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
529    }
530    if let Some(ref param_value) = p_query_skip {
531        req_builder = req_builder.query(&[("skip", &param_value.to_string())]);
532    }
533    if let Some(ref user_agent) = configuration.user_agent {
534        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
535    }
536    if let Some(ref token) = configuration.bearer_access_token {
537        req_builder = req_builder.bearer_auth(token.to_owned());
538    };
539
540    let req = req_builder.build()?;
541    let resp = configuration.client.execute(req).await?;
542
543    let status = resp.status();
544    let content_type = resp
545        .headers()
546        .get("content-type")
547        .and_then(|v| v.to_str().ok())
548        .unwrap_or("application/octet-stream");
549    let content_type = super::ContentType::from(content_type);
550
551    if !status.is_client_error() && !status.is_server_error() {
552        let content = resp.text().await?;
553        match content_type {
554            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
555            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListWorkflowExecutions200Response`"))),
556            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListWorkflowExecutions200Response`")))),
557        }
558    } else {
559        let content = resp.text().await?;
560        let entity: Option<ListWorkflowExecutionsError> = serde_json::from_str(&content).ok();
561        Err(Error::ResponseError(ResponseContent {
562            status,
563            content,
564            entity,
565        }))
566    }
567}
568
569/// Returns the snapshot history. A new version is recorded automatically before every PATCH to `nodes` / `edges` / `entryNodeId`, and explicitly when a previous version is restored. Lightweight list — call `getWorkflowVersion` for the full snapshot graph.
570pub async fn list_workflow_versions(
571    configuration: &configuration::Configuration,
572    workflow_id: &str,
573) -> Result<models::ListWorkflowVersions200Response, Error<ListWorkflowVersionsError>> {
574    // add a prefix to parameters to efficiently prevent name collisions
575    let p_path_workflow_id = workflow_id;
576
577    let uri_str = format!(
578        "{}/v1/workflows/{workflowId}/versions",
579        configuration.base_path,
580        workflowId = crate::apis::urlencode(p_path_workflow_id)
581    );
582    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
583
584    if let Some(ref user_agent) = configuration.user_agent {
585        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
586    }
587    if let Some(ref token) = configuration.bearer_access_token {
588        req_builder = req_builder.bearer_auth(token.to_owned());
589    };
590
591    let req = req_builder.build()?;
592    let resp = configuration.client.execute(req).await?;
593
594    let status = resp.status();
595    let content_type = resp
596        .headers()
597        .get("content-type")
598        .and_then(|v| v.to_str().ok())
599        .unwrap_or("application/octet-stream");
600    let content_type = super::ContentType::from(content_type);
601
602    if !status.is_client_error() && !status.is_server_error() {
603        let content = resp.text().await?;
604        match content_type {
605            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
606            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListWorkflowVersions200Response`"))),
607            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListWorkflowVersions200Response`")))),
608        }
609    } else {
610        let content = resp.text().await?;
611        let entity: Option<ListWorkflowVersionsError> = serde_json::from_str(&content).ok();
612        Err(Error::ResponseError(ResponseContent {
613            status,
614            content,
615            entity,
616        }))
617    }
618}
619
620/// Returns workflows with run stats. Filter by status or profile.
621pub async fn list_workflows(
622    configuration: &configuration::Configuration,
623    profile_id: Option<&str>,
624    status: Option<&str>,
625    limit: Option<i32>,
626    skip: Option<i32>,
627) -> Result<models::ListWorkflows200Response, Error<ListWorkflowsError>> {
628    // add a prefix to parameters to efficiently prevent name collisions
629    let p_query_profile_id = profile_id;
630    let p_query_status = status;
631    let p_query_limit = limit;
632    let p_query_skip = skip;
633
634    let uri_str = format!("{}/v1/workflows", configuration.base_path);
635    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
636
637    if let Some(ref param_value) = p_query_profile_id {
638        req_builder = req_builder.query(&[("profileId", &param_value.to_string())]);
639    }
640    if let Some(ref param_value) = p_query_status {
641        req_builder = req_builder.query(&[("status", &param_value.to_string())]);
642    }
643    if let Some(ref param_value) = p_query_limit {
644        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
645    }
646    if let Some(ref param_value) = p_query_skip {
647        req_builder = req_builder.query(&[("skip", &param_value.to_string())]);
648    }
649    if let Some(ref user_agent) = configuration.user_agent {
650        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
651    }
652    if let Some(ref token) = configuration.bearer_access_token {
653        req_builder = req_builder.bearer_auth(token.to_owned());
654    };
655
656    let req = req_builder.build()?;
657    let resp = configuration.client.execute(req).await?;
658
659    let status = resp.status();
660    let content_type = resp
661        .headers()
662        .get("content-type")
663        .and_then(|v| v.to_str().ok())
664        .unwrap_or("application/octet-stream");
665    let content_type = super::ContentType::from(content_type);
666
667    if !status.is_client_error() && !status.is_server_error() {
668        let content = resp.text().await?;
669        match content_type {
670            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
671            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListWorkflows200Response`"))),
672            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListWorkflows200Response`")))),
673        }
674    } else {
675        let content = resp.text().await?;
676        let entity: Option<ListWorkflowsError> = serde_json::from_str(&content).ok();
677        Err(Error::ResponseError(ResponseContent {
678            status,
679            content,
680            entity,
681        }))
682    }
683}
684
685/// Stop matching new inbound messages. In-flight executions continue to completion. Idempotent.
686pub async fn pause_workflow(
687    configuration: &configuration::Configuration,
688    workflow_id: &str,
689) -> Result<models::PauseWorkflow200Response, Error<PauseWorkflowError>> {
690    // add a prefix to parameters to efficiently prevent name collisions
691    let p_path_workflow_id = workflow_id;
692
693    let uri_str = format!(
694        "{}/v1/workflows/{workflowId}/pause",
695        configuration.base_path,
696        workflowId = crate::apis::urlencode(p_path_workflow_id)
697    );
698    let mut req_builder = configuration
699        .client
700        .request(reqwest::Method::POST, &uri_str);
701
702    if let Some(ref user_agent) = configuration.user_agent {
703        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
704    }
705    if let Some(ref token) = configuration.bearer_access_token {
706        req_builder = req_builder.bearer_auth(token.to_owned());
707    };
708
709    let req = req_builder.build()?;
710    let resp = configuration.client.execute(req).await?;
711
712    let status = resp.status();
713    let content_type = resp
714        .headers()
715        .get("content-type")
716        .and_then(|v| v.to_str().ok())
717        .unwrap_or("application/octet-stream");
718    let content_type = super::ContentType::from(content_type);
719
720    if !status.is_client_error() && !status.is_server_error() {
721        let content = resp.text().await?;
722        match content_type {
723            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
724            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PauseWorkflow200Response`"))),
725            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::PauseWorkflow200Response`")))),
726        }
727    } else {
728        let content = resp.text().await?;
729        let entity: Option<PauseWorkflowError> = serde_json::from_str(&content).ok();
730        Err(Error::ResponseError(ResponseContent {
731            status,
732            content,
733            entity,
734        }))
735    }
736}
737
738/// Replace the current graph with the named version's snapshot. Before the swap, the current graph is itself snapshotted as a new version, so a restore is reversible. The workflow must be in `draft` or `paused` status (same gate as a normal graph edit). The returned workflow carries `restoredFromVersion` so the UI can surface which version was rolled back to.
739pub async fn restore_workflow_version(
740    configuration: &configuration::Configuration,
741    workflow_id: &str,
742    version: i32,
743) -> Result<models::RestoreWorkflowVersion200Response, Error<RestoreWorkflowVersionError>> {
744    // add a prefix to parameters to efficiently prevent name collisions
745    let p_path_workflow_id = workflow_id;
746    let p_path_version = version;
747
748    let uri_str = format!(
749        "{}/v1/workflows/{workflowId}/versions/{version}/restore",
750        configuration.base_path,
751        workflowId = crate::apis::urlencode(p_path_workflow_id),
752        version = p_path_version
753    );
754    let mut req_builder = configuration
755        .client
756        .request(reqwest::Method::POST, &uri_str);
757
758    if let Some(ref user_agent) = configuration.user_agent {
759        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
760    }
761    if let Some(ref token) = configuration.bearer_access_token {
762        req_builder = req_builder.bearer_auth(token.to_owned());
763    };
764
765    let req = req_builder.build()?;
766    let resp = configuration.client.execute(req).await?;
767
768    let status = resp.status();
769    let content_type = resp
770        .headers()
771        .get("content-type")
772        .and_then(|v| v.to_str().ok())
773        .unwrap_or("application/octet-stream");
774    let content_type = super::ContentType::from(content_type);
775
776    if !status.is_client_error() && !status.is_server_error() {
777        let content = resp.text().await?;
778        match content_type {
779            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
780            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RestoreWorkflowVersion200Response`"))),
781            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RestoreWorkflowVersion200Response`")))),
782        }
783    } else {
784        let content = resp.text().await?;
785        let entity: Option<RestoreWorkflowVersionError> = serde_json::from_str(&content).ok();
786        Err(Error::ResponseError(ResponseContent {
787            status,
788            content,
789            entity,
790        }))
791    }
792}
793
794/// Kick off a run without waiting for an inbound message (useful for testing). Target an existing conversation by `conversationId`, or — WhatsApp only — a phone number via `to` (a conversation is found or created). `text` seeds the run's `lastMessage` variable. The graph must be runnable.
795pub async fn trigger_workflow(
796    configuration: &configuration::Configuration,
797    workflow_id: &str,
798    trigger_workflow_request: models::TriggerWorkflowRequest,
799) -> Result<models::TriggerWorkflow200Response, Error<TriggerWorkflowError>> {
800    // add a prefix to parameters to efficiently prevent name collisions
801    let p_path_workflow_id = workflow_id;
802    let p_body_trigger_workflow_request = trigger_workflow_request;
803
804    let uri_str = format!(
805        "{}/v1/workflows/{workflowId}/executions",
806        configuration.base_path,
807        workflowId = crate::apis::urlencode(p_path_workflow_id)
808    );
809    let mut req_builder = configuration
810        .client
811        .request(reqwest::Method::POST, &uri_str);
812
813    if let Some(ref user_agent) = configuration.user_agent {
814        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
815    }
816    if let Some(ref token) = configuration.bearer_access_token {
817        req_builder = req_builder.bearer_auth(token.to_owned());
818    };
819    req_builder = req_builder.json(&p_body_trigger_workflow_request);
820
821    let req = req_builder.build()?;
822    let resp = configuration.client.execute(req).await?;
823
824    let status = resp.status();
825    let content_type = resp
826        .headers()
827        .get("content-type")
828        .and_then(|v| v.to_str().ok())
829        .unwrap_or("application/octet-stream");
830    let content_type = super::ContentType::from(content_type);
831
832    if !status.is_client_error() && !status.is_server_error() {
833        let content = resp.text().await?;
834        match content_type {
835            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
836            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TriggerWorkflow200Response`"))),
837            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::TriggerWorkflow200Response`")))),
838        }
839    } else {
840        let content = resp.text().await?;
841        let entity: Option<TriggerWorkflowError> = serde_json::from_str(&content).ok();
842        Err(Error::ResponseError(ResponseContent {
843            status,
844            content,
845            entity,
846        }))
847    }
848}
849
850/// Update name, description, the graph, or reassign to a different account. The graph can only be modified while the workflow is draft or paused. Account swaps re-validate the graph against the new platform (so e.g. moving from WhatsApp to Facebook surfaces a `start_call` node as an error instead of silently saving an unrunnable graph).
851pub async fn update_workflow(
852    configuration: &configuration::Configuration,
853    workflow_id: &str,
854    update_workflow_request: Option<models::UpdateWorkflowRequest>,
855) -> Result<models::UpdateWorkflow200Response, Error<UpdateWorkflowError>> {
856    // add a prefix to parameters to efficiently prevent name collisions
857    let p_path_workflow_id = workflow_id;
858    let p_body_update_workflow_request = update_workflow_request;
859
860    let uri_str = format!(
861        "{}/v1/workflows/{workflowId}",
862        configuration.base_path,
863        workflowId = crate::apis::urlencode(p_path_workflow_id)
864    );
865    let mut req_builder = configuration
866        .client
867        .request(reqwest::Method::PATCH, &uri_str);
868
869    if let Some(ref user_agent) = configuration.user_agent {
870        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
871    }
872    if let Some(ref token) = configuration.bearer_access_token {
873        req_builder = req_builder.bearer_auth(token.to_owned());
874    };
875    req_builder = req_builder.json(&p_body_update_workflow_request);
876
877    let req = req_builder.build()?;
878    let resp = configuration.client.execute(req).await?;
879
880    let status = resp.status();
881    let content_type = resp
882        .headers()
883        .get("content-type")
884        .and_then(|v| v.to_str().ok())
885        .unwrap_or("application/octet-stream");
886    let content_type = super::ContentType::from(content_type);
887
888    if !status.is_client_error() && !status.is_server_error() {
889        let content = resp.text().await?;
890        match content_type {
891            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
892            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UpdateWorkflow200Response`"))),
893            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::UpdateWorkflow200Response`")))),
894        }
895    } else {
896        let content = resp.text().await?;
897        let entity: Option<UpdateWorkflowError> = serde_json::from_str(&content).ok();
898        Err(Error::ResponseError(ResponseContent {
899            status,
900            content,
901            entity,
902        }))
903    }
904}