Skip to main content

data_for_seo/api/merchant/
amazon.rs

1use crate::api::merchant::MerchantApi;
2use crate::entity::{
3    MerchantApiAmazonAsin, MerchantApiAmazonProducts, MerchantApiAmazonSellers,
4    MerchantApiLocation, MerchantApiTaskReady, SerpApiLanguage,
5};
6use crate::{DataForSeoApiResponse, DataForSeoClient};
7use serde::{Deserialize, Serialize};
8use serde_json::Value;
9
10impl MerchantApi<'_> {
11    /// Access the Amazon Merchant API.
12    /// See <https://docs.dataforseo.com/v3/merchant/amazon/overview/>.
13    pub fn amazon(&self) -> MerchantApiAmazon<'_> {
14        MerchantApiAmazon {
15            client: self.client,
16        }
17    }
18}
19
20/// Amazon Merchant API (products, ASIN, sellers).
21pub struct MerchantApiAmazon<'a> {
22    client: &'a DataForSeoClient,
23}
24
25impl MerchantApiAmazon<'_> {
26    /// <https://docs.dataforseo.com/v3/merchant/amazon/locations/>
27    pub async fn locations(&self) -> DataForSeoApiResponse<MerchantApiLocation> {
28        self.client.http_get("/v3/merchant/amazon/locations").await
29    }
30    /// <https://docs.dataforseo.com/v3/merchant/amazon/locations/>
31    pub async fn locations_country(
32        &self,
33        country: &str,
34    ) -> DataForSeoApiResponse<MerchantApiLocation> {
35        self.client
36            .http_get(format!("/v3/merchant/amazon/locations/{country}").as_str())
37            .await
38    }
39    /// <https://docs.dataforseo.com/v3/merchant/amazon/languages/>
40    pub async fn languages(&self) -> DataForSeoApiResponse<SerpApiLanguage> {
41        self.client.http_get("/v3/merchant/amazon/languages").await
42    }
43
44    /// <https://docs.dataforseo.com/v3/merchant/amazon/products/task_post/>
45    pub async fn products_task_post(
46        &self,
47        data: Vec<MerchantApiAmazonProductsPost>,
48    ) -> DataForSeoApiResponse<Value> {
49        self.client
50            .http_post("/v3/merchant/amazon/products/task_post", &data)
51            .await
52    }
53    /// <https://docs.dataforseo.com/v3/merchant/amazon/products/tasks_ready/>
54    pub async fn products_tasks_ready(&self) -> DataForSeoApiResponse<MerchantApiTaskReady> {
55        self.client
56            .http_get("/v3/merchant/amazon/products/tasks_ready")
57            .await
58    }
59    /// <https://docs.dataforseo.com/v3/merchant/amazon/products/task_get/advanced/>
60    pub async fn products_task_get_advanced(
61        &self,
62        id: &str,
63    ) -> DataForSeoApiResponse<MerchantApiAmazonProducts> {
64        self.client
65            .http_get(format!("/v3/merchant/amazon/products/task_get/advanced/{id}").as_str())
66            .await
67    }
68    /// <https://docs.dataforseo.com/v3/merchant/amazon/products/task_get/html/>
69    pub async fn products_task_get_html(&self, id: &str) -> DataForSeoApiResponse<Value> {
70        self.client
71            .http_get(format!("/v3/merchant/amazon/products/task_get/html/{id}").as_str())
72            .await
73    }
74    /// <https://docs.dataforseo.com/v3/merchant/amazon/products/live/advanced/>
75    pub async fn products_live_advanced(
76        &self,
77        data: Vec<MerchantApiAmazonProductsPost>,
78    ) -> DataForSeoApiResponse<MerchantApiAmazonProducts> {
79        self.client
80            .http_post("/v3/merchant/amazon/products/live/advanced", &data)
81            .await
82    }
83    /// <https://docs.dataforseo.com/v3/merchant/amazon/products/live/html/>
84    pub async fn products_live_html(
85        &self,
86        data: Vec<MerchantApiAmazonProductsPost>,
87    ) -> DataForSeoApiResponse<Value> {
88        self.client
89            .http_post("/v3/merchant/amazon/products/live/html", &data)
90            .await
91    }
92
93    /// <https://docs.dataforseo.com/v3/merchant/amazon/asin/task_post/>
94    pub async fn asin_task_post(
95        &self,
96        data: Vec<MerchantApiAmazonAsinPost>,
97    ) -> DataForSeoApiResponse<Value> {
98        self.client
99            .http_post("/v3/merchant/amazon/asin/task_post", &data)
100            .await
101    }
102    /// <https://docs.dataforseo.com/v3/merchant/amazon/asin/tasks_ready/>
103    pub async fn asin_tasks_ready(&self) -> DataForSeoApiResponse<MerchantApiTaskReady> {
104        self.client
105            .http_get("/v3/merchant/amazon/asin/tasks_ready")
106            .await
107    }
108    /// <https://docs.dataforseo.com/v3/merchant/amazon/asin/task_get/advanced/>
109    pub async fn asin_task_get_advanced(
110        &self,
111        id: &str,
112    ) -> DataForSeoApiResponse<MerchantApiAmazonAsin> {
113        self.client
114            .http_get(format!("/v3/merchant/amazon/asin/task_get/advanced/{id}").as_str())
115            .await
116    }
117    /// <https://docs.dataforseo.com/v3/merchant/amazon/asin/task_get/html/>
118    pub async fn asin_task_get_html(&self, id: &str) -> DataForSeoApiResponse<Value> {
119        self.client
120            .http_get(format!("/v3/merchant/amazon/asin/task_get/html/{id}").as_str())
121            .await
122    }
123    /// <https://docs.dataforseo.com/v3/merchant/amazon/asin/live/advanced/>
124    pub async fn asin_live_advanced(
125        &self,
126        data: Vec<MerchantApiAmazonAsinPost>,
127    ) -> DataForSeoApiResponse<MerchantApiAmazonAsin> {
128        self.client
129            .http_post("/v3/merchant/amazon/asin/live/advanced", &data)
130            .await
131    }
132    /// <https://docs.dataforseo.com/v3/merchant/amazon/asin/live/html/>
133    pub async fn asin_live_html(
134        &self,
135        data: Vec<MerchantApiAmazonAsinPost>,
136    ) -> DataForSeoApiResponse<Value> {
137        self.client
138            .http_post("/v3/merchant/amazon/asin/live/html", &data)
139            .await
140    }
141
142    /// <https://docs.dataforseo.com/v3/merchant/amazon/sellers/task_post/>
143    pub async fn sellers_task_post(
144        &self,
145        data: Vec<MerchantApiAmazonSellersPost>,
146    ) -> DataForSeoApiResponse<Value> {
147        self.client
148            .http_post("/v3/merchant/amazon/sellers/task_post", &data)
149            .await
150    }
151    /// <https://docs.dataforseo.com/v3/merchant/amazon/sellers/tasks_ready/>
152    pub async fn sellers_tasks_ready(&self) -> DataForSeoApiResponse<MerchantApiTaskReady> {
153        self.client
154            .http_get("/v3/merchant/amazon/sellers/tasks_ready")
155            .await
156    }
157    /// <https://docs.dataforseo.com/v3/merchant/amazon/sellers/task_get/advanced/>
158    pub async fn sellers_task_get_advanced(
159        &self,
160        id: &str,
161    ) -> DataForSeoApiResponse<MerchantApiAmazonSellers> {
162        self.client
163            .http_get(format!("/v3/merchant/amazon/sellers/task_get/advanced/{id}").as_str())
164            .await
165    }
166    /// <https://docs.dataforseo.com/v3/merchant/amazon/sellers/task_get/html/>
167    pub async fn sellers_task_get_html(&self, id: &str) -> DataForSeoApiResponse<Value> {
168        self.client
169            .http_get(format!("/v3/merchant/amazon/sellers/task_get/html/{id}").as_str())
170            .await
171    }
172    /// <https://docs.dataforseo.com/v3/merchant/amazon/sellers/live/advanced/>
173    pub async fn sellers_live_advanced(
174        &self,
175        data: Vec<MerchantApiAmazonSellersPost>,
176    ) -> DataForSeoApiResponse<MerchantApiAmazonSellers> {
177        self.client
178            .http_post("/v3/merchant/amazon/sellers/live/advanced", &data)
179            .await
180    }
181    /// <https://docs.dataforseo.com/v3/merchant/amazon/sellers/live/html/>
182    pub async fn sellers_live_html(
183        &self,
184        data: Vec<MerchantApiAmazonSellersPost>,
185    ) -> DataForSeoApiResponse<Value> {
186        self.client
187            .http_post("/v3/merchant/amazon/sellers/live/html", &data)
188            .await
189    }
190}
191
192/// Request payload for the Amazon products endpoints.
193/// See <https://docs.dataforseo.com/v3/merchant/amazon/products/task_post/>.
194#[derive(Debug, Default, Serialize, Deserialize, Clone)]
195pub struct MerchantApiAmazonProductsPost {
196    /// Search keyword (up to 700 characters, URL-decoded).
197    pub keyword: String,
198    /// Direct Amazon search URL to parse instead of building one from `keyword`.
199    #[serde(skip_serializing_if = "Option::is_none")]
200    pub url: Option<String>,
201    /// Task priority: `1` (normal, default) or `2` (high, extra charge).
202    #[serde(skip_serializing_if = "Option::is_none")]
203    pub priority: Option<i32>,
204    /// Full location name (e.g. `"London,England,United Kingdom"`).
205    #[serde(skip_serializing_if = "Option::is_none")]
206    pub location_name: Option<String>,
207    /// Location code; alternative to `location_name`.
208    #[serde(skip_serializing_if = "Option::is_none")]
209    pub location_code: Option<i32>,
210    /// GPS coordinates as `"latitude,longitude,radius"`.
211    #[serde(skip_serializing_if = "Option::is_none")]
212    pub location_coordinate: Option<String>,
213    /// Full language name (e.g. `"English (United States)"`).
214    #[serde(skip_serializing_if = "Option::is_none")]
215    pub language_name: Option<String>,
216    /// Language code (e.g. `en_US`); alternative to `language_name`.
217    #[serde(skip_serializing_if = "Option::is_none")]
218    pub language_code: Option<String>,
219    /// Custom Amazon domain (e.g. `amazon.co.uk`).
220    #[serde(skip_serializing_if = "Option::is_none")]
221    pub se_domain: Option<String>,
222    /// Number of results to retrieve (default `100`, max `700`).
223    #[serde(skip_serializing_if = "Option::is_none")]
224    pub depth: Option<i32>,
225    /// Maximum number of result pages to crawl (max `7`).
226    #[serde(skip_serializing_if = "Option::is_none")]
227    pub max_crawl_pages: Option<i32>,
228    /// Amazon product category (department) to search within.
229    #[serde(skip_serializing_if = "Option::is_none")]
230    pub department: Option<String>,
231    /// Raw price/sorting URL parameters; ignored when `price_min`/`price_max`/`sort_by` are set.
232    #[serde(skip_serializing_if = "Option::is_none")]
233    pub search_param: Option<String>,
234    /// Minimum product price filter.
235    #[serde(skip_serializing_if = "Option::is_none")]
236    pub price_min: Option<i32>,
237    /// Maximum product price filter.
238    #[serde(skip_serializing_if = "Option::is_none")]
239    pub price_max: Option<i32>,
240    /// Sort order (e.g. `relevance`, `price_low_to_high`, `avg_customer_review`).
241    #[serde(skip_serializing_if = "Option::is_none")]
242    pub sort_by: Option<String>,
243    /// User-defined task identifier (max 255 characters).
244    #[serde(skip_serializing_if = "Option::is_none")]
245    pub tag: Option<String>,
246    /// URL to receive the completed task via POST; requires `postback_data`.
247    #[serde(skip_serializing_if = "Option::is_none")]
248    pub postback_url: Option<String>,
249    /// Result type delivered to `postback_url` (`advanced` or `html`).
250    #[serde(skip_serializing_if = "Option::is_none")]
251    pub postback_data: Option<String>,
252    /// URL pinged with a GET request when the task completes.
253    #[serde(skip_serializing_if = "Option::is_none")]
254    pub pingback_url: Option<String>,
255}
256
257impl MerchantApiAmazonProductsPost {
258    /// Creates a request for the given search `keyword`.
259    pub fn new(keyword: &str) -> MerchantApiAmazonProductsPost {
260        MerchantApiAmazonProductsPost {
261            keyword: keyword.to_string(),
262            ..Default::default()
263        }
264    }
265}
266
267/// Request payload for the Amazon ASIN endpoints.
268/// See <https://docs.dataforseo.com/v3/merchant/amazon/asin/task_post/>.
269#[derive(Debug, Default, Serialize, Deserialize, Clone)]
270pub struct MerchantApiAmazonAsinPost {
271    /// Product ASIN to look up.
272    pub asin: String,
273    /// Task priority: `1` (normal, default) or `2` (high, extra charge).
274    #[serde(skip_serializing_if = "Option::is_none")]
275    pub priority: Option<i32>,
276    /// Full location name (e.g. `"London,England,United Kingdom"`).
277    #[serde(skip_serializing_if = "Option::is_none")]
278    pub location_name: Option<String>,
279    /// Location code; alternative to `location_name`.
280    #[serde(skip_serializing_if = "Option::is_none")]
281    pub location_code: Option<i32>,
282    /// GPS coordinates as `"latitude,longitude,radius"`.
283    #[serde(skip_serializing_if = "Option::is_none")]
284    pub location_coordinate: Option<String>,
285    /// Full language name (e.g. `"English (United States)"`).
286    #[serde(skip_serializing_if = "Option::is_none")]
287    pub language_name: Option<String>,
288    /// Language code (e.g. `en_US`); alternative to `language_name`.
289    #[serde(skip_serializing_if = "Option::is_none")]
290    pub language_code: Option<String>,
291    /// Custom Amazon domain (e.g. `amazon.co.uk`).
292    #[serde(skip_serializing_if = "Option::is_none")]
293    pub se_domain: Option<String>,
294    /// User-defined task identifier (max 255 characters).
295    #[serde(skip_serializing_if = "Option::is_none")]
296    pub tag: Option<String>,
297    /// URL to receive the completed task via POST; requires `postback_data`.
298    #[serde(skip_serializing_if = "Option::is_none")]
299    pub postback_url: Option<String>,
300    /// Result type delivered to `postback_url` (`advanced` or `html`).
301    #[serde(skip_serializing_if = "Option::is_none")]
302    pub postback_data: Option<String>,
303    /// URL pinged with a GET request when the task completes.
304    #[serde(skip_serializing_if = "Option::is_none")]
305    pub pingback_url: Option<String>,
306}
307
308impl MerchantApiAmazonAsinPost {
309    /// Creates a request for the given product `asin`.
310    pub fn new(asin: &str) -> MerchantApiAmazonAsinPost {
311        MerchantApiAmazonAsinPost {
312            asin: asin.to_string(),
313            ..Default::default()
314        }
315    }
316}
317
318/// Request payload for the Amazon sellers endpoints.
319/// See <https://docs.dataforseo.com/v3/merchant/amazon/sellers/task_post/>.
320#[derive(Debug, Default, Serialize, Deserialize, Clone)]
321pub struct MerchantApiAmazonSellersPost {
322    /// ASIN of the product to list sellers for.
323    pub asin: String,
324    /// Task priority: `1` (normal, default) or `2` (high, extra charge).
325    #[serde(skip_serializing_if = "Option::is_none")]
326    pub priority: Option<i32>,
327    /// Full location name (e.g. `"London,England,United Kingdom"`).
328    #[serde(skip_serializing_if = "Option::is_none")]
329    pub location_name: Option<String>,
330    /// Location code; alternative to `location_name`.
331    #[serde(skip_serializing_if = "Option::is_none")]
332    pub location_code: Option<i32>,
333    /// GPS coordinates as `"latitude,longitude,radius"`.
334    #[serde(skip_serializing_if = "Option::is_none")]
335    pub location_coordinate: Option<String>,
336    /// Full language name (e.g. `"English (United States)"`).
337    #[serde(skip_serializing_if = "Option::is_none")]
338    pub language_name: Option<String>,
339    /// Language code (e.g. `en_US`); alternative to `language_name`.
340    #[serde(skip_serializing_if = "Option::is_none")]
341    pub language_code: Option<String>,
342    /// Custom Amazon domain (e.g. `amazon.co.uk`).
343    #[serde(skip_serializing_if = "Option::is_none")]
344    pub se_domain: Option<String>,
345    /// User-defined task identifier (max 255 characters).
346    #[serde(skip_serializing_if = "Option::is_none")]
347    pub tag: Option<String>,
348    /// URL to receive the completed task via POST; requires `postback_data`.
349    #[serde(skip_serializing_if = "Option::is_none")]
350    pub postback_url: Option<String>,
351    /// Result type delivered to `postback_url` (`advanced` or `html`).
352    #[serde(skip_serializing_if = "Option::is_none")]
353    pub postback_data: Option<String>,
354    /// URL pinged with a GET request when the task completes.
355    #[serde(skip_serializing_if = "Option::is_none")]
356    pub pingback_url: Option<String>,
357}
358
359impl MerchantApiAmazonSellersPost {
360    /// Creates a request for the given product `asin`.
361    pub fn new(asin: &str) -> MerchantApiAmazonSellersPost {
362        MerchantApiAmazonSellersPost {
363            asin: asin.to_string(),
364            ..Default::default()
365        }
366    }
367}