/*
* Selling Partner API for Product Fees
*
* The Selling Partner API for Product Fees lets you programmatically retrieve estimated fees for a product. You can then account for those fees in your pricing.
*
* The version of the OpenAPI document: v0
*
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
/// struct for typed errors of method [`get_my_fees_estimate_for_asin`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetMyFeesEstimateForAsinError {
Status400(models::product_fees_v0::GetMyFeesEstimateResponse),
Status401(models::product_fees_v0::GetMyFeesEstimateResponse),
Status403(models::product_fees_v0::GetMyFeesEstimateResponse),
Status404(models::product_fees_v0::GetMyFeesEstimateResponse),
Status429(models::product_fees_v0::GetMyFeesEstimateResponse),
Status500(models::product_fees_v0::GetMyFeesEstimateResponse),
Status503(models::product_fees_v0::GetMyFeesEstimateResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_my_fees_estimate_for_sku`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetMyFeesEstimateForSkuError {
Status400(models::product_fees_v0::GetMyFeesEstimateResponse),
Status401(models::product_fees_v0::GetMyFeesEstimateResponse),
Status403(models::product_fees_v0::GetMyFeesEstimateResponse),
Status404(models::product_fees_v0::GetMyFeesEstimateResponse),
Status429(models::product_fees_v0::GetMyFeesEstimateResponse),
Status500(models::product_fees_v0::GetMyFeesEstimateResponse),
Status503(models::product_fees_v0::GetMyFeesEstimateResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_my_fees_estimates`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetMyFeesEstimatesError {
Status400(models::product_fees_v0::GetMyFeesEstimatesErrorList),
Status401(models::product_fees_v0::GetMyFeesEstimatesErrorList),
Status403(models::product_fees_v0::GetMyFeesEstimatesErrorList),
Status404(models::product_fees_v0::GetMyFeesEstimatesErrorList),
Status429(models::product_fees_v0::GetMyFeesEstimatesErrorList),
Status500(models::product_fees_v0::GetMyFeesEstimatesErrorList),
Status503(models::product_fees_v0::GetMyFeesEstimatesErrorList),
UnknownValue(serde_json::Value),
}
/// Returns the estimated fees for the item indicated by the specified ASIN in the marketplace specified in the request body. You can call `getMyFeesEstimateForASIN` for an item on behalf of a selling partner before the selling partner sets the item's price. The selling partner can then take estimated fees into account. Each fees request must include an original identifier. This identifier is included in the fees estimate so you can correlate a fees estimate with the original request. **Note:** This identifier value is used to identify an estimate. Actual costs may vary. Search \"fees\" in [Seller Central](https://sellercentral.amazon.com/) and consult the store-specific fee schedule for the most up-to-date information. **Note:** When using the `getMyFeesEstimateForASIN` operation with an ASIN, the fee estimates might be different. This is because these estimates use the item's catalog size, which might not always match the actual size of the item sent to Amazon. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 2 | The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).
pub 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>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_asin = asin;
let p_body = body;
let uri_str = format!("{}/products/fees/v0/items/{Asin}/feesEstimate", configuration.base_path, Asin=crate::apis::urlencode(p_asin));
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());
}
req_builder = req_builder.json(&p_body);
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::product_fees_v0::GetMyFeesEstimateResponse`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetMyFeesEstimateForAsinError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns the estimated fees for the item indicated by the specified seller SKU in the marketplace specified in the request body. **Note:** The parameters associated with this operation may contain special characters that require URL encoding to call the API. To avoid errors with SKUs when encoding URLs, refer to [URL Encoding](https://developer-docs.amazon.com/sp-api/docs/url-encoding). You can call `getMyFeesEstimateForSKU` for an item on behalf of a selling partner before the selling partner sets the item's price. The selling partner can then take any estimated fees into account. Each fees estimate request must include an original identifier. This identifier is included in the fees estimate so that you can correlate a fees estimate with the original request. **Note:** This identifier value is used to identify an estimate. Actual costs may vary. Search \"fees\" in [Seller Central](https://sellercentral.amazon.com/) and consult the store-specific fee schedule for the most up-to-date information. **Note:** When sellers use the `getMyFeesEstimateForSKU` operation with their `SellerSKU`, they get accurate fees based on real item measurements, but only after they've sent their items to Amazon. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 2 | The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).
pub 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>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_seller_sku = seller_sku;
let p_body = body;
let uri_str = format!("{}/products/fees/v0/listings/{SellerSKU}/feesEstimate", configuration.base_path, SellerSKU=crate::apis::urlencode(p_seller_sku));
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());
}
req_builder = req_builder.json(&p_body);
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::product_fees_v0::GetMyFeesEstimateResponse`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetMyFeesEstimateForSkuError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns the estimated fees for a list of products. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 0.5 | 1 | The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](doc:usage-plans-and-rate-limits-in-the-sp-api).
pub 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>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body = body;
let uri_str = format!("{}/products/fees/v0/feesEstimate", 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());
}
req_builder = req_builder.json(&p_body);
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 `Vec<models::product_fees_v0::FeesEstimateResult>`"))),
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>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetMyFeesEstimatesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}