Skip to content

Commit 3264685

Browse files
authored
Merge pull request #2 from SearchApi/feat/add-all-engines
Adds google images, maps shopping and search
2 parents 3026c33 + 188add3 commit 3264685

File tree

6 files changed

+3002
-58
lines changed

6 files changed

+3002
-58
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,9 @@ The node returns the raw JSON received from SearchApi.io. See the [official docs
107107
- **n8n Community Forum**[https://community.n8n.io](https://community.n8n.io)
108108
- **Community nodes installation** – [https://docs.n8n.io/integrations/community-nodes/installation/](https://docs.n8n.io/integrations/community-nodes/installation/)
109109

110+
## Contributing
111+
112+
1. Run `pnpm build && pnpm link` on the project root
113+
2. Run `pnpm link @searchapi/n8n-nodes-searchapi`
114+
115+
After that build the node on each change and it should be reflected in n8n local interface.

nodes/SearchApi/SearchApi.node.ts

Lines changed: 46 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { IDataObject, INodeType, INodeTypeDescription } from 'n8n-workflow';
1+
import { INodeType, INodeTypeDescription } from 'n8n-workflow';
2+
import { google } from './engines/google';
3+
import { google_images } from './engines/google_images';
4+
import { google_maps } from './engines/google_maps';
5+
import { google_shopping } from './engines/google_shopping';
26

37
export class SearchApi implements INodeType {
48
description: INodeTypeDescription = {
@@ -7,7 +11,8 @@ export class SearchApi implements INodeType {
711
icon: 'file:searchApi.svg',
812
group: ['output'],
913
version: 1,
10-
description: 'Call this tool whenever the answer might require fresh, niche, or externally-verifiable information. Make sure to always cite the sources in the final reply. ',
14+
description:
15+
'Access real-time search results from Google, Google Images, Google Maps, Google Shopping and more. Use this when you need current, up-to-date information, product searches, location data, or visual content that may not be available in your training data.',
1116
subtitle: '={{ $parameter["engine"] }}',
1217
defaults: { name: 'SearchApi' },
1318
// @ts-ignore
@@ -17,7 +22,7 @@ export class SearchApi implements INodeType {
1722
credentials: [{ name: 'searchApi', required: true }],
1823
usableAsTool: true,
1924
requestDefaults: {
20-
baseURL: 'https://www.searchapi.io/api/v1',
25+
baseURL: 'http://localhost:3000/api/v1', // TODO: Change to https://www.searchapi.io/api/v1
2126
method: 'GET',
2227
url: '/search',
2328
headers: { Accept: 'application/json' },
@@ -27,72 +32,55 @@ export class SearchApi implements INodeType {
2732
},
2833
hints: [
2934
{
30-
message: "Hit SearchAPI's free 100-request quota? Check the Pricing page 📈'",
31-
type: 'info',
32-
whenToDisplay: 'beforeExecution',
33-
location: 'inputPane',
35+
message: "Hit SearchAPI's free 100-request quota? Check the Pricing page 📈'",
36+
type: 'info',
37+
whenToDisplay: 'beforeExecution',
38+
location: 'inputPane',
3439
},
35-
],
40+
],
3641
properties: [
42+
// eslint-disable-next-line n8n-nodes-base/node-param-default-missing
3743
{
38-
displayName: 'Engine (Engine)',
39-
name: 'engine',
40-
type: 'string',
41-
default: 'google',
42-
required: true,
43-
44-
description: 'Search engine to use for the query',
45-
hint: 'Check https://www.searchapi.io/docs/google for the available engines',
46-
routing: {
47-
request: {
48-
qs: {
49-
engine: '={{ $value }}',
50-
},
51-
},
52-
},
44+
displayName: 'Resource',
45+
name: 'resource',
46+
type: 'options',
47+
description: 'The search engine to use',
48+
noDataExpression: true,
49+
options: [
50+
google.resource,
51+
google_images.resource,
52+
google_maps.resource,
53+
google_shopping.resource,
54+
55+
],
56+
default: google.resource.value,
5357
},
5458
{
55-
displayName: 'Parameters',
56-
name: 'parameters',
57-
type: 'fixedCollection',
58-
typeOptions: { multipleValues: true },
59-
default: {},
60-
description: 'Add the parameters you want to use for the search, refer to the SearchAPI.io documentation for the available parameters for the selected engine',
59+
displayName: 'Operation Name',
60+
name: 'operation',
61+
type: 'options',
62+
noDataExpression: true,
6163
options: [
6264
{
63-
displayName: 'Parameter',
64-
name: 'parameter',
65-
values: [
66-
{
67-
displayName: 'Name',
68-
name: 'name',
69-
type: 'string',
70-
default: '',
71-
placeholder: 'q',
72-
},
73-
{
74-
displayName: 'Value',
75-
name: 'value',
76-
type: 'string',
77-
default: '',
78-
placeholder: 'pizza near me',
65+
name: 'Search',
66+
value: 'search',
67+
action: 'Search',
68+
description: 'Search using the engine specified in the resource',
69+
routing: {
70+
request: {
71+
qs: {
72+
engine: '={{ $parameter["resource"] }}',
73+
},
7974
},
80-
],
75+
},
8176
},
8277
],
83-
/**
84-
* Build an object like { hl: 'en', gl: 'us' } out of
85-
* the collection entries and merge it into qs.
86-
*/
87-
routing: {
88-
request: {
89-
// We are doing this cast here because we need to
90-
// build an object out of the collection entries
91-
// and merge it into qs, but qs expects an object.
92-
qs: '={{ Object.fromEntries(($value.parameter ?? []).map(p => [p.name, p.value])) }}' as unknown as IDataObject,
93-
},
94-
},
78+
default: 'search',
9579
},
80+
...google.properties,
81+
...google_images.properties,
82+
...google_maps.properties,
83+
...google_shopping.properties,
9684
],
9785
};
9886
}

0 commit comments

Comments
 (0)