Skip to main content

data_for_seo/api/keywords_data/
mod.rs

1mod bing;
2mod clickstream_data;
3mod dataforseo_trends;
4mod google_ads;
5mod google_trends;
6
7use crate::{DataForSeoApiResponse, DataForSeoClient};
8use serde::{Deserialize, Serialize};
9
10pub use bing::*;
11pub use clickstream_data::*;
12pub use dataforseo_trends::*;
13pub use google_ads::*;
14pub use google_trends::*;
15
16/// Entry point for the Keywords Data API domain.
17pub struct KeywordsDataApi<'a> {
18    client: &'a DataForSeoClient,
19}
20
21impl DataForSeoClient {
22    /// Keywords Data API (Google Ads, Bing, Google Trends, DataForSEO Trends, Clickstream).
23    /// See <https://docs.dataforseo.com/v3/keywords_data/overview/>.
24    pub fn keywords_data(&self) -> KeywordsDataApi<'_> {
25        KeywordsDataApi { client: self }
26    }
27}
28
29impl KeywordsDataApi<'_> {
30    /// Lists all locations supported across the Keywords Data sub-APIs.
31    pub async fn locations(&self) -> DataForSeoApiResponse<KeywordsDataApiLocation> {
32        self.client.http_get("/v3/keywords_data/locations").await
33    }
34    /// Lists locations supported by a given search engine path, e.g. "google_ads".
35    pub async fn locations_se(&self, se: &str) -> DataForSeoApiResponse<KeywordsDataApiLocation> {
36        self.client
37            .http_get(format!("/v3/keywords_data/{}/locations", se).as_str())
38            .await
39    }
40    /// Lists locations within a country (by ISO code).
41    pub async fn locations_country(
42        &self,
43        country: &str,
44    ) -> DataForSeoApiResponse<KeywordsDataApiLocation> {
45        self.client
46            .http_get(format!("/v3/keywords_data/locations/{}", country).as_str())
47            .await
48    }
49    /// Lists locations within a country for a given search engine path.
50    pub async fn locations_country_se(
51        &self,
52        se: &str,
53        country: &str,
54    ) -> DataForSeoApiResponse<KeywordsDataApiLocation> {
55        self.client
56            .http_get(format!("/v3/keywords_data/{}/locations/{}", se, country).as_str())
57            .await
58    }
59    /// Lists completed tasks ready to be collected across all sub-APIs.
60    pub async fn task_ready(&self) -> DataForSeoApiResponse<KeywordsDataApiTaskReadyResult> {
61        self.client.http_get("/v3/keywords_data/tasks_ready").await
62    }
63    /// Lists completed tasks ready to be collected for a given search engine path.
64    pub async fn task_ready_se(
65        &self,
66        se: &str,
67    ) -> DataForSeoApiResponse<KeywordsDataApiTaskReadyResult> {
68        self.client
69            .http_get(format!("/v3/keywords_data/{}/tasks_ready", se).as_str())
70            .await
71    }
72    /// Lists tasks that were re-run after an error across all sub-APIs.
73    pub async fn task_fixed(&self) -> DataForSeoApiResponse<KeywordsDataApiTaskReadyResult> {
74        self.client.http_get("/v3/keywords_data/tasks_fixed").await
75    }
76    /// Lists tasks that were re-run after an error for a given search engine path.
77    pub async fn task_fixed_se(
78        &self,
79        se: &str,
80    ) -> DataForSeoApiResponse<KeywordsDataApiTaskReadyResult> {
81        self.client
82            .http_get(format!("/v3/keywords_data/{}/tasks_fixed", se).as_str())
83            .await
84    }
85}
86
87/// An entry from a `tasks_ready` or `tasks_fixed` listing.
88/// See <https://docs.dataforseo.com/v3/keywords_data/google_ads/search_volume/tasks_ready/>.
89#[derive(Debug, Default, Serialize, Deserialize, Clone)]
90pub struct KeywordsDataApiTaskReadyResult {
91    /// Identifier of the completed task, UUID format.
92    pub id: Option<String>,
93    /// Search engine the task was posted for (e.g. `google_ads`).
94    pub se: Option<String>,
95    /// Search engine type, where applicable.
96    pub se_type: Option<String>,
97    /// Date and time when the task was posted, UTC.
98    pub date_posted: Option<String>,
99    /// User-defined tag echoed from the task request.
100    pub tag: Option<String>,
101    /// URL for collecting the results in the regular format, if available.
102    pub endpoint_regular: Option<String>,
103    /// URL for collecting the results in the advanced format, if available.
104    pub endpoint_advanced: Option<String>,
105    /// URL for collecting the results in the HTML format, if available.
106    pub endpoint_html: Option<String>,
107}
108
109/// A location supported by a Keywords Data sub-API.
110/// See <https://docs.dataforseo.com/v3/keywords_data/google_ads/locations/>.
111#[derive(Debug, Default, Serialize, Deserialize, Clone)]
112pub struct KeywordsDataApiLocation {
113    /// Numeric location identifier.
114    pub location_code: Option<i32>,
115    /// Full location name.
116    pub location_name: Option<String>,
117    /// Code of the parent location, if any.
118    pub location_code_parent: Option<i32>,
119    /// ISO country code of the location.
120    pub country_iso_code: Option<String>,
121    /// Location type, e.g. "Country", "Region" or "City".
122    pub location_type: Option<String>,
123}