amazon_spapi/apis/
product_fees_v0.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 GetMyFeesEstimateForAsinError {
22 Status400(models::product_fees_v0::GetMyFeesEstimateResponse),
23 Status401(models::product_fees_v0::GetMyFeesEstimateResponse),
24 Status403(models::product_fees_v0::GetMyFeesEstimateResponse),
25 Status404(models::product_fees_v0::GetMyFeesEstimateResponse),
26 Status429(models::product_fees_v0::GetMyFeesEstimateResponse),
27 Status500(models::product_fees_v0::GetMyFeesEstimateResponse),
28 Status503(models::product_fees_v0::GetMyFeesEstimateResponse),
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetMyFeesEstimateForSkuError {
36 Status400(models::product_fees_v0::GetMyFeesEstimateResponse),
37 Status401(models::product_fees_v0::GetMyFeesEstimateResponse),
38 Status403(models::product_fees_v0::GetMyFeesEstimateResponse),
39 Status404(models::product_fees_v0::GetMyFeesEstimateResponse),
40 Status429(models::product_fees_v0::GetMyFeesEstimateResponse),
41 Status500(models::product_fees_v0::GetMyFeesEstimateResponse),
42 Status503(models::product_fees_v0::GetMyFeesEstimateResponse),
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetMyFeesEstimatesError {
50 Status400(models::product_fees_v0::GetMyFeesEstimatesErrorList),
51 Status401(models::product_fees_v0::GetMyFeesEstimatesErrorList),
52 Status403(models::product_fees_v0::GetMyFeesEstimatesErrorList),
53 Status404(models::product_fees_v0::GetMyFeesEstimatesErrorList),
54 Status429(models::product_fees_v0::GetMyFeesEstimatesErrorList),
55 Status500(models::product_fees_v0::GetMyFeesEstimatesErrorList),
56 Status503(models::product_fees_v0::GetMyFeesEstimatesErrorList),
57 UnknownValue(serde_json::Value),
58}
59
60
61pub async fn get_my_fees_estimate_for_asin(configuration: &configuration::Configuration, asin: &str, body: models::product_fees_v0::GetMyFeesEstimateRequest) -> Result<models::product_fees_v0::GetMyFeesEstimateResponse, Error<GetMyFeesEstimateForAsinError>> {
63 let p_asin = asin;
65 let p_body = body;
66
67 let uri_str = format!("{}/products/fees/v0/items/{Asin}/feesEstimate", configuration.base_path, Asin=crate::apis::urlencode(p_asin));
68 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
69
70 if let Some(ref user_agent) = configuration.user_agent {
71 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
72 }
73 req_builder = req_builder.json(&p_body);
74
75 let req = req_builder.build()?;
76 let resp = configuration.client.execute(req).await?;
77
78 let status = resp.status();
79 let content_type = resp
80 .headers()
81 .get("content-type")
82 .and_then(|v| v.to_str().ok())
83 .unwrap_or("application/octet-stream");
84 let content_type = super::ContentType::from(content_type);
85
86 if !status.is_client_error() && !status.is_server_error() {
87 let content = resp.text().await?;
88 match content_type {
89 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
90 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::product_fees_v0::GetMyFeesEstimateResponse`"))),
91 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::product_fees_v0::GetMyFeesEstimateResponse`")))),
92 }
93 } else {
94 let content = resp.text().await?;
95 let entity: Option<GetMyFeesEstimateForAsinError> = serde_json::from_str(&content).ok();
96 Err(Error::ResponseError(ResponseContent { status, content, entity }))
97 }
98}
99
100pub async fn get_my_fees_estimate_for_sku(configuration: &configuration::Configuration, seller_sku: &str, body: models::product_fees_v0::GetMyFeesEstimateRequest) -> Result<models::product_fees_v0::GetMyFeesEstimateResponse, Error<GetMyFeesEstimateForSkuError>> {
102 let p_seller_sku = seller_sku;
104 let p_body = body;
105
106 let uri_str = format!("{}/products/fees/v0/listings/{SellerSKU}/feesEstimate", configuration.base_path, SellerSKU=crate::apis::urlencode(p_seller_sku));
107 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
108
109 if let Some(ref user_agent) = configuration.user_agent {
110 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
111 }
112 req_builder = req_builder.json(&p_body);
113
114 let req = req_builder.build()?;
115 let resp = configuration.client.execute(req).await?;
116
117 let status = resp.status();
118 let content_type = resp
119 .headers()
120 .get("content-type")
121 .and_then(|v| v.to_str().ok())
122 .unwrap_or("application/octet-stream");
123 let content_type = super::ContentType::from(content_type);
124
125 if !status.is_client_error() && !status.is_server_error() {
126 let content = resp.text().await?;
127 match content_type {
128 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
129 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::product_fees_v0::GetMyFeesEstimateResponse`"))),
130 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::product_fees_v0::GetMyFeesEstimateResponse`")))),
131 }
132 } else {
133 let content = resp.text().await?;
134 let entity: Option<GetMyFeesEstimateForSkuError> = serde_json::from_str(&content).ok();
135 Err(Error::ResponseError(ResponseContent { status, content, entity }))
136 }
137}
138
139pub async fn get_my_fees_estimates(configuration: &configuration::Configuration, body: Vec<models::product_fees_v0::FeesEstimateByIdRequest>) -> Result<Vec<models::product_fees_v0::FeesEstimateResult>, Error<GetMyFeesEstimatesError>> {
141 let p_body = body;
143
144 let uri_str = format!("{}/products/fees/v0/feesEstimate", configuration.base_path);
145 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
146
147 if let Some(ref user_agent) = configuration.user_agent {
148 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
149 }
150 req_builder = req_builder.json(&p_body);
151
152 let req = req_builder.build()?;
153 let resp = configuration.client.execute(req).await?;
154
155 let status = resp.status();
156 let content_type = resp
157 .headers()
158 .get("content-type")
159 .and_then(|v| v.to_str().ok())
160 .unwrap_or("application/octet-stream");
161 let content_type = super::ContentType::from(content_type);
162
163 if !status.is_client_error() && !status.is_server_error() {
164 let content = resp.text().await?;
165 match content_type {
166 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
167 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::product_fees_v0::FeesEstimateResult>`"))),
168 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::product_fees_v0::FeesEstimateResult>`")))),
169 }
170 } else {
171 let content = resp.text().await?;
172 let entity: Option<GetMyFeesEstimatesError> = serde_json::from_str(&content).ok();
173 Err(Error::ResponseError(ResponseContent { status, content, entity }))
174 }
175}
176