Skip to main content

amazon_spapi/apis/
catalog_items_2022_04_01.rs

1/*
2 * Selling Partner API for Catalog Items
3 *
4 * Use the Selling Partner API for Catalog Items to retrieve information about items in the Amazon catalog.  For more information, refer to the [Catalog Items API Use Case Guide](https://developer-docs.amazon.com/sp-api/docs/:catalog-items-api-v2022-04-01-use-case-guide).
5 *
6 * The version of the OpenAPI document: 2022-04-01
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_catalog_item`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetCatalogItemError {
22    Status400(models::catalog_items_2022_04_01::ErrorList),
23    Status403(models::catalog_items_2022_04_01::ErrorList),
24    Status404(models::catalog_items_2022_04_01::ErrorList),
25    Status413(models::catalog_items_2022_04_01::ErrorList),
26    Status415(models::catalog_items_2022_04_01::ErrorList),
27    Status429(models::catalog_items_2022_04_01::ErrorList),
28    Status500(models::catalog_items_2022_04_01::ErrorList),
29    Status503(models::catalog_items_2022_04_01::ErrorList),
30    UnknownValue(serde_json::Value),
31}
32
33/// struct for typed errors of method [`search_catalog_items`]
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum SearchCatalogItemsError {
37    Status400(models::catalog_items_2022_04_01::ErrorList),
38    Status403(models::catalog_items_2022_04_01::ErrorList),
39    Status404(models::catalog_items_2022_04_01::ErrorList),
40    Status413(models::catalog_items_2022_04_01::ErrorList),
41    Status415(models::catalog_items_2022_04_01::ErrorList),
42    Status429(models::catalog_items_2022_04_01::ErrorList),
43    Status500(models::catalog_items_2022_04_01::ErrorList),
44    Status503(models::catalog_items_2022_04_01::ErrorList),
45    UnknownValue(serde_json::Value),
46}
47
48
49/// Retrieves details for an item in the Amazon catalog.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 2 | 2 |  The `x-amzn-RateLimit-Limit` response header contains the usage plan rate limits for the operation, when available. The preceding table contains the default rate and burst values for this operation. Selling partners whose business demands require higher throughput might have higher rate and burst values than those shown here. For more information, refer to [Usage Plans and Rate Limits](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
50pub async fn get_catalog_item(configuration: &configuration::Configuration, asin: &str, marketplace_ids: Vec<String>, included_data: Option<Vec<String>>, locale: Option<&str>) -> Result<models::catalog_items_2022_04_01::Item, Error<GetCatalogItemError>> {
51    // add a prefix to parameters to efficiently prevent name collisions
52    let p_asin = asin;
53    let p_marketplace_ids = marketplace_ids;
54    let p_included_data = included_data;
55    let p_locale = locale;
56
57    let uri_str = format!("{}/catalog/2022-04-01/items/{asin}", configuration.base_path, asin=crate::apis::urlencode(p_asin));
58    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
59
60    req_builder = match "csv" {
61        "multi" => req_builder.query(&p_marketplace_ids.into_iter().map(|p| ("marketplaceIds".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
62        _ => req_builder.query(&[("marketplaceIds", &p_marketplace_ids.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
63    };
64    if let Some(ref param_value) = p_included_data {
65        req_builder = match "csv" {
66            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("includedData".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
67            _ => req_builder.query(&[("includedData", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
68        };
69    }
70    if let Some(ref param_value) = p_locale {
71        req_builder = req_builder.query(&[("locale", &param_value.to_string())]);
72    }
73    if let Some(ref user_agent) = configuration.user_agent {
74        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
75    }
76
77    let req = req_builder.build()?;
78    let resp = configuration.client.execute(req).await?;
79
80    let status = resp.status();
81    let content_type = resp
82        .headers()
83        .get("content-type")
84        .and_then(|v| v.to_str().ok())
85        .unwrap_or("application/octet-stream");
86    let content_type = super::ContentType::from(content_type);
87
88    if !status.is_client_error() && !status.is_server_error() {
89        let content = resp.text().await?;
90        match content_type {
91            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
92            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::catalog_items_2022_04_01::Item`"))),
93            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::catalog_items_2022_04_01::Item`")))),
94        }
95    } else {
96        let content = resp.text().await?;
97        let entity: Option<GetCatalogItemError> = serde_json::from_str(&content).ok();
98        Err(Error::ResponseError(ResponseContent { status, content, entity }))
99    }
100}
101
102/// Search for a list of Amazon catalog items and item-related information. You can search by identifier or by keywords.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 2 | 2 |  The `x-amzn-RateLimit-Limit` response header contains the usage plan rate limits for the operation, when available. The preceding table contains the default rate and burst values for this operation. Selling partners whose business demands require higher throughput might have higher rate and burst values than those shown here. For more information, refer to [Usage Plans and Rate Limits](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
103pub async fn search_catalog_items(configuration: &configuration::Configuration, marketplace_ids: Vec<String>, identifiers: Option<Vec<String>>, identifiers_type: Option<&str>, included_data: Option<Vec<String>>, locale: Option<&str>, seller_id: Option<&str>, keywords: Option<Vec<String>>, brand_names: Option<Vec<String>>, classification_ids: Option<Vec<String>>, page_size: Option<i32>, page_token: Option<&str>, keywords_locale: Option<&str>) -> Result<models::catalog_items_2022_04_01::ItemSearchResults, Error<SearchCatalogItemsError>> {
104    // add a prefix to parameters to efficiently prevent name collisions
105    let p_marketplace_ids = marketplace_ids;
106    let p_identifiers = identifiers;
107    let p_identifiers_type = identifiers_type;
108    let p_included_data = included_data;
109    let p_locale = locale;
110    let p_seller_id = seller_id;
111    let p_keywords = keywords;
112    let p_brand_names = brand_names;
113    let p_classification_ids = classification_ids;
114    let p_page_size = page_size;
115    let p_page_token = page_token;
116    let p_keywords_locale = keywords_locale;
117
118    let uri_str = format!("{}/catalog/2022-04-01/items", configuration.base_path);
119    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
120
121    if let Some(ref param_value) = p_identifiers {
122        req_builder = match "csv" {
123            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("identifiers".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
124            _ => req_builder.query(&[("identifiers", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
125        };
126    }
127    if let Some(ref param_value) = p_identifiers_type {
128        req_builder = req_builder.query(&[("identifiersType", &param_value.to_string())]);
129    }
130    req_builder = match "csv" {
131        "multi" => req_builder.query(&p_marketplace_ids.into_iter().map(|p| ("marketplaceIds".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
132        _ => req_builder.query(&[("marketplaceIds", &p_marketplace_ids.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
133    };
134    if let Some(ref param_value) = p_included_data {
135        req_builder = match "csv" {
136            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("includedData".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
137            _ => req_builder.query(&[("includedData", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
138        };
139    }
140    if let Some(ref param_value) = p_locale {
141        req_builder = req_builder.query(&[("locale", &param_value.to_string())]);
142    }
143    if let Some(ref param_value) = p_seller_id {
144        req_builder = req_builder.query(&[("sellerId", &param_value.to_string())]);
145    }
146    if let Some(ref param_value) = p_keywords {
147        req_builder = match "csv" {
148            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("keywords".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
149            _ => req_builder.query(&[("keywords", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
150        };
151    }
152    if let Some(ref param_value) = p_brand_names {
153        req_builder = match "csv" {
154            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("brandNames".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
155            _ => req_builder.query(&[("brandNames", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
156        };
157    }
158    if let Some(ref param_value) = p_classification_ids {
159        req_builder = match "csv" {
160            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("classificationIds".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
161            _ => req_builder.query(&[("classificationIds", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
162        };
163    }
164    if let Some(ref param_value) = p_page_size {
165        req_builder = req_builder.query(&[("pageSize", &param_value.to_string())]);
166    }
167    if let Some(ref param_value) = p_page_token {
168        req_builder = req_builder.query(&[("pageToken", &param_value.to_string())]);
169    }
170    if let Some(ref param_value) = p_keywords_locale {
171        req_builder = req_builder.query(&[("keywordsLocale", &param_value.to_string())]);
172    }
173    if let Some(ref user_agent) = configuration.user_agent {
174        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
175    }
176
177    let req = req_builder.build()?;
178    let resp = configuration.client.execute(req).await?;
179
180    let status = resp.status();
181    let content_type = resp
182        .headers()
183        .get("content-type")
184        .and_then(|v| v.to_str().ok())
185        .unwrap_or("application/octet-stream");
186    let content_type = super::ContentType::from(content_type);
187
188    if !status.is_client_error() && !status.is_server_error() {
189        let content = resp.text().await?;
190        match content_type {
191            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
192            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::catalog_items_2022_04_01::ItemSearchResults`"))),
193            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::catalog_items_2022_04_01::ItemSearchResults`")))),
194        }
195    } else {
196        let content = resp.text().await?;
197        let entity: Option<SearchCatalogItemsError> = serde_json::from_str(&content).ok();
198        Err(Error::ResponseError(ResponseContent { status, content, entity }))
199    }
200}
201