Skip to content

Commit 9922943

Browse files
committed
[Types] Google Shopping API
1 parent 4290c7f commit 9922943

5 files changed

Lines changed: 185 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to
1010

1111
### Added
1212

13+
- [Google Shopping] Add new API.
14+
1315
### Changed
1416

1517
### Fixed

mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export {
2323
} from "./src/serpapi.ts";
2424

2525
export type { GoogleParameters } from "./src/engines/google.ts";
26+
export type { GoogleShoppingParameters } from "./src/engines/google_shopping.ts";
2627
export type { GoogleJobsParameters } from "./src/engines/google_jobs.ts";
2728
export type { GoogleJobsListingParameters } from "./src/engines/google_jobs_listing.ts";
2829
export type { GoogleReverseImageParameters } from "./src/engines/google_reverse_image.ts";

src/engines/engine_map.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { GoogleParameters } from "./google.ts";
2+
import type { GoogleShoppingParameters } from "./google_shopping.ts";
23
import type { GoogleJobsParameters } from "./google_jobs.ts";
34
import type { GoogleJobsListingParameters } from "./google_jobs_listing.ts";
45
import type { GoogleReverseImageParameters } from "./google_reverse_image.ts";
@@ -55,6 +56,7 @@ import type { YelpReviewsParameters } from "./yelp_reviews.ts";
5556

