/*
* 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.162.2
* 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 [`bulk_create_contacts`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum BulkCreateContactsError {
Status400(),
Status401(models::InlineObject1),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`create_contact`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateContactError {
Status400(),
Status401(models::InlineObject1),
Status409(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_contact`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteContactError {
Status400(),
Status401(models::InlineObject1),
Status404(models::InlineObject2),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_contact`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetContactError {
Status400(),
Status401(models::InlineObject1),
Status404(models::InlineObject2),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_contact_channels`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetContactChannelsError {
Status400(),
Status401(models::InlineObject1),
Status404(models::InlineObject2),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_contacts`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListContactsError {
Status400(),
Status401(models::InlineObject1),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`update_contact`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateContactError {
Status400(),
Status401(models::InlineObject1),
Status404(models::InlineObject2),
UnknownValue(serde_json::Value),
}
/// Import up to 1000 contacts at a time. Skips duplicates, merging any new tags onto the existing contact. accountId is required whenever contacts carry a platformIdentifier (or a row-level accountId); platform is always derived from the resolved account, never used to decide whether channels are created, and a mismatched platform 404s as account not found. When accountId is set, each contact must carry a platformIdentifier; a row missing it is rejected individually (reported in errors[], HTTP 200), not a 400 for the whole import. On phone platforms (whatsapp, sms) the platformIdentifier is normalized to digits and a value that is not phone-shaped is rejected per contact and reported in errors[], not imported.
pub async fn bulk_create_contacts(
configuration: &configuration::Configuration,
bulk_create_contacts_request: models::BulkCreateContactsRequest,
) -> Result<models::BulkCreateContacts200Response, Error<BulkCreateContactsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_bulk_create_contacts_request = bulk_create_contacts_request;
let uri_str = format!("{}/v1/contacts/bulk", 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(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_bulk_create_contacts_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::BulkCreateContacts200Response`"))),
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::BulkCreateContacts200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<BulkCreateContactsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Create a new contact. Optionally create a platform channel in the same request by providing accountId, platform, and platformIdentifier.
pub async fn create_contact(
configuration: &configuration::Configuration,
create_contact_request: models::CreateContactRequest,
) -> Result<models::CreateContact200Response, Error<CreateContactError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_create_contact_request = create_contact_request;
let uri_str = format!("{}/v1/contacts", 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(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_create_contact_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::CreateContact200Response`"))),
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::CreateContact200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CreateContactError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Permanently deletes a contact and all associated channels.
pub async fn delete_contact(
configuration: &configuration::Configuration,
contact_id: &str,
) -> Result<(), Error<DeleteContactError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_contact_id = contact_id;
let uri_str = format!(
"{}/v1/contacts/{contactId}",
configuration.base_path,
contactId = crate::apis::urlencode(p_path_contact_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();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<DeleteContactError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns a contact with all associated messaging channels.
pub async fn get_contact(
configuration: &configuration::Configuration,
contact_id: &str,
) -> Result<models::GetContact200Response, Error<GetContactError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_contact_id = contact_id;
let uri_str = format!(
"{}/v1/contacts/{contactId}",
configuration.base_path,
contactId = crate::apis::urlencode(p_path_contact_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::GetContact200Response`"))),
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::GetContact200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetContactError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Returns all messaging channels linked to a contact (e.g. Instagram DM, Telegram, WhatsApp).
pub async fn get_contact_channels(
configuration: &configuration::Configuration,
contact_id: &str,
) -> Result<models::GetContactChannels200Response, Error<GetContactChannelsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_contact_id = contact_id;
let uri_str = format!(
"{}/v1/contacts/{contactId}/channels",
configuration.base_path,
contactId = crate::apis::urlencode(p_path_contact_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::GetContactChannels200Response`"))),
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::GetContactChannels200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetContactChannelsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// List and search contacts for a profile. Supports filtering by tags, platform, subscription status, and text search on name, email and company.
pub async fn list_contacts(
configuration: &configuration::Configuration,
profile_id: Option<&str>,
account_id: Option<&str>,
search: Option<&str>,
tag: Option<&str>,
tags: Option<&str>,
platform: Option<&str>,
is_subscribed: Option<&str>,
limit: Option<i32>,
skip: Option<i32>,
) -> Result<models::ListContacts200Response, Error<ListContactsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_profile_id = profile_id;
let p_query_account_id = account_id;
let p_query_search = search;
let p_query_tag = tag;
let p_query_tags = tags;
let p_query_platform = platform;
let p_query_is_subscribed = is_subscribed;
let p_query_limit = limit;
let p_query_skip = skip;
let uri_str = format!("{}/v1/contacts", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_profile_id {
req_builder = req_builder.query(&[("profileId", ¶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_search {
req_builder = req_builder.query(&[("search", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_tag {
req_builder = req_builder.query(&[("tag", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_tags {
req_builder = req_builder.query(&[("tags", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_platform {
req_builder = req_builder.query(&[("platform", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_is_subscribed {
req_builder = req_builder.query(&[("isSubscribed", ¶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_skip {
req_builder = req_builder.query(&[("skip", ¶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::ListContacts200Response`"))),
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::ListContacts200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListContactsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
/// Update one or more fields on a contact. Only provided fields are changed.
pub async fn update_contact(
configuration: &configuration::Configuration,
contact_id: &str,
update_contact_request: Option<models::UpdateContactRequest>,
) -> Result<models::UpdateContact200Response, Error<UpdateContactError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_contact_id = contact_id;
let p_body_update_contact_request = update_contact_request;
let uri_str = format!(
"{}/v1/contacts/{contactId}",
configuration.base_path,
contactId = crate::apis::urlencode(p_path_contact_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_contact_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::UpdateContact200Response`"))),
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::UpdateContact200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UpdateContactError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}