Skip to content

Commit 3218827

Browse files
committed
Allow the node to be used as a tool
Also improves the default description for the model to use
1 parent fca53bb commit 3218827

File tree

4 files changed

+141
-61
lines changed

4 files changed

+141
-61
lines changed

README.md

Lines changed: 93 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,111 @@
11
![Banner image](https://user-images.githubusercontent.com/10284570/173569848-c624317f-42b1-45a6-ab09-f0ea3c247648.png)
22

3-
# n8n-nodes-starter
3+
# n8n SearchAPI.io Node
44

5-
This repo contains example nodes to help you get started building your own custom integrations for [n8n](n8n.io). It includes the node linter and other dependencies.
5+
Search the web with [SearchAPI.io](https://www.searchapi.io/) directly from your n8n workflows. The node exposes the full power of the `/api/v1/search` endpoint and supports **all engines and query parameters** offered by the service.
66

7-
To make your custom node available to the community, you must create it as an npm package, and [submit it to the npm registry](https://docs.npmjs.com/packages-and-modules/contributing-packages-to-the-registry).
7+
> **Why SearchAPI.io?**\
8+
> Real‑time SERP data from Google, Bing, DuckDuckGo, Yahoo, Yandex and more – no captchas, no proxies, one simple API.
89
9-
## Plan
10+
---
1011

11-
- Node type: Action
12-
- Style: Declarative
12+
## Installation
1313

14-
## Prerequisites
14+
### Via the n8n UI (recommended)
1515

16-
You need the following installed on your development machine:
16+
1. Open **Settings → Community Nodes** inside your self‑hosted n8n instance.
17+
2. Click **Install → Browse** and search for `n8n-nodes-searchapi`.
18+
3. Select the package, accept the risk prompt, and hit **Install**.
1719

18-
* [git](https://git-scm.com/downloads)
19-
* Node.js and pnpm. Minimum version Node 18. You can find instructions on how to install both using nvm (Node Version Manager) for Linux, Mac, and WSL [here](https://github.com/nvm-sh/nvm). For Windows users, refer to Microsoft's guide to [Install NodeJS on Windows](https://docs.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-windows).
20-
* Install n8n with:
20+
### Via the command line
21+
22+
```bash
23+
# inside your n8n installation folder
24+
npm install n8n-nodes-searchapi
25+
# or with pnpm
26+
pnpm add n8n-nodes-searchapi
27+
```
28+
29+
Restart n8n after the install finishes.
30+
31+
> **Compatibility**
32+
>
33+
> - n8n ≥ 1.30.0
34+
> - Node.js ≥ 18
35+
36+
---
37+
38+
## Credentials
39+
40+
1. Sign up at **[SearchAPI.io](https://www.searchapi.io/)** and copy your **API Key**.
41+
2. In n8n go to **Credentials → + New Credential → SearchAPI**.
42+
3. Paste the key and save.\
43+
The new credential will now appear in the node’s **Credential** dropdown.
44+
45+
---
46+
47+
## Usage
48+
49+
### 1. Drag‑and‑drop UI
50+
51+
1. Add the **SearchAPI** node to your workflow.
52+
2. Choose your **Credential** and the **Engine**.
53+
3. Under **Parameters,** click **Add Parameter** for each query string field you need. To determine which fields to add, refer to the engine's documentation.
54+
- **Name**: `q`
55+
- **Value**: `weather new york`
56+
4. Execute the workflow to receive the response as JSON.
57+
58+
### 2. Pass a parameters object (programmatic)
59+
60+
You can also pass a parameters object directly to the node, instead of the UI:
61+
62+
```json
63+
{
64+
"parameters": {
65+
"q": "n8n workflow automation",
66+
"device": "mobile",
67+
"location": "Berlin"
68+
}
69+
}
70+
```
71+
72+
- Feed the object through a **Set** node or any previous node.
2173
```
22-
pnpm install n8n -g
74+
{{$json.parameters}}
2375
```
24-
* Recommended: follow n8n's guide to [set up your development environment](https://docs.n8n.io/integrations/creating-nodes/build/node-development-environment/).
76+
- The node will give preference to the parameters object.
77+
78+
---
79+
80+
## Example workflow
81+
82+
The sample below searches Google for “n8n community nodes” and extracts the first organic result.
83+
84+
85+
86+
You can import the full `.json` from `/examples/searchapi_google_basic.json` in this repo.
87+
88+
---
89+
90+
## Output
91+
92+
The node returns the raw JSON received from SearchAPI.io. See the [official docs](https://www.searchapi.io/docs/google) for complete schemas.
2593

26-
## Using this starter
94+
---
2795

28-
These are the basic steps for working with the starter. For detailed guidance on creating and publishing nodes, refer to the [documentation](https://docs.n8n.io/integrations/creating-nodes/).
96+
## Troubleshooting
2997

30-
1. [Generate a new repository](https://github.com/n8n-io/n8n-nodes-starter/generate) from this template repository.
31-
2. Clone your new repo:
32-
```
33-
git clone https://github.com/<your organization>/<your-repo-name>.git
34-
```
35-
3. Run `pnpm i` to install dependencies.
36-
4. Open the project in your editor.
37-
5. Browse the examples in `/nodes` and `/credentials`. Modify the examples, or replace them with your own nodes.
38-
6. Update the `package.json` to match your details.
39-
7. Run `pnpm lint` to check for errors or `pnpm lintfix` to automatically fix errors when possible.
40-
8. Test your node locally. Refer to [Run your node locally](https://docs.n8n.io/integrations/creating-nodes/test/run-node-locally/) for guidance.
41-
9. Replace this README with documentation for your node. Use the [README_TEMPLATE](README_TEMPLATE.md) to get started.
42-
10. Update the LICENSE file to use your details.
43-
11. [Publish](https://docs.npmjs.com/packages-and-modules/contributing-packages-to-the-registry) your package to npm.
98+
| Error message | Likely cause | Fix |
99+
| ---------------------------- | ---------------------------- | --------------------------------------------------------------------------- |
100+
| **401 Unauthorized** | Invalid or missing API key | Double‑check the credentials. |
101+
| **422 Unprocessable Entity** | Wrong parameter name / value | Verify against SearchAPI docs. |
102+
| **429 Too Many Requests** | Rate limit exceeded | Slow down the workflow or [upgrade plan](https://www.searchapi.io/pricing). |
44103

45-
## More information
104+
---
46105

47-
Refer to our [documentation on creating nodes](https://docs.n8n.io/integrations/creating-nodes/) for detailed information on building your own nodes.
106+
## Resources
48107

49-
## License
108+
- **SearchAPI.io documentation**[https://www.searchapi.io/docs](https://www.searchapi.io/docs)
109+
- **n8n Community Forum**[https://community.n8n.io](https://community.n8n.io)
110+
- **Community nodes installation** – [https://docs.n8n.io/integrations/community-nodes/installation/](https://docs.n8n.io/integrations/community-nodes/installation/)
50111

51-
[MIT](https://github.com/n8n-io/n8n-nodes-starter/blob/master/LICENSE.md)

nodes/SearchApi/SearchApi.node.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ export class SearchApi implements INodeType {
77
icon: 'file:searchApi.svg',
88
group: ['output'],
99
version: 1,
10-
description: 'Search the web via SearchAPI.io (declarative)',
10+
description: 'Call this tool whenever the answer might require fresh, niche, or externally-verifiable information. \
11+
Set the `engine` to the required backend (default: `google`). Always include `q` (the user’s query) and your \
12+
`api_key`; add optional parameters to localize, paginate, filter by date, or change device-type as needed. \
13+
Return the raw JSON response, then cite sources in the final reply. ',
1114
subtitle: '={{ $parameter["engine"] }}',
1215
defaults: { name: 'SearchAPI' },
16+
// @ts-ignore
1317
inputs: ['main'],
18+
// @ts-ignore
1419
outputs: ['main'],
15-
1620
credentials: [{ name: 'searchApi', required: true }],
17-
21+
usableAsTool: true,
1822
requestDefaults: {
1923
baseURL: 'https://www.searchapi.io/api/v1',
2024
method: 'GET',
@@ -24,15 +28,24 @@ export class SearchApi implements INodeType {
2428
api_key: '={{ $credentials.apiKey }}', // generic-auth pattern :contentReference[oaicite:3]{index=3}
2529
},
2630
},
27-
31+
hints: [
32+
{
33+
message: "Hit SearchAPI's free 100-request quota? Check the Pricing page 📈'",
34+
type: 'info',
35+
whenToDisplay: 'beforeExecution',
36+
location: 'inputPane',
37+
},
38+
],
2839
properties: [
2940
{
3041
displayName: 'Engine (Engine)',
3142
name: 'engine',
3243
type: 'string',
3344
default: 'google',
3445
required: true,
46+
3547
description: 'Search engine to use for the query',
48+
hint: 'Check https://www.searchapi.io/docs/google for the available engines',
3649
routing: {
3750
request: {
3851
qs: {
@@ -47,8 +60,7 @@ export class SearchApi implements INodeType {
4760
type: 'fixedCollection',
4861
typeOptions: { multipleValues: true },
4962
default: {},
50-
hint: 'You can pass a paramters object to this node, to use the parameters in the search',
51-
description: 'Add the parameters you want to use for the search, refer to the SearchAPI.io documentation for the available parameters',
63+
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',
5264
options: [
5365
{
5466
displayName: 'Parameter',
@@ -59,12 +71,14 @@ export class SearchApi implements INodeType {
5971
name: 'name',
6072
type: 'string',
6173
default: '',
74+
placeholder: 'q',
6275
},
6376
{
6477
displayName: 'Value',
6578
name: 'value',
6679
type: 'string',
6780
default: '',
81+
placeholder: 'pizza near me',
6882
},
6983
],
7084
},
@@ -78,7 +92,7 @@ export class SearchApi implements INodeType {
7892
// We are doing this cast here because we need to
7993
// build an object out of the collection entries
8094
// and merge it into qs, but qs expects an object.
81-
qs: '={{ Object.fromEntries(($value.parameter ?? $json.parameters ?? []).map(p => [p.name, p.value])) }}' as unknown as IDataObject,
95+
qs: '={{ Object.fromEntries(($value.parameter ?? []).map(p => [p.name, p.value])) }}' as unknown as IDataObject,
8296
},
8397
},
8498
},

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
"gulp": "^4.0.2",
5050
"prettier": "^3.3.2",
5151
"sqlite3": "^5.1.7",
52-
"typescript": "^5.5.3"
52+
"typescript": "^5.5.3",
53+
"n8n-workflow": "^1.70.0"
5354
},
5455
"peerDependencies": {
5556
"n8n-workflow": "*"

pnpm-lock.yaml

Lines changed: 25 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)