amazon_spapi/apis/
finances_2024_06_19.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ListTransactionsError {
22 Status400(models::finances_2024_06_19::ErrorList),
23 Status403(models::finances_2024_06_19::ErrorList),
24 Status404(models::finances_2024_06_19::ErrorList),
25 Status415(models::finances_2024_06_19::ErrorList),
26 Status413(models::finances_2024_06_19::ErrorList),
27 Status429(models::finances_2024_06_19::ErrorList),
28 Status500(models::finances_2024_06_19::ErrorList),
29 Status503(models::finances_2024_06_19::ErrorList),
30 UnknownValue(serde_json::Value),
31}
32
33
34pub async fn list_transactions(configuration: &configuration::Configuration, posted_after: String, posted_before: Option<String>, marketplace_id: Option<&str>, transaction_status: Option<&str>, next_token: Option<&str>) -> Result<models::finances_2024_06_19::ListTransactionsResponse, Error<ListTransactionsError>> {
36 let p_posted_after = posted_after;
38 let p_posted_before = posted_before;
39 let p_marketplace_id = marketplace_id;
40 let p_transaction_status = transaction_status;
41 let p_next_token = next_token;
42
43 let uri_str = format!("{}/finances/2024-06-19/transactions", configuration.base_path);
44 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
45
46 req_builder = req_builder.query(&[("postedAfter", &p_posted_after.to_string())]);
47 if let Some(ref param_value) = p_posted_before {
48 req_builder = req_builder.query(&[("postedBefore", ¶m_value.to_string())]);
49 }
50 if let Some(ref param_value) = p_marketplace_id {
51 req_builder = req_builder.query(&[("marketplaceId", ¶m_value.to_string())]);
52 }
53 if let Some(ref param_value) = p_transaction_status {
54 req_builder = req_builder.query(&[("transactionStatus", ¶m_value.to_string())]);
55 }
56 if let Some(ref param_value) = p_next_token {
57 req_builder = req_builder.query(&[("nextToken", ¶m_value.to_string())]);
58 }
59 if let Some(ref user_agent) = configuration.user_agent {
60 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
61 }
62
63 let req = req_builder.build()?;
64 let resp = configuration.client.execute(req).await?;
65
66 let status = resp.status();
67 let content_type = resp
68 .headers()
69 .get("content-type")
70 .and_then(|v| v.to_str().ok())
71 .unwrap_or("application/octet-stream");
72 let content_type = super::ContentType::from(content_type);
73
74 if !status.is_client_error() && !status.is_server_error() {
75 let content = resp.text().await?;
76 match content_type {
77 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
78 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::finances_2024_06_19::ListTransactionsResponse`"))),
79 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::finances_2024_06_19::ListTransactionsResponse`")))),
80 }
81 } else {
82 let content = resp.text().await?;
83 let entity: Option<ListTransactionsError> = serde_json::from_str(&content).ok();
84 Err(Error::ResponseError(ResponseContent { status, content, entity }))
85 }
86}
87