/*
* Zernio API
*
* API reference for Zernio. Authenticate with a Bearer API key. Base URL: https://zernio.com/api Versioning and deprecation: all endpoints are versioned in the URL path (current version: /v1). Breaking changes only ship in a new path version; existing versions keep working. Deprecated operations are marked 'deprecated: true' in this spec and announced in the changelog (https://zernio.com/changelog) before removal. Errors: every 4xx/5xx response is application/json with a machine-readable 'code' and a human-readable 'error' message (see the ErrorResponse schema). Request ids: responses carry an X-Request-Id header with the id we log the request under. Quote it when reporting a problem. A valid x-request-id you send is reused as that id.
*
* The version of the OpenAPI document: 1.522.0
* Contact: support@zernio.com
* Generated by: https://openapi-generator.tech
*/
use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};
/// struct for typed errors of method [`activate_automation`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ActivateAutomationError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status403(models::ErrorResponse),
Status404(models::InlineObject1),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`approve_automation_approval`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ApproveAutomationApprovalError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status403(models::ErrorResponse),
Status404(models::InlineObject1),
Status409(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`backtest_automation`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum BacktestAutomationError {
Status400(models::InstallAutomationTemplate400Response),
Status401(models::ErrorResponse),
Status403(models::ErrorResponse),
Status404(models::InlineObject1),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`backtest_automation_draft`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum BacktestAutomationDraftError {
Status400(models::InstallAutomationTemplate400Response),
Status401(models::ErrorResponse),
Status403(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`create_automation`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateAutomationError {
Status400(models::InstallAutomationTemplate400Response),
Status401(models::ErrorResponse),
Status403(models::ErrorResponse),
Status409(),
Status422(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`create_automation_template`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateAutomationTemplateError {
Status400(models::InstallAutomationTemplate400Response),
Status401(models::ErrorResponse),
Status404(models::ErrorResponse),
Status409(models::ErrorResponse),
Status422(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_automation`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteAutomationError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status404(models::InlineObject1),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_automation_template`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteAutomationTemplateError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status404(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_automation`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAutomationError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status404(models::InlineObject1),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_automation_approval`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAutomationApprovalError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status404(models::InlineObject1),
Status409(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_automation_catalog`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAutomationCatalogError {
Status401(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_automation_controls`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAutomationControlsError {
Status401(models::ErrorResponse),
Status403(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_automation_template`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAutomationTemplateError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status404(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_shared_automation_template`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetSharedAutomationTemplateError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status404(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_zernio_automation_template`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetZernioAutomationTemplateError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status404(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`install_automation_template`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum InstallAutomationTemplateError {
Status400(models::InstallAutomationTemplate400Response),
Status401(models::ErrorResponse),
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status409(),
Status422(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`install_shared_automation_template`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum InstallSharedAutomationTemplateError {
Status400(models::InstallAutomationTemplate400Response),
Status401(models::ErrorResponse),
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status409(),
Status422(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`install_zernio_automation_template`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum InstallZernioAutomationTemplateError {
Status400(models::InstallAutomationTemplate400Response),
Status401(models::ErrorResponse),
Status403(models::ErrorResponse),
Status404(models::ErrorResponse),
Status409(),
Status422(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_automation_actions`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListAutomationActionsError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_automation_approvals`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListAutomationApprovalsError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status404(models::InlineObject1),
Status409(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_automation_checks`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListAutomationChecksError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status404(models::InlineObject1),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_automation_templates`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListAutomationTemplatesError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_automations`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListAutomationsError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`pause_automation`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PauseAutomationError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status404(models::InlineObject1),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`preview_automation`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PreviewAutomationError {
Status400(models::InstallAutomationTemplate400Response),
Status401(models::ErrorResponse),
Status403(models::ErrorResponse),
Status404(models::InlineObject1),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`preview_automation_draft`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PreviewAutomationDraftError {
Status400(models::InstallAutomationTemplate400Response),
Status401(models::ErrorResponse),
Status403(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`reject_automation_approval`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RejectAutomationApprovalError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status403(models::ErrorResponse),
Status404(models::InlineObject1),
Status409(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`update_automation`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateAutomationError {
Status400(models::InstallAutomationTemplate400Response),
Status401(models::ErrorResponse),
Status403(models::ErrorResponse),
Status404(models::InlineObject1),
Status409(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`update_automation_ad_account_controls`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateAutomationAdAccountControlsError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status403(models::ErrorResponse),
Status404(models::InlineObject1),
Status409(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`update_automation_controls`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateAutomationControlsError {
Status400(models::ErrorResponse),
Status401(models::ErrorResponse),
Status403(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`update_automation_template`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateAutomationTemplateError {
Status400(models::InstallAutomationTemplate400Response),
Status401(models::ErrorResponse),
Status404(models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// An ad rule's first check runs right away.
pub async fn activate_automation(
configuration: &configuration::Configuration,
automation_id: &str,
) -> Result<models::CreateAutomation201Response, Error<ActivateAutomationError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_automation_id = automation_id;
let uri_str = format!(
"{}/v1/automations/{automationId}/activate",
configuration.base_path,
automationId = crate::apis::urlencode(p_path_automation_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateAutomation201Response`"))),
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::CreateAutomation201Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ActivateAutomationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Approves a pending request, so the automation acts on each change it holds. Each change is checked again first, and one that no longer applies is skipped. Only the approvers the automation names now can decide, matched by the email of the user behind the API key. A request already decided, expired or cancelled is refused with nothing changed. Each applied or failed change fires `automation.action.applied` or `automation.action.failed`.
pub async fn approve_automation_approval(
configuration: &configuration::Configuration,
automation_id: &str,
approval_id: &str,
automation_approval_decision: Option<models::AutomationApprovalDecision>,
) -> Result<models::GetAutomationApproval200Response, Error<ApproveAutomationApprovalError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_automation_id = automation_id;
let p_path_approval_id = approval_id;
let p_body_automation_approval_decision = automation_approval_decision;
let uri_str = format!(
"{}/v1/automations/{automationId}/approvals/{approvalId}/approve",
configuration.base_path,
automationId = crate::apis::urlencode(p_path_automation_id),
approvalId = crate::apis::urlencode(p_path_approval_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_automation_approval_decision);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetAutomationApproval200Response`"))),
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::GetAutomationApproval200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ApproveAutomationApprovalError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// What a saved automation would have done over the last `days` days, replayed on stored daily metrics. Nothing is changed. Each day lists what it would have done. Its own changes carry into later days, but the metrics stay what really happened. `notes` says what the replay could not know. Only ad automations can be backtested, on at most 5,000 ads.
pub async fn backtest_automation(
configuration: &configuration::Configuration,
automation_id: &str,
days: Option<i32>,
) -> Result<models::AutomationBacktest, Error<BacktestAutomationError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_automation_id = automation_id;
let p_query_days = days;
let uri_str = format!(
"{}/v1/automations/{automationId}/backtest",
configuration.base_path,
automationId = crate::apis::urlencode(p_path_automation_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref param_value) = p_query_days {
req_builder = req_builder.query(&[("days", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AutomationBacktest`"))),
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::AutomationBacktest`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<BacktestAutomationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Replays an automation over past days on stored daily metrics, without saving it or changing anything. It refuses what saving would refuse. Each day lists what it would have done. Its own changes carry into later days, but the metrics stay what really happened. `notes` says what the replay could not know. Only ad automations can be backtested, on at most 5,000 ads.
pub async fn backtest_automation_draft(
configuration: &configuration::Configuration,
automation_definition: models::AutomationDefinition,
days: Option<i32>,
) -> Result<models::AutomationBacktest, Error<BacktestAutomationDraftError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_automation_definition = automation_definition;
let p_query_days = days;
let uri_str = format!("{}/v1/automations/backtest", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref param_value) = p_query_days {
req_builder = req_builder.query(&[("days", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_automation_definition);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AutomationBacktest`"))),
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::AutomationBacktest`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<BacktestAutomationDraftError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Creates an automation. Its shape picks the kind: - **Ad rule**: a `schedule` over campaigns, ad sets or ads, with metric `conditions` and ad `steps`. It stays paused unless `status` is `active`; preview it first with `POST /v1/automations/preview`. - **Event**: a Zernio event in `trigger.type`, such as `post.failed`, with notify steps. It is on unless `status` is `paused`. - **Scheduled**: a `schedule` over a profile's posts, with notify steps and an optional boost. It is on unless `status` is `paused`. Everything an automation cannot hold is refused at once: the 400 lists every problem with its JSON path in `details.problems`.
pub async fn create_automation(
configuration: &configuration::Configuration,
automation_definition: models::AutomationDefinition,
idempotency_key: Option<&str>,
) -> Result<models::CreateAutomation201Response, Error<CreateAutomationError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_automation_definition = automation_definition;
let p_header_idempotency_key = idempotency_key;
let uri_str = format!("{}/v1/automations", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(param_value) = p_header_idempotency_key {
req_builder = req_builder.header("Idempotency-Key", param_value.to_string());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_automation_definition);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateAutomation201Response`"))),
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::CreateAutomation201Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CreateAutomationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Saves a reusable setup of one or more automations (up to 20) that your team, or anyone you share it with, can install. Start from your own automations, one of Zernio's templates, a shared template, or definitions sent as they are. Nothing tied to one account is kept. Ad accounts, a trigger's profile and accounts, and alert destinations become `inputs` that each install fills. Campaign ids, id filters, dates and approval steps are dropped. From one of Zernio's templates, each threshold and budget or bid amount also becomes an input, with the template's own value as its default. A template that would not install is refused: the 400 lists every problem in `details.problems`.
pub async fn create_automation_template(
configuration: &configuration::Configuration,
create_automation_template_request: models::CreateAutomationTemplateRequest,
idempotency_key: Option<&str>,
) -> Result<models::CreateAutomationTemplate201Response, Error<CreateAutomationTemplateError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_create_automation_template_request = create_automation_template_request;
let p_header_idempotency_key = idempotency_key;
let uri_str = format!("{}/v1/automations/templates", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(param_value) = p_header_idempotency_key {
req_builder = req_builder.header("Idempotency-Key", param_value.to_string());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_create_automation_template_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateAutomationTemplate201Response`"))),
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::CreateAutomationTemplate201Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CreateAutomationTemplateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn delete_automation(
configuration: &configuration::Configuration,
automation_id: &str,
) -> Result<models::UpdateYoutubeDefaultPlaylist200Response, Error<DeleteAutomationError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_automation_id = automation_id;
let uri_str = format!(
"{}/v1/automations/{automationId}",
configuration.base_path,
automationId = crate::apis::urlencode(p_path_automation_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UpdateYoutubeDefaultPlaylist200Response`"))),
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::UpdateYoutubeDefaultPlaylist200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<DeleteAutomationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Deletes one of your team's templates and its share link. Automations already installed from it stay.
pub async fn delete_automation_template(
configuration: &configuration::Configuration,
template_id: &str,
) -> Result<models::DeleteAutomationTemplate200Response, Error<DeleteAutomationTemplateError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_template_id = template_id;
let uri_str = format!(
"{}/v1/automations/templates/{templateId}",
configuration.base_path,
templateId = crate::apis::urlencode(p_path_template_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteAutomationTemplate200Response`"))),
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::DeleteAutomationTemplate200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<DeleteAutomationTemplateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// An automation installed from a template also carries `template`.
pub async fn get_automation(
configuration: &configuration::Configuration,
automation_id: &str,
) -> Result<models::CreateAutomation201Response, Error<GetAutomationError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_automation_id = automation_id;
let uri_str = format!(
"{}/v1/automations/{automationId}",
configuration.base_path,
automationId = crate::apis::urlencode(p_path_automation_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateAutomation201Response`"))),
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::CreateAutomation201Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetAutomationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// One approval request with the changes it holds, who may decide it and whether you can.
pub async fn get_automation_approval(
configuration: &configuration::Configuration,
automation_id: &str,
approval_id: &str,
) -> Result<models::GetAutomationApproval200Response, Error<GetAutomationApprovalError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_automation_id = automation_id;
let p_path_approval_id = approval_id;
let uri_str = format!(
"{}/v1/automations/{automationId}/approvals/{approvalId}",
configuration.base_path,
automationId = crate::apis::urlencode(p_path_automation_id),
approvalId = crate::apis::urlencode(p_path_approval_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetAutomationApproval200Response`"))),
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::GetAutomationApproval200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetAutomationApprovalError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// What an automation can contain and where each part works, built from the same checks that validate a save, so it never offers what saving refuses. - `schema`: the JSON Schema of the body of `POST /v1/automations`. - `triggers`: every trigger, tagged with its `kind`. Ad rule and scheduled triggers list their intervals; event triggers list each event with its facts. - The other sections describe ad rules: per subject (campaign, ad set, ad) its metrics and steps with the platforms that accept them, plus filters, groups, alerts, conditions, limits and approval.
pub async fn get_automation_catalog(
configuration: &configuration::Configuration,
) -> Result<models::GetAutomationCatalog200Response, Error<GetAutomationCatalogError>> {
let uri_str = format!("{}/v1/automations/catalog", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetAutomationCatalog200Response`"))),
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::GetAutomationCatalog200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetAutomationCatalogError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// The team's switch for every ad rule, and each ad account's own switch and daily raise limit. Boosting automations do not read them. Every team member sees the same controls. `adAccounts` lists each ad account your automations use, plus any ad account that has controls set.
pub async fn get_automation_controls(
configuration: &configuration::Configuration,
) -> Result<models::GetAutomationControls200Response, Error<GetAutomationControlsError>> {
let uri_str = format!("{}/v1/automations/controls", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetAutomationControls200Response`"))),
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::GetAutomationControls200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetAutomationControlsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns one of your team's templates, with its inputs and automations.
pub async fn get_automation_template(
configuration: &configuration::Configuration,
template_id: &str,
) -> Result<models::CreateAutomationTemplate201Response, Error<GetAutomationTemplateError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_template_id = template_id;
let uri_str = format!(
"{}/v1/automations/templates/{templateId}",
configuration.base_path,
templateId = crate::apis::urlencode(p_path_template_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateAutomationTemplate201Response`"))),
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::CreateAutomationTemplate201Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetAutomationTemplateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns a template shared by link, from any team. Who made it and its install counts in that team are left out, and `share` is null.
pub async fn get_shared_automation_template(
configuration: &configuration::Configuration,
share_token: &str,
) -> Result<models::CreateAutomationTemplate201Response, Error<GetSharedAutomationTemplateError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_share_token = share_token;
let uri_str = format!(
"{}/v1/automations/templates/shared/{shareToken}",
configuration.base_path,
shareToken = crate::apis::urlencode(p_path_share_token)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateAutomationTemplate201Response`"))),
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::CreateAutomationTemplate201Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetSharedAutomationTemplateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns one of Zernio's ready-made ad rule templates in the same shape as your own. Each threshold and budget or bid amount is an input with the template's own value as its default, so an install can change it or leave it.
pub async fn get_zernio_automation_template(
configuration: &configuration::Configuration,
template_id: &str,
) -> Result<models::CreateAutomationTemplate201Response, Error<GetZernioAutomationTemplateError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_template_id = template_id;
let uri_str = format!(
"{}/v1/automations/templates/zernio/{templateId}",
configuration.base_path,
templateId = crate::apis::urlencode(p_path_template_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateAutomationTemplate201Response`"))),
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::CreateAutomationTemplate201Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetZernioAutomationTemplateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Creates every automation in the template, with your values in place of its inputs. All or nothing: if one automation fails, the ones already created are removed. New automations stay paused unless `status` is `active`. To install on many ad accounts at once, send `targets` (up to 50). Each target is its own install with its own `inputs`, which win over the shared `inputs`. A failed target leaves the others in place, and the response is 207.
pub async fn install_automation_template(
configuration: &configuration::Configuration,
template_id: &str,
automation_template_install_request: models::AutomationTemplateInstallRequest,
idempotency_key: Option<&str>,
) -> Result<models::AutomationTemplateInstallResponse, Error<InstallAutomationTemplateError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_template_id = template_id;
let p_body_automation_template_install_request = automation_template_install_request;
let p_header_idempotency_key = idempotency_key;
let uri_str = format!(
"{}/v1/automations/templates/{templateId}/install",
configuration.base_path,
templateId = crate::apis::urlencode(p_path_template_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(param_value) = p_header_idempotency_key {
req_builder = req_builder.header("Idempotency-Key", param_value.to_string());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_automation_template_install_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AutomationTemplateInstallResponse`"))),
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::AutomationTemplateInstallResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<InstallAutomationTemplateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Installs a template shared by link into your account, the same way as your own templates. To install on many ad accounts at once, send `targets` (up to 50). Each target is its own install with its own `inputs`, which win over the shared `inputs`. A failed target leaves the others in place, and the response is 207.
pub async fn install_shared_automation_template(
configuration: &configuration::Configuration,
share_token: &str,
automation_template_install_request: models::AutomationTemplateInstallRequest,
idempotency_key: Option<&str>,
) -> Result<models::AutomationTemplateInstallResponse, Error<InstallSharedAutomationTemplateError>>
{
// add a prefix to parameters to efficiently prevent name collisions
let p_path_share_token = share_token;
let p_body_automation_template_install_request = automation_template_install_request;
let p_header_idempotency_key = idempotency_key;
let uri_str = format!(
"{}/v1/automations/templates/shared/{shareToken}/install",
configuration.base_path,
shareToken = crate::apis::urlencode(p_path_share_token)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(param_value) = p_header_idempotency_key {
req_builder = req_builder.header("Idempotency-Key", param_value.to_string());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_automation_template_install_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AutomationTemplateInstallResponse`"))),
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::AutomationTemplateInstallResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<InstallSharedAutomationTemplateError> =
serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Installs one of Zernio's ready-made templates. Leave a value input out to keep the template's default. To install on many ad accounts at once, send `targets` (up to 50). Each target is its own install with its own `inputs`, which win over the shared `inputs`. A failed target leaves the others in place, and the response is 207.
pub async fn install_zernio_automation_template(
configuration: &configuration::Configuration,
template_id: &str,
automation_template_install_request: models::AutomationTemplateInstallRequest,
idempotency_key: Option<&str>,
) -> Result<models::AutomationTemplateInstallResponse, Error<InstallZernioAutomationTemplateError>>
{
// add a prefix to parameters to efficiently prevent name collisions
let p_path_template_id = template_id;
let p_body_automation_template_install_request = automation_template_install_request;
let p_header_idempotency_key = idempotency_key;
let uri_str = format!(
"{}/v1/automations/templates/zernio/{templateId}/install",
configuration.base_path,
templateId = crate::apis::urlencode(p_path_template_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(param_value) = p_header_idempotency_key {
req_builder = req_builder.header("Idempotency-Key", param_value.to_string());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_automation_template_install_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AutomationTemplateInstallResponse`"))),
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::AutomationTemplateInstallResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<InstallZernioAutomationTemplateError> =
serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Every change your ad rules made, newest first: what changed, the value before and after, and whether it was applied, skipped or failed. What event and scheduled automations did is in each one's checks.
pub async fn list_automation_actions(
configuration: &configuration::Configuration,
automation_id: Option<&str>,
account_id: Option<&str>,
r#type: Option<&str>,
from: Option<String>,
to: Option<String>,
limit: Option<i32>,
cursor: Option<&str>,
) -> Result<models::ListAutomationActions200Response, Error<ListAutomationActionsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_automation_id = automation_id;
let p_query_account_id = account_id;
let p_query_type = r#type;
let p_query_from = from;
let p_query_to = to;
let p_query_limit = limit;
let p_query_cursor = cursor;
let uri_str = format!("{}/v1/automations/actions", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_automation_id {
req_builder = req_builder.query(&[("automationId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_type {
req_builder = req_builder.query(&[("type", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_from {
req_builder = req_builder.query(&[("from", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to {
req_builder = req_builder.query(&[("to", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_cursor {
req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListAutomationActions200Response`"))),
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::ListAutomationActions200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListAutomationActionsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// The requests an automation sent for a person's approval before acting, newest first. Each lists the changes it holds, who may decide it and until when. Only automations that ask for approval have requests. Others return 409.
pub async fn list_automation_approvals(
configuration: &configuration::Configuration,
automation_id: &str,
status: Option<&str>,
limit: Option<i32>,
) -> Result<models::ListAutomationApprovals200Response, Error<ListAutomationApprovalsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_automation_id = automation_id;
let p_query_status = status;
let p_query_limit = limit;
let uri_str = format!(
"{}/v1/automations/{automationId}/approvals",
configuration.base_path,
automationId = crate::apis::urlencode(p_path_automation_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_status {
req_builder = req_builder.query(&[("status", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListAutomationApprovals200Response`"))),
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::ListAutomationApprovals200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListAutomationApprovalsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Each time the automation ran, newest first, with what matched and what it did. For an event automation, each check is one event that reached it.
pub async fn list_automation_checks(
configuration: &configuration::Configuration,
automation_id: &str,
limit: Option<i32>,
cursor: Option<&str>,
) -> Result<models::ListAutomationChecks200Response, Error<ListAutomationChecksError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_automation_id = automation_id;
let p_query_limit = limit;
let p_query_cursor = cursor;
let uri_str = format!(
"{}/v1/automations/{automationId}/checks",
configuration.base_path,
automationId = crate::apis::urlencode(p_path_automation_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_cursor {
req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListAutomationChecks200Response`"))),
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::ListAutomationChecks200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListAutomationChecksError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Lists your team's templates, newest first. Every team member sees the templates any member saved. A team keeps up to 200.
pub async fn list_automation_templates(
configuration: &configuration::Configuration,
scope: Option<&str>,
) -> Result<models::ListAutomationTemplates200Response, Error<ListAutomationTemplatesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_scope = scope;
let uri_str = format!("{}/v1/automations/templates", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_scope {
req_builder = req_builder.query(&[("scope", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListAutomationTemplates200Response`"))),
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::ListAutomationTemplates200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListAutomationTemplatesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Lists the automations on the profiles your key can reach, newest first, across every kind: ad rules, event automations and scheduled automations.
pub async fn list_automations(
configuration: &configuration::Configuration,
account_id: Option<&str>,
ad_account_id: Option<&str>,
limit: Option<i32>,
cursor: Option<&str>,
) -> Result<models::ListAutomations200Response, Error<ListAutomationsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_account_id = account_id;
let p_query_ad_account_id = ad_account_id;
let p_query_limit = limit;
let p_query_cursor = cursor;
let uri_str = format!("{}/v1/automations", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_ad_account_id {
req_builder = req_builder.query(&[("adAccountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_cursor {
req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListAutomations200Response`"))),
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::ListAutomations200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListAutomationsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Pausing never needs ads access.
pub async fn pause_automation(
configuration: &configuration::Configuration,
automation_id: &str,
) -> Result<models::CreateAutomation201Response, Error<PauseAutomationError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_automation_id = automation_id;
let uri_str = format!(
"{}/v1/automations/{automationId}/pause",
configuration.base_path,
automationId = crate::apis::urlencode(p_path_automation_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateAutomation201Response`"))),
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::CreateAutomation201Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PauseAutomationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Shows what an ad rule would do if it ran now. Nothing is changed. Event and scheduled automations cannot be previewed yet (400, `not_supported`).
pub async fn preview_automation(
configuration: &configuration::Configuration,
automation_id: &str,
limit: Option<i32>,
) -> Result<models::AutomationPreview, Error<PreviewAutomationError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_automation_id = automation_id;
let p_query_limit = limit;
let uri_str = format!(
"{}/v1/automations/{automationId}/preview",
configuration.base_path,
automationId = crate::apis::urlencode(p_path_automation_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AutomationPreview`"))),
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::AutomationPreview`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PreviewAutomationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Shows what an ad rule would do if it ran now, without saving it or changing anything: every object it checks, each condition with its actual value, and the steps a match would run. It refuses what saving would refuse. Event and scheduled automations cannot be previewed yet (400, `not_supported`).
pub async fn preview_automation_draft(
configuration: &configuration::Configuration,
automation_definition: models::AutomationDefinition,
limit: Option<i32>,
) -> Result<models::AutomationPreview, Error<PreviewAutomationDraftError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_automation_definition = automation_definition;
let p_query_limit = limit;
let uri_str = format!("{}/v1/automations/preview", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_automation_definition);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AutomationPreview`"))),
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::AutomationPreview`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PreviewAutomationDraftError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Rejects a pending request: every change it holds is skipped and nothing is changed on the ad account. Only the approvers the automation names now can decide, matched by the email of the user behind the API key. Rejecting needs no ads access, like pausing.
pub async fn reject_automation_approval(
configuration: &configuration::Configuration,
automation_id: &str,
approval_id: &str,
automation_approval_decision: Option<models::AutomationApprovalDecision>,
) -> Result<models::GetAutomationApproval200Response, Error<RejectAutomationApprovalError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_automation_id = automation_id;
let p_path_approval_id = approval_id;
let p_body_automation_approval_decision = automation_approval_decision;
let uri_str = format!(
"{}/v1/automations/{automationId}/approvals/{approvalId}/reject",
configuration.base_path,
automationId = crate::apis::urlencode(p_path_automation_id),
approvalId = crate::apis::urlencode(p_path_approval_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_automation_approval_decision);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetAutomationApproval200Response`"))),
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::GetAutomationApproval200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<RejectAutomationApprovalError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Replaces the top-level fields you send and keeps the rest: to change one step, send all of `steps`. The result is checked as a whole automation, so problems carry the same paths as on create. An automation keeps its kind, and an ad rule stays on its ad account. Send `alert: null` to remove an ad rule's alert. Send the `version` you read as `If-Match`: if the automation was saved since, the edit is refused with a 409 (`automation_stale`). An edit is also refused with a 409 when another save lands while it is being applied.
pub async fn update_automation(
configuration: &configuration::Configuration,
automation_id: &str,
update_automation_request: models::UpdateAutomationRequest,
if_match: Option<&str>,
) -> Result<models::CreateAutomation201Response, Error<UpdateAutomationError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_automation_id = automation_id;
let p_body_update_automation_request = update_automation_request;
let p_header_if_match = if_match;
let uri_str = format!(
"{}/v1/automations/{automationId}",
configuration.base_path,
automationId = crate::apis::urlencode(p_path_automation_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::PATCH, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(param_value) = p_header_if_match {
req_builder = req_builder.header("If-Match", param_value.to_string());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_update_automation_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateAutomation201Response`"))),
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::CreateAutomation201Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UpdateAutomationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Turns ad rules off or on for one ad account, sets its daily raise limit, or both. Send at least one of `paused` and `dailyRaiseLimit`; fields you leave out keep their value. The ad account must be one the connection in `accountId` reaches, as for an automation on it. Controls apply to every ad rule of the team on that ad account.
pub async fn update_automation_ad_account_controls(
configuration: &configuration::Configuration,
update_automation_ad_account_controls_request: models::UpdateAutomationAdAccountControlsRequest,
) -> Result<models::GetAutomationControls200Response, Error<UpdateAutomationAdAccountControlsError>>
{
// add a prefix to parameters to efficiently prevent name collisions
let p_body_update_automation_ad_account_controls_request =
update_automation_ad_account_controls_request;
let uri_str = format!(
"{}/v1/automations/controls/ad-accounts",
configuration.base_path
);
let mut req_builder = configuration
.client
.request(reqwest::Method::PATCH, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_update_automation_ad_account_controls_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetAutomationControls200Response`"))),
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::GetAutomationControls200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UpdateAutomationAdAccountControlsError> =
serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Turns every ad rule of the team off (`paused: true`) or back on. Each rule keeps its own status, so turning the switch back on resumes exactly the rules that were active. Scheduled automations that boost posts are not stopped by it: pause them one by one. It reaches every profile, so only the account owner or a full-access team member can use it. A key limited to some profiles gets 403. Turning off a switch that is already off keeps its original `pausedAt`.
pub async fn update_automation_controls(
configuration: &configuration::Configuration,
update_automation_controls_request: models::UpdateAutomationControlsRequest,
) -> Result<models::GetAutomationControls200Response, Error<UpdateAutomationControlsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_update_automation_controls_request = update_automation_controls_request;
let uri_str = format!("{}/v1/automations/controls", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::PATCH, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_update_automation_controls_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetAutomationControls200Response`"))),
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::GetAutomationControls200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UpdateAutomationControlsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Renames a template, turns its share link on or off, or replaces its automations. Send at least one field. Renaming or sharing keeps the `version`. New content (`from` or `automations`) is a new version; automations already installed keep the version they came from. `visibility: link` turns the share link on (the same link while it stays on) and `visibility: team` revokes it. To copy a shared template, use `POST /v1/automations/templates` instead.
pub async fn update_automation_template(
configuration: &configuration::Configuration,
template_id: &str,
update_automation_template_request: models::UpdateAutomationTemplateRequest,
) -> Result<models::CreateAutomationTemplate201Response, Error<UpdateAutomationTemplateError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_template_id = template_id;
let p_body_update_automation_template_request = update_automation_template_request;
let uri_str = format!(
"{}/v1/automations/templates/{templateId}",
configuration.base_path,
templateId = crate::apis::urlencode(p_path_template_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::PATCH, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_update_automation_template_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateAutomationTemplate201Response`"))),
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::CreateAutomationTemplate201Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UpdateAutomationTemplateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}