Skip to main content

data_for_seo/api/dataforseo_labs/
amazon.rs

1//! Amazon endpoints of the DataForSEO Labs API.
2//! See <https://docs.dataforseo.com/v3/dataforseo_labs/amazon/>.
3
4use crate::entity::{
5    DataForSeoLabsAmazonProductCompetitorItem, DataForSeoLabsAmazonProductKeywordIntersectionItem,
6    DataForSeoLabsAmazonProductRankOverviewItem, DataForSeoLabsAmazonRankedKeywordItem,
7    DataForSeoLabsAmazonRelatedKeywordItem, DataForSeoLabsAmazonSearchVolumeItem,
8    DataForSeoLabsResult,
9};
10use crate::{DataForSeoApiResponse, DataForSeoClient};
11use serde::{Deserialize, Serialize};
12use serde_json::Value;
13use std::collections::HashMap;
14
15/// Amazon endpoints of the DataForSEO Labs API.
16pub struct DataForSeoLabsApiAmazon<'a> {
17    pub(crate) client: &'a DataForSeoClient,
18}
19
20impl DataForSeoLabsApiAmazon<'_> {
21    /// Amazon search volume for a batch of keywords.
22    /// See <https://docs.dataforseo.com/v3/dataforseo_labs/amazon/bulk_search_volume/live/>.
23    pub async fn bulk_search_volume(
24        &self,
25        data: Vec<DataForSeoLabsAmazonBulkSearchVolumeRequest>,
26    ) -> DataForSeoApiResponse<DataForSeoLabsResult<DataForSeoLabsAmazonSearchVolumeItem>> {
27        self.client
28            .http_post("/v3/dataforseo_labs/amazon/bulk_search_volume/live", &data)
29            .await
30    }
31
32    /// Keywords related to a seed keyword on Amazon.
33    /// See <https://docs.dataforseo.com/v3/dataforseo_labs/amazon/related_keywords/live/>.
34    pub async fn related_keywords(
35        &self,
36        data: Vec<DataForSeoLabsAmazonRelatedKeywordsRequest>,
37    ) -> DataForSeoApiResponse<DataForSeoLabsResult<DataForSeoLabsAmazonRelatedKeywordItem>> {
38        self.client
39            .http_post("/v3/dataforseo_labs/amazon/related_keywords/live", &data)
40            .await
41    }
42
43    /// Keywords an Amazon product (ASIN) ranks for.
44    /// See <https://docs.dataforseo.com/v3/dataforseo_labs/amazon/ranked_keywords/live/>.
45    pub async fn ranked_keywords(
46        &self,
47        data: Vec<DataForSeoLabsAmazonRankedKeywordsRequest>,
48    ) -> DataForSeoApiResponse<DataForSeoLabsResult<DataForSeoLabsAmazonRankedKeywordItem>> {
49        self.client
50            .http_post("/v3/dataforseo_labs/amazon/ranked_keywords/live", &data)
51            .await
52    }
53
54    /// Aggregated ranking overview of an Amazon product.
55    /// See <https://docs.dataforseo.com/v3/dataforseo_labs/amazon/product_rank_overview/live/>.
56    pub async fn product_rank_overview(
57        &self,
58        data: Vec<DataForSeoLabsAmazonProductRankOverviewRequest>,
59    ) -> DataForSeoApiResponse<DataForSeoLabsResult<DataForSeoLabsAmazonProductRankOverviewItem>>
60    {
61        self.client
62            .http_post(
63                "/v3/dataforseo_labs/amazon/product_rank_overview/live",
64                &data,
65            )
66            .await
67    }
68
69    /// Amazon products (ASINs) competing with a target product.
70    /// See <https://docs.dataforseo.com/v3/dataforseo_labs/amazon/product_competitors/live/>.
71    pub async fn product_competitors(
72        &self,
73        data: Vec<DataForSeoLabsAmazonProductCompetitorsRequest>,
74    ) -> DataForSeoApiResponse<DataForSeoLabsResult<DataForSeoLabsAmazonProductCompetitorItem>>
75    {
76        self.client
77            .http_post("/v3/dataforseo_labs/amazon/product_competitors/live", &data)
78            .await
79    }
80
81    /// Keywords a set of Amazon products rank for together.
82    /// See <https://docs.dataforseo.com/v3/dataforseo_labs/amazon/product_keyword_intersections/live/>.
83    pub async fn product_keyword_intersections(
84        &self,
85        data: Vec<DataForSeoLabsAmazonProductKeywordIntersectionsRequest>,
86    ) -> DataForSeoApiResponse<
87        DataForSeoLabsResult<DataForSeoLabsAmazonProductKeywordIntersectionItem>,
88    > {
89        self.client
90            .http_post(
91                "/v3/dataforseo_labs/amazon/product_keyword_intersections/live",
92                &data,
93            )
94            .await
95    }
96}
97
98/// Request body for Amazon `bulk_search_volume`.
99/// See <https://docs.dataforseo.com/v3/dataforseo_labs/amazon/bulk_search_volume/live/>.
100#[derive(Debug, Default, Serialize, Deserialize, Clone)]
101pub struct DataForSeoLabsAmazonBulkSearchVolumeRequest {
102    /// Keywords to analyze.
103    pub keywords: Vec<String>,
104    /// Full location name (e.g. `"United States"`); alternative to `location_code`.
105    #[serde(skip_serializing_if = "Option::is_none")]
106    pub location_name: Option<String>,
107    /// Location code (e.g. `2840`); alternative to `location_name`.
108    #[serde(skip_serializing_if = "Option::is_none")]
109    pub location_code: Option<i32>,
110    /// Full language name (e.g. `"English"`); alternative to `language_code`.
111    #[serde(skip_serializing_if = "Option::is_none")]
112    pub language_name: Option<String>,
113    /// Language code (e.g. `"en"`); alternative to `language_name`.
114    #[serde(skip_serializing_if = "Option::is_none")]
115    pub language_code: Option<String>,
116    /// User-defined task identifier (max 255 characters).
117    #[serde(skip_serializing_if = "Option::is_none")]
118    pub tag: Option<String>,
119}
120
121impl DataForSeoLabsAmazonBulkSearchVolumeRequest {
122    /// Creates a request for the given keywords.
123    pub fn new(keywords: Vec<String>) -> DataForSeoLabsAmazonBulkSearchVolumeRequest {
124        DataForSeoLabsAmazonBulkSearchVolumeRequest {
125            keywords,
126            ..Default::default()
127        }
128    }
129}
130
131/// Request body for Amazon `related_keywords`.
132/// See <https://docs.dataforseo.com/v3/dataforseo_labs/amazon/related_keywords/live/>.
133#[derive(Debug, Default, Serialize, Deserialize, Clone)]
134pub struct DataForSeoLabsAmazonRelatedKeywordsRequest {
135    /// Keyword the data relates to.
136    pub keyword: String,
137    /// Full location name (e.g. `"United States"`); alternative to `location_code`.
138    #[serde(skip_serializing_if = "Option::is_none")]
139    pub location_name: Option<String>,
140    /// Location code (e.g. `2840`); alternative to `location_name`.
141    #[serde(skip_serializing_if = "Option::is_none")]
142    pub location_code: Option<i32>,
143    /// Full language name (e.g. `"English"`); alternative to `language_code`.
144    #[serde(skip_serializing_if = "Option::is_none")]
145    pub language_name: Option<String>,
146    /// Language code (e.g. `"en"`); alternative to `language_name`.
147    #[serde(skip_serializing_if = "Option::is_none")]
148    pub language_code: Option<String>,
149    /// Keyword expansion depth (0-4); higher values return more keywords.
150    #[serde(skip_serializing_if = "Option::is_none")]
151    pub depth: Option<i64>,
152    /// Whether to include data for the seed keyword itself.
153    #[serde(skip_serializing_if = "Option::is_none")]
154    pub include_seed_keyword: Option<bool>,
155    /// Whether to exclude highly similar keywords from the results.
156    #[serde(skip_serializing_if = "Option::is_none")]
157    pub ignore_synonyms: Option<bool>,
158    /// Maximum number of returned items (default 100, max 1000).
159    #[serde(skip_serializing_if = "Option::is_none")]
160    pub limit: Option<i32>,
161    /// Offset into the result set, for pagination.
162    #[serde(skip_serializing_if = "Option::is_none")]
163    pub offset: Option<i32>,
164    /// User-defined task identifier (max 255 characters).
165    #[serde(skip_serializing_if = "Option::is_none")]
166    pub tag: Option<String>,
167}
168
169impl DataForSeoLabsAmazonRelatedKeywordsRequest {
170    /// Creates a request for the given seed keyword.
171    pub fn new(keyword: &str) -> DataForSeoLabsAmazonRelatedKeywordsRequest {
172        DataForSeoLabsAmazonRelatedKeywordsRequest {
173            keyword: keyword.to_string(),
174            ..Default::default()
175        }
176    }
177}
178
179/// Request body for Amazon `ranked_keywords`.
180/// See <https://docs.dataforseo.com/v3/dataforseo_labs/amazon/ranked_keywords/live/>.
181#[derive(Debug, Default, Serialize, Deserialize, Clone)]
182pub struct DataForSeoLabsAmazonRankedKeywordsRequest {
183    /// Amazon product identifier (ASIN).
184    pub asin: String,
185    /// Full location name (e.g. `"United States"`); alternative to `location_code`.
186    #[serde(skip_serializing_if = "Option::is_none")]
187    pub location_name: Option<String>,
188    /// Location code (e.g. `2840`); alternative to `location_name`.
189    #[serde(skip_serializing_if = "Option::is_none")]
190    pub location_code: Option<i32>,
191    /// Full language name (e.g. `"English"`); alternative to `language_code`.
192    #[serde(skip_serializing_if = "Option::is_none")]
193    pub language_name: Option<String>,
194    /// Language code (e.g. `"en"`); alternative to `language_name`.
195    #[serde(skip_serializing_if = "Option::is_none")]
196    pub language_code: Option<String>,
197    /// Whether to exclude highly similar keywords from the results.
198    #[serde(skip_serializing_if = "Option::is_none")]
199    pub ignore_synonyms: Option<bool>,
200    /// Array of filtering conditions applied to the results.
201    #[serde(skip_serializing_if = "Option::is_none")]
202    pub filters: Option<Vec<Value>>,
203    /// Sorting rules applied to the results.
204    #[serde(skip_serializing_if = "Option::is_none")]
205    pub order_by: Option<Vec<String>>,
206    /// Maximum number of returned items (default 100, max 1000).
207    #[serde(skip_serializing_if = "Option::is_none")]
208    pub limit: Option<i32>,
209    /// Offset into the result set, for pagination.
210    #[serde(skip_serializing_if = "Option::is_none")]
211    pub offset: Option<i32>,
212    /// User-defined task identifier (max 255 characters).
213    #[serde(skip_serializing_if = "Option::is_none")]
214    pub tag: Option<String>,
215}
216
217impl DataForSeoLabsAmazonRankedKeywordsRequest {
218    /// Creates a request for the given product ASIN.
219    pub fn new(asin: &str) -> DataForSeoLabsAmazonRankedKeywordsRequest {
220        DataForSeoLabsAmazonRankedKeywordsRequest {
221            asin: asin.to_string(),
222            ..Default::default()
223        }
224    }
225}
226
227/// Request body for Amazon `product_rank_overview`.
228/// See <https://docs.dataforseo.com/v3/dataforseo_labs/amazon/product_rank_overview/live/>.
229#[derive(Debug, Default, Serialize, Deserialize, Clone)]
230pub struct DataForSeoLabsAmazonProductRankOverviewRequest {
231    /// Amazon product identifier (ASIN).
232    pub asin: String,
233    /// Full location name (e.g. `"United States"`); alternative to `location_code`.
234    #[serde(skip_serializing_if = "Option::is_none")]
235    pub location_name: Option<String>,
236    /// Location code (e.g. `2840`); alternative to `location_name`.
237    #[serde(skip_serializing_if = "Option::is_none")]
238    pub location_code: Option<i32>,
239    /// Full language name (e.g. `"English"`); alternative to `language_code`.
240    #[serde(skip_serializing_if = "Option::is_none")]
241    pub language_name: Option<String>,
242    /// Language code (e.g. `"en"`); alternative to `language_name`.
243    #[serde(skip_serializing_if = "Option::is_none")]
244    pub language_code: Option<String>,
245    /// User-defined task identifier (max 255 characters).
246    #[serde(skip_serializing_if = "Option::is_none")]
247    pub tag: Option<String>,
248}
249
250impl DataForSeoLabsAmazonProductRankOverviewRequest {
251    /// Creates a request for the given product ASIN.
252    pub fn new(asin: &str) -> DataForSeoLabsAmazonProductRankOverviewRequest {
253        DataForSeoLabsAmazonProductRankOverviewRequest {
254            asin: asin.to_string(),
255            ..Default::default()
256        }
257    }
258}
259
260/// Request body for Amazon `product_competitors`.
261/// See <https://docs.dataforseo.com/v3/dataforseo_labs/amazon/product_competitors/live/>.
262#[derive(Debug, Default, Serialize, Deserialize, Clone)]
263pub struct DataForSeoLabsAmazonProductCompetitorsRequest {
264    /// Amazon product identifier (ASIN).
265    pub asin: String,
266    /// Full location name (e.g. `"United States"`); alternative to `location_code`.
267    #[serde(skip_serializing_if = "Option::is_none")]
268    pub location_name: Option<String>,
269    /// Location code (e.g. `2840`); alternative to `location_name`.
270    #[serde(skip_serializing_if = "Option::is_none")]
271    pub location_code: Option<i32>,
272    /// Full language name (e.g. `"English"`); alternative to `language_code`.
273    #[serde(skip_serializing_if = "Option::is_none")]
274    pub language_name: Option<String>,
275    /// Language code (e.g. `"en"`); alternative to `language_name`.
276    #[serde(skip_serializing_if = "Option::is_none")]
277    pub language_code: Option<String>,
278    /// Array of filtering conditions applied to the results.
279    #[serde(skip_serializing_if = "Option::is_none")]
280    pub filters: Option<Vec<Value>>,
281    /// Sorting rules applied to the results.
282    #[serde(skip_serializing_if = "Option::is_none")]
283    pub order_by: Option<Vec<String>>,
284    /// Maximum number of returned items (default 100, max 1000).
285    #[serde(skip_serializing_if = "Option::is_none")]
286    pub limit: Option<i32>,
287    /// Offset into the result set, for pagination.
288    #[serde(skip_serializing_if = "Option::is_none")]
289    pub offset: Option<i32>,
290    /// User-defined task identifier (max 255 characters).
291    #[serde(skip_serializing_if = "Option::is_none")]
292    pub tag: Option<String>,
293}
294
295impl DataForSeoLabsAmazonProductCompetitorsRequest {
296    /// Creates a request for the given product ASIN.
297    pub fn new(asin: &str) -> DataForSeoLabsAmazonProductCompetitorsRequest {
298        DataForSeoLabsAmazonProductCompetitorsRequest {
299            asin: asin.to_string(),
300            ..Default::default()
301        }
302    }
303}
304
305/// Request body for Amazon `product_keyword_intersections`.
306/// See <https://docs.dataforseo.com/v3/dataforseo_labs/amazon/product_keyword_intersections/live/>.
307#[derive(Debug, Default, Serialize, Deserialize, Clone)]
308pub struct DataForSeoLabsAmazonProductKeywordIntersectionsRequest {
309    /// Product ASINs, keyed by an index string.
310    pub asins: HashMap<String, String>,
311    /// Full location name (e.g. `"United States"`); alternative to `location_code`.
312    #[serde(skip_serializing_if = "Option::is_none")]
313    pub location_name: Option<String>,
314    /// Location code (e.g. `2840`); alternative to `location_name`.
315    #[serde(skip_serializing_if = "Option::is_none")]
316    pub location_code: Option<i32>,
317    /// Full language name (e.g. `"English"`); alternative to `language_code`.
318    #[serde(skip_serializing_if = "Option::is_none")]
319    pub language_name: Option<String>,
320    /// Language code (e.g. `"en"`); alternative to `language_name`.
321    #[serde(skip_serializing_if = "Option::is_none")]
322    pub language_code: Option<String>,
323    /// How the intersection is computed: `"union"` or `"intersect"`.
324    #[serde(skip_serializing_if = "Option::is_none")]
325    pub intersection_mode: Option<String>,
326    /// Array of filtering conditions applied to the results.
327    #[serde(skip_serializing_if = "Option::is_none")]
328    pub filters: Option<Vec<Value>>,
329    /// Sorting rules applied to the results.
330    #[serde(skip_serializing_if = "Option::is_none")]
331    pub order_by: Option<Vec<String>>,
332    /// Maximum number of returned items (default 100, max 1000).
333    #[serde(skip_serializing_if = "Option::is_none")]
334    pub limit: Option<i32>,
335    /// Offset into the result set, for pagination.
336    #[serde(skip_serializing_if = "Option::is_none")]
337    pub offset: Option<i32>,
338    /// User-defined task identifier (max 255 characters).
339    #[serde(skip_serializing_if = "Option::is_none")]
340    pub tag: Option<String>,
341}
342
343impl DataForSeoLabsAmazonProductKeywordIntersectionsRequest {
344    /// Creates a request over the given asins map (index string -> ASIN).
345    pub fn new(
346        asins: HashMap<String, String>,
347    ) -> DataForSeoLabsAmazonProductKeywordIntersectionsRequest {
348        DataForSeoLabsAmazonProductKeywordIntersectionsRequest {
349            asins,
350            ..Default::default()
351        }
352    }
353}