amazon_spapi/apis/
product_pricing_v0.rs

1/*
2 * Selling Partner API for Pricing
3 *
4 * The Selling Partner API for Pricing helps you programmatically retrieve product pricing and offer information for Amazon Marketplace products.
5 *
6 * The version of the OpenAPI document: v0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`get_competitive_pricing`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetCompetitivePricingError {
22    Status400(models::product_pricing_v0::GetPricingResponse),
23    Status401(models::product_pricing_v0::GetPricingResponse),
24    Status403(models::product_pricing_v0::GetPricingResponse),
25    Status404(models::product_pricing_v0::GetPricingResponse),
26    Status429(models::product_pricing_v0::GetPricingResponse),
27    Status500(models::product_pricing_v0::GetPricingResponse),
28    Status503(models::product_pricing_v0::GetPricingResponse),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_item_offers`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetItemOffersError {
36    Status400(models::product_pricing_v0::GetOffersResponse),
37    Status401(models::product_pricing_v0::GetOffersResponse),
38    Status403(models::product_pricing_v0::GetOffersResponse),
39    Status404(models::product_pricing_v0::GetOffersResponse),
40    Status429(models::product_pricing_v0::GetOffersResponse),
41    Status500(models::product_pricing_v0::GetOffersResponse),
42    Status503(models::product_pricing_v0::GetOffersResponse),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`get_item_offers_batch`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetItemOffersBatchError {
50    Status400(models::product_pricing_v0::Errors),
51    Status401(models::product_pricing_v0::Errors),
52    Status403(models::product_pricing_v0::Errors),
53    Status404(models::product_pricing_v0::Errors),
54    Status429(models::product_pricing_v0::Errors),
55    Status500(models::product_pricing_v0::Errors),
56    Status503(models::product_pricing_v0::Errors),
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`get_listing_offers`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum GetListingOffersError {
64    Status400(models::product_pricing_v0::GetOffersResponse),
65    Status401(models::product_pricing_v0::GetOffersResponse),
66    Status403(models::product_pricing_v0::GetOffersResponse),
67    Status404(models::product_pricing_v0::GetOffersResponse),
68    Status429(models::product_pricing_v0::GetOffersResponse),
69    Status500(models::product_pricing_v0::GetOffersResponse),
70    Status503(models::product_pricing_v0::GetOffersResponse),
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`get_listing_offers_batch`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum GetListingOffersBatchError {
78    Status400(models::product_pricing_v0::Errors),
79    Status401(models::product_pricing_v0::Errors),
80    Status403(models::product_pricing_v0::Errors),
81    Status404(models::product_pricing_v0::Errors),
82    Status429(models::product_pricing_v0::Errors),
83    Status500(models::product_pricing_v0::Errors),
84    Status503(models::product_pricing_v0::Errors),
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`get_pricing`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum GetPricingError {
92    Status400(models::product_pricing_v0::GetPricingResponse),
93    Status401(models::product_pricing_v0::GetPricingResponse),
94    Status403(models::product_pricing_v0::GetPricingResponse),
95    Status404(models::product_pricing_v0::GetPricingResponse),
96    Status429(models::product_pricing_v0::GetPricingResponse),
97    Status500(models::product_pricing_v0::GetPricingResponse),
98    Status503(models::product_pricing_v0::GetPricingResponse),
99    UnknownValue(serde_json::Value),
100}
101
102
103/// 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).
104pub 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>> {
105    // add a prefix to parameters to efficiently prevent name collisions
106    let p_marketplace_id = marketplace_id;
107    let p_item_type = item_type;
108    let p_asins = asins;
109    let p_skus = skus;
110    let p_customer_type = customer_type;
111
112    let uri_str = format!("{}/products/pricing/v0/competitivePrice", configuration.base_path);
113    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
114
115    req_builder = req_builder.query(&[("MarketplaceId", &p_marketplace_id.to_string())]);
116    if let Some(ref param_value) = p_asins {
117        req_builder = match "csv" {
118            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("Asins".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
119            _ => req_builder.query(&[("Asins", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
120        };
121    }
122    if let Some(ref param_value) = p_skus {
123        req_builder = match "csv" {
124            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("Skus".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
125            _ => req_builder.query(&[("Skus", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
126        };
127    }
128    req_builder = req_builder.query(&[("ItemType", &p_item_type.to_string())]);
129    if let Some(ref param_value) = p_customer_type {
130        req_builder = req_builder.query(&[("CustomerType", &param_value.to_string())]);
131    }
132    if let Some(ref user_agent) = configuration.user_agent {
133        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
134    }
135
136    let req = req_builder.build()?;
137    let resp = configuration.client.execute(req).await?;
138
139    let status = resp.status();
140    let content_type = resp
141        .headers()
142        .get("content-type")
143        .and_then(|v| v.to_str().ok())
144        .unwrap_or("application/octet-stream");
145    let content_type = super::ContentType::from(content_type);
146
147    if !status.is_client_error() && !status.is_server_error() {
148        let content = resp.text().await?;
149        match content_type {
150            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
151            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`"))),
152            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`")))),
153        }
154    } else {
155        let content = resp.text().await?;
156        let entity: Option<GetCompetitivePricingError> = serde_json::from_str(&content).ok();
157        Err(Error::ResponseError(ResponseContent { status, content, entity }))
158    }
159}
160
161/// 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).
162pub 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>> {
163    // add a prefix to parameters to efficiently prevent name collisions
164    let p_marketplace_id = marketplace_id;
165    let p_item_condition = item_condition;
166    let p_asin = asin;
167    let p_customer_type = customer_type;
168
169    let uri_str = format!("{}/products/pricing/v0/items/{Asin}/offers", configuration.base_path, Asin=crate::apis::urlencode(p_asin));
170    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
171
172    req_builder = req_builder.query(&[("MarketplaceId", &p_marketplace_id.to_string())]);
173    req_builder = req_builder.query(&[("ItemCondition", &p_item_condition.to_string())]);
174    if let Some(ref param_value) = p_customer_type {
175        req_builder = req_builder.query(&[("CustomerType", &param_value.to_string())]);
176    }
177    if let Some(ref user_agent) = configuration.user_agent {
178        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
179    }
180
181    let req = req_builder.build()?;
182    let resp = configuration.client.execute(req).await?;
183
184    let status = resp.status();
185    let content_type = resp
186        .headers()
187        .get("content-type")
188        .and_then(|v| v.to_str().ok())
189        .unwrap_or("application/octet-stream");
190    let content_type = super::ContentType::from(content_type);
191
192    if !status.is_client_error() && !status.is_server_error() {
193        let content = resp.text().await?;
194        match content_type {
195            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
196            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`"))),
197            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`")))),
198        }
199    } else {
200        let content = resp.text().await?;
201        let entity: Option<GetItemOffersError> = serde_json::from_str(&content).ok();
202        Err(Error::ResponseError(ResponseContent { status, content, entity }))
203    }
204}
205
206/// 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).
207pub 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>> {
208    // add a prefix to parameters to efficiently prevent name collisions
209    let p_get_item_offers_batch_request_body = get_item_offers_batch_request_body;
210
211    let uri_str = format!("{}/batches/products/pricing/v0/itemOffers", configuration.base_path);
212    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
213
214    if let Some(ref user_agent) = configuration.user_agent {
215        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
216    }
217    req_builder = req_builder.json(&p_get_item_offers_batch_request_body);
218
219    let req = req_builder.build()?;
220    let resp = configuration.client.execute(req).await?;
221
222    let status = resp.status();
223    let content_type = resp
224        .headers()
225        .get("content-type")
226        .and_then(|v| v.to_str().ok())
227        .unwrap_or("application/octet-stream");
228    let content_type = super::ContentType::from(content_type);
229
230    if !status.is_client_error() && !status.is_server_error() {
231        let content = resp.text().await?;
232        match content_type {
233            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
234            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`"))),
235            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`")))),
236        }
237    } else {
238        let content = resp.text().await?;
239        let entity: Option<GetItemOffersBatchError> = serde_json::from_str(&content).ok();
240        Err(Error::ResponseError(ResponseContent { status, content, entity }))
241    }
242}
243
244/// 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).
245pub 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>> {
246    // add a prefix to parameters to efficiently prevent name collisions
247    let p_marketplace_id = marketplace_id;
248    let p_item_condition = item_condition;
249    let p_seller_sku = seller_sku;
250    let p_customer_type = customer_type;
251
252    let uri_str = format!("{}/products/pricing/v0/listings/{SellerSKU}/offers", configuration.base_path, SellerSKU=crate::apis::urlencode(p_seller_sku));
253    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
254
255    req_builder = req_builder.query(&[("MarketplaceId", &p_marketplace_id.to_string())]);
256    req_builder = req_builder.query(&[("ItemCondition", &p_item_condition.to_string())]);
257    if let Some(ref param_value) = p_customer_type {
258        req_builder = req_builder.query(&[("CustomerType", &param_value.to_string())]);
259    }
260    if let Some(ref user_agent) = configuration.user_agent {
261        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
262    }
263
264    let req = req_builder.build()?;
265    let resp = configuration.client.execute(req).await?;
266
267    let status = resp.status();
268    let content_type = resp
269        .headers()
270        .get("content-type")
271        .and_then(|v| v.to_str().ok())
272        .unwrap_or("application/octet-stream");
273    let content_type = super::ContentType::from(content_type);
274
275    if !status.is_client_error() && !status.is_server_error() {
276        let content = resp.text().await?;
277        match content_type {
278            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
279            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`"))),
280            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`")))),
281        }
282    } else {
283        let content = resp.text().await?;
284        let entity: Option<GetListingOffersError> = serde_json::from_str(&content).ok();
285        Err(Error::ResponseError(ResponseContent { status, content, entity }))
286    }
287}
288
289/// 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).
290pub 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>> {
291    // add a prefix to parameters to efficiently prevent name collisions
292    let p_get_listing_offers_batch_request_body = get_listing_offers_batch_request_body;
293
294    let uri_str = format!("{}/batches/products/pricing/v0/listingOffers", configuration.base_path);
295    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
296
297    if let Some(ref user_agent) = configuration.user_agent {
298        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
299    }
300    req_builder = req_builder.json(&p_get_listing_offers_batch_request_body);
301
302    let req = req_builder.build()?;
303    let resp = configuration.client.execute(req).await?;
304
305    let status = resp.status();
306    let content_type = resp
307        .headers()
308        .get("content-type")
309        .and_then(|v| v.to_str().ok())
310        .unwrap_or("application/octet-stream");
311    let content_type = super::ContentType::from(content_type);
312
313    if !status.is_client_error() && !status.is_server_error() {
314        let content = resp.text().await?;
315        match content_type {
316            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
317            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`"))),
318            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`")))),
319        }
320    } else {
321        let content = resp.text().await?;
322        let entity: Option<GetListingOffersBatchError> = serde_json::from_str(&content).ok();
323        Err(Error::ResponseError(ResponseContent { status, content, entity }))
324    }
325}
326
327/// 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).
328pub 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>> {
329    // add a prefix to parameters to efficiently prevent name collisions
330    let p_marketplace_id = marketplace_id;
331    let p_item_type = item_type;
332    let p_asins = asins;
333    let p_skus = skus;
334    let p_item_condition = item_condition;
335    let p_offer_type = offer_type;
336
337    let uri_str = format!("{}/products/pricing/v0/price", configuration.base_path);
338    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
339
340    req_builder = req_builder.query(&[("MarketplaceId", &p_marketplace_id.to_string())]);
341    if let Some(ref param_value) = p_asins {
342        req_builder = match "csv" {
343            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("Asins".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
344            _ => req_builder.query(&[("Asins", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
345        };
346    }
347    if let Some(ref param_value) = p_skus {
348        req_builder = match "csv" {
349            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("Skus".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
350            _ => req_builder.query(&[("Skus", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
351        };
352    }
353    req_builder = req_builder.query(&[("ItemType", &p_item_type.to_string())]);
354    if let Some(ref param_value) = p_item_condition {
355        req_builder = req_builder.query(&[("ItemCondition", &param_value.to_string())]);
356    }
357    if let Some(ref param_value) = p_offer_type {
358        req_builder = req_builder.query(&[("OfferType", &param_value.to_string())]);
359    }
360    if let Some(ref user_agent) = configuration.user_agent {
361        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
362    }
363
364    let req = req_builder.build()?;
365    let resp = configuration.client.execute(req).await?;
366
367    let status = resp.status();
368    let content_type = resp
369        .headers()
370        .get("content-type")
371        .and_then(|v| v.to_str().ok())
372        .unwrap_or("application/octet-stream");
373    let content_type = super::ContentType::from(content_type);
374
375    if !status.is_client_error() && !status.is_server_error() {
376        let content = resp.text().await?;
377        match content_type {
378            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
379            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`"))),
380            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`")))),
381        }
382    } else {
383        let content = resp.text().await?;
384        let entity: Option<GetPricingError> = serde_json::from_str(&content).ok();
385        Err(Error::ResponseError(ResponseContent { status, content, entity }))
386    }
387}
388