5657
export type EngineMap = {
5758
google: { parameters: GoogleParameters };
59+
google_shopping: { parameters: GoogleShoppingParameters };
5860
google_jobs: { parameters: GoogleJobsParameters };
5961
google_jobs_listing: { parameters: GoogleJobsListingParameters };
6062
google_reverse_image: { parameters: GoogleReverseImageParameters };

src/engines/google.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ export type GoogleParameters = BaseParameters & {
241241
* `lcl` - [Google Local API](https://serpapi.com/local-results)
242242
* `vid`: [Google Videos API](https://serpapi.com/videos-results),
243243
* `nws`: [Google News API](https://serpapi.com/news-results),
244-
* `shop`: [Google Shopping API](https://serpapi.com/shopping-results)
244+
* `shop`: [Google Shopping API](https://serpapi.com/shopping-results),
245+
* or any other Google service.
245246
*/
246247
tbm?: string;
247248

src/engines/google_shopping.ts

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
import type { BaseParameters } from "../types.ts";
2+
3+
export type GoogleShoppingParameters = BaseParameters & {
4+
/**
5+
* Search Query
6+
* Parameter defines the query you want to search. You can use anything that you
7+
* would use in a regular Google Shopping search. e.g. `inurl:`, `site:`,
8+
* `intitle:`.
9+
*/
10+
q: string;
11+
12+
/**
13+
* Location
14+
* Parameter defines from where you want the search to originate. If several
15+
* locations match the location requested, we'll pick the most popular one. Head to
16+
* the [/locations.json API](https://serpapi.com/locations-api) if you need a more
17+
* precise control. location and uule parameters can't be used together. Avoid
18+
* utilizing location when setting the location outside the U.S. when using Google
19+
* Shopping API.
20+
*/
21+
location?: string;
22+
23+
/**
24+
* Encoded Location
25+
* Parameter is the Google encoded location you want to use for the search. uule
26+
* and location parameters can't be used together.
27+
*/
28+
uule?: string;
29+
30+
/**
31+
* Domain
32+
* Parameter defines the Google domain to use. It defaults to `google.com`. Head to
33+
* the [Google domains](https://serpapi.com/google-domains) for a full list of
34+
* supported Google domains.
35+
*/
36+
google_domain?: string;
37+
38+
/**
39+
* Country
40+
* Parameter defines the country to use for the Google search. It's a two-letter
41+
* country code. (e.g., `us` for the United States, `uk` for United Kingdom, or
42+
* `fr` for France) Head to the [Google
43+
* countries](https://serpapi.com/google-countries) for a full list of supported
44+
* Google countries.
45+
*/
46+
gl?: string;
47+
48+
/**
49+
* Language
50+
* Parameter defines the language to use for the Google Maps search. It's a
51+
* two-letter language code. (e.g., `en` for English, `es` for Spanish, or `fr` for
52+
* French) Head to the Google languages for a full list of supported [Google
53+
* languages](https://serpapi.com/google-languages).
54+
*/
55+
hl?: string;
56+
57+
/**
58+
* as_dt
59+
* Parameter controls whether to include or exclude results from the site named in
60+
* the as_sitesearch parameter.
61+
*/
62+
as_dt?: string;
63+
64+
/**
65+
* as_epq
66+
* Parameter identifies a phrase that all documents in the search results must
67+
* contain. You can also use the [phrase
68+
* search](https://developers.google.com/custom-search/docs/xml_results#PhraseSearchqt)
69+
* query term to search for a phrase.
70+
*/
71+
as_epq?: string;
72+
73+
/**
74+
* as_eq
75+
* Parameter identifies a word or phrase that should not appear in any documents in
76+
* the search results. You can also use the [exclude
77+
* query](https://developers.google.com/custom-search/docs/xml_results#Excludeqt)
78+
* term to ensure that a particular word or phrase will not appear in the documents
79+
* in a set of search results.
80+
*/
81+
as_eq?: string;
82+
83+
/**
84+
* as_lq
85+
* Parameter specifies that all search results should contain a link to a
86+
* particular URL. You can also use the
87+
* [link:](https://developers.google.com/custom-search/docs/xml_results#BackLinksqt)
88+
* query term for this type of query.
89+
*/
90+
as_lq?: string;
91+
92+
/**
93+
* as_nlo
94+
* Parameter specifies the starting value for a search range. Use as_nlo and as_nhi
95+
* to append an inclusive search range.
96+
*/
97+
as_nlo?: string;
98+
99+
/**
100+
* as_nhi
101+
* Parameter specifies the ending value for a search range. Use as_nlo and as_nhi
102+
* to append an inclusive search range.
103+
*/
104+
as_nhi?: string;
105+
106+
/**
107+
* as_oq
108+
* Parameter provides additional search terms to check for in a document, where
109+
* each document in the search results must contain at least one of the additional
110+
* search terms. You can also use the [Boolean
111+
* OR](https://developers.google.com/custom-search/docs/xml_results#BooleanOrqt)
112+
* query term for this type of query.
113+
*/
114+
as_oq?: string;
115+
116+
/**
117+
* as_q
118+
* Parameter provides search terms to check for in a document. This parameter is
119+
* also commonly used to allow users to specify additional terms to search for
120+
* within a set of search results.
121+
*/
122+
as_q?: string;
123+
124+
/**
125+
* as_qdr
126+
* Parameter requests search results from a specified time period (quick date
127+
* range). The following values are supported:
128+
* `d[number]`: requests results from the specified number of past days. Example
129+
* for the past 10 days: `as_qdr=d10`
130+
* `w[number]`: requests results from the specified number of past weeks.
131+
* `m[number]`: requests results from the specified number of past months.
132+
* `y[number]`: requests results from the specified number of past years. Example
133+
* for the past year: `as_qdr=y`
134+
*/
135+
as_qdr?: string;
136+
137+
/**
138+
* as_rq
139+
* Parameter specifies that all search results should be pages that are related to
140+
* the specified URL. The parameter value should be a URL. You can also use the
141+
* [related:](https://developers.google.com/custom-search/docs/xml_results#RelatedLinksqt)
142+
* query term for this type of query.
143+
*/
144+
as_rq?: string;
145+
146+
/**
147+
* as_sitesearch
148+
* Parameter allows you to specify that all search results should be pages from a
149+
* given site. By setting the as_dt parameter, you can also use it to exclude pages
150+
* from a given site from your search resutls.
151+
*/
152+
as_sitesearch?: string;
153+
154+
/**
155+
* Advanced Search Parameters
156+
* (to be searched) parameter defines advanced search parameters that aren't
157+
* possible in the regular query field.
158+
*/
159+
tbs?: string;
160+
161+
/**
162+
* Result Offset
163+
* Parameter defines the result offset. It skips the given number of results. It's
164+
* used for pagination. (e.g., `0` (default) is the first page of results, `60` is
165+
* the 2nd page of results, `120` is the 3rd page of results, etc.).
166+
*/
167+
start?: number;
168+
169+
/**
170+
* Number of Results
171+
* Parameter defines the maximum number of results to return. (e.g., `60` (default)
172+
* returns 60 results, `40` returns 40 results, and `100` (maximum) returns 100
173+
* results).
174+
* Any number greater than maximum number (`100`) will default to `100`.
175+
* Any number lesser than minimum number (`1`) will default to `60`.
176+
*/
177+
num?: string;
178+
};

0 commit comments

Comments
 (0)