/*
* Selling Partner API for Pricing
*
* The Selling Partner API for Pricing helps you programmatically retrieve product pricing and offer information for Amazon Marketplace products.
*
* 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_competitive_pricing`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCompetitivePricingError {
Status400(models::product_pricing_v0::GetPricingResponse),
Status401(models::product_pricing_v0::GetPricingResponse),
Status403(models::product_pricing_v0::GetPricingResponse),
Status404(models::product_pricing_v0::GetPricingResponse),
Status429(models::product_pricing_v0::GetPricingResponse),
Status500(models::product_pricing_v0::GetPricingResponse),
Status503(models::product_pricing_v0::GetPricingResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_item_offers`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetItemOffersError {
Status400(models::product_pricing_v0::GetOffersResponse),
Status401(models::product_pricing_v0::GetOffersResponse),
Status403(models::product_pricing_v0::GetOffersResponse),
Status404(models::product_pricing_v0::GetOffersResponse),
Status429(models::product_pricing_v0::GetOffersResponse),
Status500(models::product_pricing_v0::GetOffersResponse),
Status503(models::product_pricing_v0::GetOffersResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_item_offers_batch`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetItemOffersBatchError {
Status400(models::product_pricing_v0::Errors),
Status401(models::product_pricing_v0::Errors),
Status403(models::product_pricing_v0::Errors),
Status404(models::product_pricing_v0::Errors),
Status429(models::product_pricing_v0::Errors),
Status500(models::product_pricing_v0::Errors),
Status503(models::product_pricing_v0::Errors),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_listing_offers`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetListingOffersError {
Status400(models::product_pricing_v0::GetOffersResponse),
Status401(models::product_pricing_v0::GetOffersResponse),
Status403(models::product_pricing_v0::GetOffersResponse),
Status404(models::product_pricing_v0::GetOffersResponse),
Status429(models::product_pricing_v0::GetOffersResponse),
Status500(models::product_pricing_v0::GetOffersResponse),
Status503(models::product_pricing_v0::GetOffersResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_listing_offers_batch`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetListingOffersBatchError {
Status400(models::product_pricing_v0::Errors),
Status401(models::product_pricing_v0::Errors),
Status403(models::product_pricing_v0::Errors),
Status404(models::product_pricing_v0::Errors),
Status429(models::product_pricing_v0::Errors),
Status500(models::product_pricing_v0::Errors),
Status503(models::product_pricing_v0::Errors),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_pricing`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetPricingError {
Status400(models::product_pricing_v0::GetPricingResponse),
Status401(models::product_pricing_v0::GetPricingResponse),
Status403(models::product_pricing_v0::GetPricingResponse),
Status404(models::product_pricing_v0::GetPricingResponse),
Status429(models::product_pricing_v0::GetPricingResponse),
Status500(models::product_pricing_v0::GetPricingResponse),
Status503(models::product_pricing_v0::GetPricingResponse),
UnknownValue(serde_json::Value),
}
/// Returns competitive pricing information for a seller's offer listings based on seller SKU or ASIN. **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). **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_competitive_pricing(configuration: &configuration::Configuration, marketplace_id: &str, item_type: &str, asins: Option<Vec<String>>, skus: Option<Vec<String>>, customer_type: Option<&str>) -> Result<models::product_pricing_v0::GetPricingResponse, Error<GetCompetitivePricingError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_marketplace_id = marketplace_id;
let p_item_type = item_type;
let p_asins = asins;
let p_skus = skus;
let p_customer_type = customer_type;
let uri_str = format!("{}/products/pricing/v0/competitivePrice", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("MarketplaceId", &p_marketplace_id.to_string())]);
if let Some(ref param_value) = p_asins {
req_builder = match "csv" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("Asins".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("Asins", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_skus {
req_builder = match "csv" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("Skus".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("Skus", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
req_builder = req_builder.query(&[("ItemType", &p_item_type.to_string())]);
if let Some(ref param_value) = p_customer_type {
req_builder = req_builder.query(&[("CustomerType", ¶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());
}
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_pricing_v0::GetPricingResponse`"))),
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_pricing_v0::GetPricingResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetCompetitivePricingError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns the lowest priced offers for a single item based on ASIN. **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_item_offers(configuration: &configuration::Configuration, marketplace_id: &str, item_condition: &str, asin: &str, customer_type: Option<&str>) -> Result<models::product_pricing_v0::GetOffersResponse, Error<GetItemOffersError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_marketplace_id = marketplace_id;
let p_item_condition = item_condition;
let p_asin = asin;
let p_customer_type = customer_type;
let uri_str = format!("{}/products/pricing/v0/items/{Asin}/offers", configuration.base_path, Asin=crate::apis::urlencode(p_asin));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("MarketplaceId", &p_marketplace_id.to_string())]);
req_builder = req_builder.query(&[("ItemCondition", &p_item_condition.to_string())]);
if let Some(ref param_value) = p_customer_type {
req_builder = req_builder.query(&[("CustomerType", ¶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());
}
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_pricing_v0::GetOffersResponse`"))),
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_pricing_v0::GetOffersResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetItemOffersError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns the lowest priced offers for a batch of items based on ASIN. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 0.1 | 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](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
pub async fn get_item_offers_batch(configuration: &configuration::Configuration, get_item_offers_batch_request_body: models::product_pricing_v0::GetItemOffersBatchRequest) -> Result<models::product_pricing_v0::GetItemOffersBatchResponse, Error<GetItemOffersBatchError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_get_item_offers_batch_request_body = get_item_offers_batch_request_body;
let uri_str = format!("{}/batches/products/pricing/v0/itemOffers", 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_get_item_offers_batch_request_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_pricing_v0::GetItemOffersBatchResponse`"))),
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_pricing_v0::GetItemOffersBatchResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetItemOffersBatchError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns the lowest priced offers for a single SKU listing. **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). **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_listing_offers(configuration: &configuration::Configuration, marketplace_id: &str, item_condition: &str, seller_sku: &str, customer_type: Option<&str>) -> Result<models::product_pricing_v0::GetOffersResponse, Error<GetListingOffersError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_marketplace_id = marketplace_id;
let p_item_condition = item_condition;
let p_seller_sku = seller_sku;
let p_customer_type = customer_type;
let uri_str = format!("{}/products/pricing/v0/listings/{SellerSKU}/offers", configuration.base_path, SellerSKU=crate::apis::urlencode(p_seller_sku));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("MarketplaceId", &p_marketplace_id.to_string())]);
req_builder = req_builder.query(&[("ItemCondition", &p_item_condition.to_string())]);
if let Some(ref param_value) = p_customer_type {
req_builder = req_builder.query(&[("CustomerType", ¶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());
}
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_pricing_v0::GetOffersResponse`"))),
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_pricing_v0::GetOffersResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetListingOffersError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns the lowest priced offers for a batch of listings by SKU. **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_listing_offers_batch(configuration: &configuration::Configuration, get_listing_offers_batch_request_body: models::product_pricing_v0::GetListingOffersBatchRequest) -> Result<models::product_pricing_v0::GetListingOffersBatchResponse, Error<GetListingOffersBatchError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_get_listing_offers_batch_request_body = get_listing_offers_batch_request_body;
let uri_str = format!("{}/batches/products/pricing/v0/listingOffers", 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_get_listing_offers_batch_request_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_pricing_v0::GetListingOffersBatchResponse`"))),
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_pricing_v0::GetListingOffersBatchResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetListingOffersBatchError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns pricing information for a seller's offer listings based on seller SKU or ASIN. **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). **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_pricing(configuration: &configuration::Configuration, marketplace_id: &str, item_type: &str, asins: Option<Vec<String>>, skus: Option<Vec<String>>, item_condition: Option<&str>, offer_type: Option<&str>) -> Result<models::product_pricing_v0::GetPricingResponse, Error<GetPricingError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_marketplace_id = marketplace_id;
let p_item_type = item_type;
let p_asins = asins;
let p_skus = skus;
let p_item_condition = item_condition;
let p_offer_type = offer_type;
let uri_str = format!("{}/products/pricing/v0/price", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("MarketplaceId", &p_marketplace_id.to_string())]);
if let Some(ref param_value) = p_asins {
req_builder = match "csv" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("Asins".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("Asins", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_skus {
req_builder = match "csv" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("Skus".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("Skus", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
req_builder = req_builder.query(&[("ItemType", &p_item_type.to_string())]);
if let Some(ref param_value) = p_item_condition {
req_builder = req_builder.query(&[("ItemCondition", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_offer_type {
req_builder = req_builder.query(&[("OfferType", ¶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());
}
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_pricing_v0::GetPricingResponse`"))),
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_pricing_v0::GetPricingResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetPricingError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}