amazon_sp_api/models/
catalog_items.rs

1use reqwest::{Method, Response};
2use crate::error_handling::Errors;
3use crate::general::{Client, CountryMarketplace};
4pub struct CatalogItems;
5impl CatalogItems {
6
7    /// Search for and return a list of Amazon catalog items and associated information.
8    ///
9    /// Rate (requests per second): 2
10    /// Burst: 2
11    ///
12    /// # Parameters
13    /// - client: Reference to the HTTP client
14    /// - marketplace_ids: Required list of Amazon marketplace identifiers
15    /// - identifiers: Optional list of product identifiers to search for
16    /// - identifiers_type: Required when identifiers are provided
17    /// - included_data: Optional list of data sets to include (default: summaries)
18    /// - locale: Optional locale for localized summaries
19    /// - seller_id: Required when identifiers_type is SKU
20    /// - keywords: Optional list of search keywords (cannot be used with identifiers)
21    /// - brand_names: Optional list of brand names for keyword searches
22    /// - classification_ids: Optional list of classification IDs for keyword searches
23    /// - page_size: Optional number of results per page (max: 20, default: 10)
24    /// - page_token: Optional token for pagination
25    /// - keywords_locale: Optional language of the keywords
26    pub async fn search_catalog_items(
27        client: &mut Client,
28        marketplace_ids: Vec<CountryMarketplace>,
29        identifiers: Option<Vec<String>>,
30        identifiers_type: Option<String>,
31        included_data: Option<Vec<String>>,
32        locale: Option<String>,
33        seller_id: Option<String>,
34        keywords: Option<Vec<String>>,
35        brand_names: Option<Vec<String>>,
36        classification_ids: Option<Vec<String>>,
37        page_size: Option<i32>,
38        page_token: Option<String>,
39        keywords_locale: Option<String>,
40    ) -> Result<Response, Errors> {
41        const URI: &str = "/catalog/2022-04-01/items";
42
43        let mut params: Vec<(String, String)> = Vec::new();
44
45        params.push(("marketplaceIds".to_string(), marketplace_ids.iter().map(|b|b.details().0.to_string()).collect::<Vec<String>>().join(",")));
46
47        if let Some(ids) = identifiers {
48            params.push(("identifiers".to_string(), ids.join(",")));
49        }
50        if let Some(id_type) = identifiers_type {
51            params.push(("identifiersType".to_string(), id_type));
52        }
53        if let Some(data) = included_data {
54            params.push(("includedData".to_string(), data.join(",")));
55        }
56        if let Some(loc) = locale {
57            params.push(("locale".to_string(), loc));
58        }
59        if let Some(sid) = seller_id {
60            params.push(("sellerId".to_string(), sid));
61        }
62        if let Some(kw) = keywords {
63            params.push(("keywords".to_string(), kw.join(",")));
64        }
65        if let Some(brands) = brand_names {
66            params.push(("brandNames".to_string(), brands.join(",")));
67        }
68        if let Some(class_ids) = classification_ids {
69            params.push(("classificationIds".to_string(), class_ids.join(",")));
70        }
71        if let Some(size) = page_size {
72            params.push(("pageSize".to_string(), size.to_string()));
73        }
74        if let Some(token) = page_token {
75            params.push(("pageToken".to_string(), token));
76        }
77        if let Some(kw_locale) = keywords_locale {
78            params.push(("keywordsLocale".to_string(), kw_locale));
79        }
80        client.make_request(URI, Method::GET, Some(params)).await
81    }
82
83    /// Retrieves details for an item in the Amazon catalog by ASIN.
84    ///
85    /// Rate (requests per second): 2
86    /// Burst: 2
87    ///
88    /// # Parameters
89    /// - client: Reference to the HTTP client
90    /// - asin: The Amazon Standard Identification Number of the item
91    /// - marketplace_ids: Required list of Amazon marketplace identifiers
92    /// - included_data: Optional list of data sets to include (default: summaries)
93    /// - locale: Optional locale for localized summaries
94    pub async fn get_catalog_item(
95        client: &mut Client,
96        asin: String,
97        marketplace_ids: Vec<CountryMarketplace>,
98        included_data: Option<Vec<String>>,
99        locale: Option<String>,
100    ) -> Result<Response, Errors> {
101        let uri = format!("/catalog/2022-04-01/items/{}", asin);
102
103        let mut params: Vec<(String, String)> = Vec::new();
104
105        // Add required parameters
106        params.push(("marketplaceIds".to_string(), marketplace_ids.iter().map(|b|b.details().0.to_string()).collect::<Vec<String>>().join(",")));
107
108        // Add optional parameters
109        if let Some(data) = included_data {
110            params.push(("includedData".to_string(), data.join(",")));
111        }
112        if let Some(loc) = locale {
113            params.push(("locale".to_string(), loc));
114        }
115
116        client.make_request(&uri, Method::GET, Some(params)).await
117    }
118    }