Skip to main content

late/apis/
accounts_api.rs

1/*
2 * Zernio API
3 *
4 * API reference for Zernio. Authenticate with a Bearer API key. Base URL: https://zernio.com/api
5 *
6 * The version of the OpenAPI document: 1.0.3
7 * Contact: support@zernio.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`delete_account`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum DeleteAccountError {
20    Status401(models::InlineObject),
21    Status404(models::InlineObject1),
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_account_health`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetAccountHealthError {
29    Status401(models::InlineObject),
30    Status404(models::InlineObject1),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`get_all_accounts_health`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetAllAccountsHealthError {
38    Status401(models::InlineObject),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`get_follower_stats`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetFollowerStatsError {
46    Status401(models::InlineObject),
47    Status403(models::GetFollowerStats403Response),
48    UnknownValue(serde_json::Value),
49}
50
51/// struct for typed errors of method [`get_tik_tok_creator_info`]
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum GetTikTokCreatorInfoError {
55    Status400(models::GetYouTubeDailyViews400Response),
56    Status401(models::InlineObject),
57    Status404(models::InlineObject1),
58    Status429(models::GetYouTubeDailyViews400Response),
59    UnknownValue(serde_json::Value),
60}
61
62/// struct for typed errors of method [`list_accounts`]
63#[derive(Debug, Clone, Serialize, Deserialize)]
64#[serde(untagged)]
65pub enum ListAccountsError {
66    Status401(models::InlineObject),
67    UnknownValue(serde_json::Value),
68}
69
70/// struct for typed errors of method [`move_account_to_profile`]
71#[derive(Debug, Clone, Serialize, Deserialize)]
72#[serde(untagged)]
73pub enum MoveAccountToProfileError {
74    Status400(),
75    Status401(models::InlineObject),
76    Status403(),
77    Status404(),
78    UnknownValue(serde_json::Value),
79}
80
81/// struct for typed errors of method [`update_account`]
82#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum UpdateAccountError {
85    Status400(),
86    Status401(models::InlineObject),
87    Status404(models::InlineObject1),
88    UnknownValue(serde_json::Value),
89}
90
91/// Disconnects and removes a connected social account.
92pub async fn delete_account(
93    configuration: &configuration::Configuration,
94    account_id: &str,
95) -> Result<models::DeleteAccountGroup200Response, Error<DeleteAccountError>> {
96    // add a prefix to parameters to efficiently prevent name collisions
97    let p_path_account_id = account_id;
98
99    let uri_str = format!(
100        "{}/v1/accounts/{accountId}",
101        configuration.base_path,
102        accountId = crate::apis::urlencode(p_path_account_id)
103    );
104    let mut req_builder = configuration
105        .client
106        .request(reqwest::Method::DELETE, &uri_str);
107
108    if let Some(ref user_agent) = configuration.user_agent {
109        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
110    }
111    if let Some(ref token) = configuration.bearer_access_token {
112        req_builder = req_builder.bearer_auth(token.to_owned());
113    };
114
115    let req = req_builder.build()?;
116    let resp = configuration.client.execute(req).await?;
117
118    let status = resp.status();
119    let content_type = resp
120        .headers()
121        .get("content-type")
122        .and_then(|v| v.to_str().ok())
123        .unwrap_or("application/octet-stream");
124    let content_type = super::ContentType::from(content_type);
125
126    if !status.is_client_error() && !status.is_server_error() {
127        let content = resp.text().await?;
128        match content_type {
129            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
130            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteAccountGroup200Response`"))),
131            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::DeleteAccountGroup200Response`")))),
132        }
133    } else {
134        let content = resp.text().await?;
135        let entity: Option<DeleteAccountError> = serde_json::from_str(&content).ok();
136        Err(Error::ResponseError(ResponseContent {
137            status,
138            content,
139            entity,
140        }))
141    }
142}
143
144/// Returns detailed health info for a specific account including token status, permissions, and recommendations.
145pub async fn get_account_health(
146    configuration: &configuration::Configuration,
147    account_id: &str,
148) -> Result<models::GetAccountHealth200Response, Error<GetAccountHealthError>> {
149    // add a prefix to parameters to efficiently prevent name collisions
150    let p_path_account_id = account_id;
151
152    let uri_str = format!(
153        "{}/v1/accounts/{accountId}/health",
154        configuration.base_path,
155        accountId = crate::apis::urlencode(p_path_account_id)
156    );
157    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
158
159    if let Some(ref user_agent) = configuration.user_agent {
160        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
161    }
162    if let Some(ref token) = configuration.bearer_access_token {
163        req_builder = req_builder.bearer_auth(token.to_owned());
164    };
165
166    let req = req_builder.build()?;
167    let resp = configuration.client.execute(req).await?;
168
169    let status = resp.status();
170    let content_type = resp
171        .headers()
172        .get("content-type")
173        .and_then(|v| v.to_str().ok())
174        .unwrap_or("application/octet-stream");
175    let content_type = super::ContentType::from(content_type);
176
177    if !status.is_client_error() && !status.is_server_error() {
178        let content = resp.text().await?;
179        match content_type {
180            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
181            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetAccountHealth200Response`"))),
182            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::GetAccountHealth200Response`")))),
183        }
184    } else {
185        let content = resp.text().await?;
186        let entity: Option<GetAccountHealthError> = serde_json::from_str(&content).ok();
187        Err(Error::ResponseError(ResponseContent {
188            status,
189            content,
190            entity,
191        }))
192    }
193}
194
195/// Returns health status of all connected accounts including token validity, permissions, and issues needing attention.
196pub async fn get_all_accounts_health(
197    configuration: &configuration::Configuration,
198    profile_id: Option<&str>,
199    platform: Option<&str>,
200    status: Option<&str>,
201) -> Result<models::GetAllAccountsHealth200Response, Error<GetAllAccountsHealthError>> {
202    // add a prefix to parameters to efficiently prevent name collisions
203    let p_query_profile_id = profile_id;
204    let p_query_platform = platform;
205    let p_query_status = status;
206
207    let uri_str = format!("{}/v1/accounts/health", configuration.base_path);
208    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
209
210    if let Some(ref param_value) = p_query_profile_id {
211        req_builder = req_builder.query(&[("profileId", &param_value.to_string())]);
212    }
213    if let Some(ref param_value) = p_query_platform {
214        req_builder = req_builder.query(&[("platform", &param_value.to_string())]);
215    }
216    if let Some(ref param_value) = p_query_status {
217        req_builder = req_builder.query(&[("status", &param_value.to_string())]);
218    }
219    if let Some(ref user_agent) = configuration.user_agent {
220        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
221    }
222    if let Some(ref token) = configuration.bearer_access_token {
223        req_builder = req_builder.bearer_auth(token.to_owned());
224    };
225
226    let req = req_builder.build()?;
227    let resp = configuration.client.execute(req).await?;
228
229    let status = resp.status();
230    let content_type = resp
231        .headers()
232        .get("content-type")
233        .and_then(|v| v.to_str().ok())
234        .unwrap_or("application/octet-stream");
235    let content_type = super::ContentType::from(content_type);
236
237    if !status.is_client_error() && !status.is_server_error() {
238        let content = resp.text().await?;
239        match content_type {
240            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
241            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetAllAccountsHealth200Response`"))),
242            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::GetAllAccountsHealth200Response`")))),
243        }
244    } else {
245        let content = resp.text().await?;
246        let entity: Option<GetAllAccountsHealthError> = serde_json::from_str(&content).ok();
247        Err(Error::ResponseError(ResponseContent {
248            status,
249            content,
250            entity,
251        }))
252    }
253}
254
255/// Returns follower count history and growth metrics for connected social accounts. Requires analytics add-on subscription. Follower counts are refreshed once per day.
256pub async fn get_follower_stats(
257    configuration: &configuration::Configuration,
258    account_ids: Option<&str>,
259    profile_id: Option<&str>,
260    from_date: Option<String>,
261    to_date: Option<String>,
262    granularity: Option<&str>,
263) -> Result<models::GetFollowerStats200Response, Error<GetFollowerStatsError>> {
264    // add a prefix to parameters to efficiently prevent name collisions
265    let p_query_account_ids = account_ids;
266    let p_query_profile_id = profile_id;
267    let p_query_from_date = from_date;
268    let p_query_to_date = to_date;
269    let p_query_granularity = granularity;
270
271    let uri_str = format!("{}/v1/accounts/follower-stats", configuration.base_path);
272    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
273
274    if let Some(ref param_value) = p_query_account_ids {
275        req_builder = req_builder.query(&[("accountIds", &param_value.to_string())]);
276    }
277    if let Some(ref param_value) = p_query_profile_id {
278        req_builder = req_builder.query(&[("profileId", &param_value.to_string())]);
279    }
280    if let Some(ref param_value) = p_query_from_date {
281        req_builder = req_builder.query(&[("fromDate", &param_value.to_string())]);
282    }
283    if let Some(ref param_value) = p_query_to_date {
284        req_builder = req_builder.query(&[("toDate", &param_value.to_string())]);
285    }
286    if let Some(ref param_value) = p_query_granularity {
287        req_builder = req_builder.query(&[("granularity", &param_value.to_string())]);
288    }
289    if let Some(ref user_agent) = configuration.user_agent {
290        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
291    }
292    if let Some(ref token) = configuration.bearer_access_token {
293        req_builder = req_builder.bearer_auth(token.to_owned());
294    };
295
296    let req = req_builder.build()?;
297    let resp = configuration.client.execute(req).await?;
298
299    let status = resp.status();
300    let content_type = resp
301        .headers()
302        .get("content-type")
303        .and_then(|v| v.to_str().ok())
304        .unwrap_or("application/octet-stream");
305    let content_type = super::ContentType::from(content_type);
306
307    if !status.is_client_error() && !status.is_server_error() {
308        let content = resp.text().await?;
309        match content_type {
310            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
311            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetFollowerStats200Response`"))),
312            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::GetFollowerStats200Response`")))),
313        }
314    } else {
315        let content = resp.text().await?;
316        let entity: Option<GetFollowerStatsError> = serde_json::from_str(&content).ok();
317        Err(Error::ResponseError(ResponseContent {
318            status,
319            content,
320            entity,
321        }))
322    }
323}
324
325/// Returns TikTok creator details, available privacy levels, posting limits, and commercial content options for a specific TikTok account. Only works with TikTok accounts.
326pub async fn get_tik_tok_creator_info(
327    configuration: &configuration::Configuration,
328    account_id: &str,
329    media_type: Option<&str>,
330) -> Result<models::GetTikTokCreatorInfo200Response, Error<GetTikTokCreatorInfoError>> {
331    // add a prefix to parameters to efficiently prevent name collisions
332    let p_path_account_id = account_id;
333    let p_query_media_type = media_type;
334
335    let uri_str = format!(
336        "{}/v1/accounts/{accountId}/tiktok/creator-info",
337        configuration.base_path,
338        accountId = crate::apis::urlencode(p_path_account_id)
339    );
340    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
341
342    if let Some(ref param_value) = p_query_media_type {
343        req_builder = req_builder.query(&[("mediaType", &param_value.to_string())]);
344    }
345    if let Some(ref user_agent) = configuration.user_agent {
346        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
347    }
348    if let Some(ref token) = configuration.bearer_access_token {
349        req_builder = req_builder.bearer_auth(token.to_owned());
350    };
351
352    let req = req_builder.build()?;
353    let resp = configuration.client.execute(req).await?;
354
355    let status = resp.status();
356    let content_type = resp
357        .headers()
358        .get("content-type")
359        .and_then(|v| v.to_str().ok())
360        .unwrap_or("application/octet-stream");
361    let content_type = super::ContentType::from(content_type);
362
363    if !status.is_client_error() && !status.is_server_error() {
364        let content = resp.text().await?;
365        match content_type {
366            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
367            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetTikTokCreatorInfo200Response`"))),
368            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::GetTikTokCreatorInfo200Response`")))),
369        }
370    } else {
371        let content = resp.text().await?;
372        let entity: Option<GetTikTokCreatorInfoError> = serde_json::from_str(&content).ok();
373        Err(Error::ResponseError(ResponseContent {
374            status,
375            content,
376            entity,
377        }))
378    }
379}
380
381/// Returns connected social accounts. Only includes accounts within the plan limit by default. Follower data requires analytics add-on. Supports optional server-side pagination via page/limit params. When omitted, returns all accounts (backward-compatible).
382pub async fn list_accounts(
383    configuration: &configuration::Configuration,
384    profile_id: Option<&str>,
385    platform: Option<&str>,
386    include_over_limit: Option<bool>,
387    page: Option<i32>,
388    limit: Option<i32>,
389) -> Result<models::ListAccounts200Response, Error<ListAccountsError>> {
390    // add a prefix to parameters to efficiently prevent name collisions
391    let p_query_profile_id = profile_id;
392    let p_query_platform = platform;
393    let p_query_include_over_limit = include_over_limit;
394    let p_query_page = page;
395    let p_query_limit = limit;
396
397    let uri_str = format!("{}/v1/accounts", configuration.base_path);
398    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
399
400    if let Some(ref param_value) = p_query_profile_id {
401        req_builder = req_builder.query(&[("profileId", &param_value.to_string())]);
402    }
403    if let Some(ref param_value) = p_query_platform {
404        req_builder = req_builder.query(&[("platform", &param_value.to_string())]);
405    }
406    if let Some(ref param_value) = p_query_include_over_limit {
407        req_builder = req_builder.query(&[("includeOverLimit", &param_value.to_string())]);
408    }
409    if let Some(ref param_value) = p_query_page {
410        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
411    }
412    if let Some(ref param_value) = p_query_limit {
413        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
414    }
415    if let Some(ref user_agent) = configuration.user_agent {
416        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
417    }
418    if let Some(ref token) = configuration.bearer_access_token {
419        req_builder = req_builder.bearer_auth(token.to_owned());
420    };
421
422    let req = req_builder.build()?;
423    let resp = configuration.client.execute(req).await?;
424
425    let status = resp.status();
426    let content_type = resp
427        .headers()
428        .get("content-type")
429        .and_then(|v| v.to_str().ok())
430        .unwrap_or("application/octet-stream");
431    let content_type = super::ContentType::from(content_type);
432
433    if !status.is_client_error() && !status.is_server_error() {
434        let content = resp.text().await?;
435        match content_type {
436            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
437            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListAccounts200Response`"))),
438            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::ListAccounts200Response`")))),
439        }
440    } else {
441        let content = resp.text().await?;
442        let entity: Option<ListAccountsError> = serde_json::from_str(&content).ok();
443        Err(Error::ResponseError(ResponseContent {
444            status,
445            content,
446            entity,
447        }))
448    }
449}
450
451/// Moves a connected social account to a different profile owned by the same user. The target profile must belong to the same user as the account.  For API keys restricted to specific profiles, BOTH the source account's current profile AND the target profile must be in the key's allowed set. Calls with a target profile outside the key's scope return 403.
452pub async fn move_account_to_profile(
453    configuration: &configuration::Configuration,
454    account_id: &str,
455    move_account_to_profile_request: models::MoveAccountToProfileRequest,
456) -> Result<models::MoveAccountToProfile200Response, Error<MoveAccountToProfileError>> {
457    // add a prefix to parameters to efficiently prevent name collisions
458    let p_path_account_id = account_id;
459    let p_body_move_account_to_profile_request = move_account_to_profile_request;
460
461    let uri_str = format!(
462        "{}/v1/accounts/{accountId}",
463        configuration.base_path,
464        accountId = crate::apis::urlencode(p_path_account_id)
465    );
466    let mut req_builder = configuration
467        .client
468        .request(reqwest::Method::PATCH, &uri_str);
469
470    if let Some(ref user_agent) = configuration.user_agent {
471        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
472    }
473    if let Some(ref token) = configuration.bearer_access_token {
474        req_builder = req_builder.bearer_auth(token.to_owned());
475    };
476    req_builder = req_builder.json(&p_body_move_account_to_profile_request);
477
478    let req = req_builder.build()?;
479    let resp = configuration.client.execute(req).await?;
480
481    let status = resp.status();
482    let content_type = resp
483        .headers()
484        .get("content-type")
485        .and_then(|v| v.to_str().ok())
486        .unwrap_or("application/octet-stream");
487    let content_type = super::ContentType::from(content_type);
488
489    if !status.is_client_error() && !status.is_server_error() {
490        let content = resp.text().await?;
491        match content_type {
492            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
493            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MoveAccountToProfile200Response`"))),
494            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::MoveAccountToProfile200Response`")))),
495        }
496    } else {
497        let content = resp.text().await?;
498        let entity: Option<MoveAccountToProfileError> = serde_json::from_str(&content).ok();
499        Err(Error::ResponseError(ResponseContent {
500            status,
501            content,
502            entity,
503        }))
504    }
505}
506
507/// Updates a connected social account's display name or username override.  For X/Twitter accounts on usage-based billing, also accepts an `xCapabilities` object to toggle background API operations that incur X API pass-through costs. Both fields are opt-in (default `false`) — when off, no analytics syncs or DM polling are performed for that account, and no API call is metered for those operations. Publishing and deleting posts are always available regardless of these toggles. Setting `xCapabilities` on a non-X account returns 400.
508pub async fn update_account(
509    configuration: &configuration::Configuration,
510    account_id: &str,
511    update_account_request: models::UpdateAccountRequest,
512) -> Result<models::UpdateAccount200Response, Error<UpdateAccountError>> {
513    // add a prefix to parameters to efficiently prevent name collisions
514    let p_path_account_id = account_id;
515    let p_body_update_account_request = update_account_request;
516
517    let uri_str = format!(
518        "{}/v1/accounts/{accountId}",
519        configuration.base_path,
520        accountId = crate::apis::urlencode(p_path_account_id)
521    );
522    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
523
524    if let Some(ref user_agent) = configuration.user_agent {
525        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
526    }
527    if let Some(ref token) = configuration.bearer_access_token {
528        req_builder = req_builder.bearer_auth(token.to_owned());
529    };
530    req_builder = req_builder.json(&p_body_update_account_request);
531
532    let req = req_builder.build()?;
533    let resp = configuration.client.execute(req).await?;
534
535    let status = resp.status();
536    let content_type = resp
537        .headers()
538        .get("content-type")
539        .and_then(|v| v.to_str().ok())
540        .unwrap_or("application/octet-stream");
541    let content_type = super::ContentType::from(content_type);
542
543    if !status.is_client_error() && !status.is_server_error() {
544        let content = resp.text().await?;
545        match content_type {
546            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
547            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UpdateAccount200Response`"))),
548            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::UpdateAccount200Response`")))),
549        }
550    } else {
551        let content = resp.text().await?;
552        let entity: Option<UpdateAccountError> = serde_json::from_str(&content).ok();
553        Err(Error::ResponseError(ResponseContent {
554            status,
555            content,
556            entity,
557        }))
558    }
559}