Webhooks & APIs: Connect Any App, Build an AI API
Call any API with n8n's HTTP Request node, then build a secured AI endpoint with a Webhook, Gemini and Respond to Webhook.
Video chapters
- 00:00Intro
- 00:42APIs and webhooks in two minutes
- 01:30The project: your own AI summarize API
- 02:26Step 1: Call an API with HTTP Request
- 03:25Four tricks for any API
- 04:50Step 2: Create your webhook
- 05:45Step 3: Add the AI, then respond
- 06:44Test it, then go live
- 07:41Secure your webhook
- 08:39Pro tips for webhook APIs
- 09:53You built a secured AI API
Most real automations start with one app talking to another. In this episode you learn both directions: calling other services with the HTTP Request node, and being called with a Webhook, by building a small AI summarization API that any app can use.
What you need
- n8n with a public HTTPS address (Episode 4, or n8n Cloud)
- The free Gemini credential from Episode 1
- A terminal with curl (or Postman)
APIs and webhooks in two minutes
Let's get the basics straight first. It takes two minutes, and it makes everything else easy.
An API is simply a way for one program to ask another service for data, or to tell it to do something.
Every API call is a request. It has a method, a URL, some headers, like an API key, and sometimes a JSON body with the data you're sending.
The two methods you'll use most are GET, which reads data, and POST, which sends data.
A webhook flips this around. It's a URL that sits and waits. When something calls it, your workflow runs.
So in n8n, the rule is simple. With the HTTP Request node, you call other services.
With the Webhook node, other services call you. Today we'll use both.
Quick reference
- API: A way for programs to ask another service for data
- Request: Method + URL + headers + optional JSON body
- Methods: GET reads data, POST sends data
- Webhook: A URL that waits, and runs when called
- HTTP Request node: You call them
- Webhook node: They call you
an HTTP request
POST /v1/messages
Host: api.example.com
Content-Type: application/json
X-API-Key: ••••••••
{
"text": "Summarize this"
}
← 200 OK {"summary": "..."}The project: your own AI summarize API
Here's what we're building: a tiny AI API.
Any app, a website, a script, or another workflow, sends some text to your n8n address.
A Webhook node receives it.
An AI step, using the same free Gemini model as before, writes a short summary.
And a Respond to Webhook node sends clean JSON straight back to the caller, in the same request. That's a real API endpoint, built without writing a backend.
But first, a warm-up. Let's call someone else's API, using a free public weather service that needs no key at all.
Why build your own API at all? Because it turns one workflow into a building block. Your website's contact form, a mobile app, a Google Sheet, or another n8n workflow can all reuse the same AI step, and when you improve the prompt, every one of them gets the improvement at once.
Quick reference
Any app → Webhook → AI Summarize → Respond
Step 1 · Call an API with HTTP Request
Step one. In a new workflow, add an HTTP Request node, and keep the method as GET, because we're reading data.
For the URL, use the Open-Meteo forecast endpoint. Open-Meteo is a free weather API that doesn't need an account for basic use, which makes it perfect for practice.
Now turn on send query parameters, and add three of them. Latitude and longitude for any city. I'm using London here. And a parameter called current, listing the values we want: the temperature, and the wind speed.
Click test step. The response comes back as JSON, and n8n shows it as fields you can drag into any later node.
Under current, you'll see the time, the temperature, and the wind speed. You could now send this to Telegram every morning, or log it to a sheet. And every other API works the same way. Only the URL, the parameters and the authentication change.
Quick reference
- Add an “HTTP Request” node, method GET
- URL: https://api.open-meteo.com/v1/forecast
- Send Query Parameters: latitude, longitude, current
- Test step → JSON response
QUERY PARAMETERS
latitude = 51.51 longitude = -0.13 current = temperature_2m,wind_speed_10m
time: "2026-11-08T09:00" temperature_2m: 11.4 wind_speed_10m: 14.2
Four tricks for any API
Before we build our own API, here are four tricks that make any API easier in n8n.
One. Import cURL. Almost every API's documentation shows example requests using curl. In the HTTP Request node, click import cURL, paste the example, and n8n fills in the method, URL, headers and body for you.
Two. Credentials. If n8n has a built-in credential for the service, choose predefined credential type. If not, use generic credentials, usually Header Auth, and store the API key there. Never paste keys directly into the URL or the headers.
Three. Pagination. Many APIs return results one page at a time. The HTTP Request node has a pagination option that keeps fetching pages until there are none left.
Four. Batching and retries. In the node options, you can send requests in small batches with a pause in between, and in the node settings, turn on retry on fail. That's how you stay inside an API's rate limits, and survive a temporary error.
And a bonus tip. Spend five minutes reading the API's docs before you build. Find the endpoint, the authentication type, and the rate limits. It saves a lot of trial and error.
Quick reference
- Import cURL: Paste an example from the API docs, n8n fills the node
- Credentials: Use a predefined credential, or Generic: Header Auth
- Pagination: Built-in option to fetch page after page
- Batching + retries: Respect rate limits, retry on temporary errors
- Read the docs first: Endpoint, auth type, limits: 5 minutes well spent
Step 2 · Create your webhook
Now the main project. Step two: create the webhook. Start a new workflow, and add the Webhook trigger.
Set the HTTP method to POST, because callers will send us text in the request body.
Set the path to summarize. This becomes the end of your API's address.
And change the respond setting to using respond to webhook node. This tells n8n to wait, and send back whatever we build at the end of the workflow, instead of an instant empty reply.
At the top of the node, you'll see two URLs: a test URL and a production URL. Notice the difference. The test one contains webhook dash test. The production one just says webhook. We'll come back to why that matters in a moment.
Click listen for test event. n8n is now waiting for a call to the test URL, and we'll send one shortly.
Quick reference
- New workflow → “Webhook” trigger
- HTTP Method: POST
- Path: summarize
- Respond: “Using ‘Respond to Webhook’ Node”
- Listen for test event, then send a request
WEBHOOK URLS
Test:
https://n8n.yourdomain.com/
webhook-test/summarize
Production:
https://n8n.yourdomain.com/
webhook/summarizeStep 3 · Add the AI, then respond
Step three: the AI, and the response. After the webhook, add a Basic LLM Chain, and attach the Google Gemini chat model with your saved credential.
Set the prompt to define below. The text that callers send arrives inside the request body, so the expression is dollar json dot body dot text.
Write a clear prompt: summarize the text in three short bullet points, in plain language, and return only the bullet points. Being strict about the format matters, because another program will read this answer.
Finally, add a Respond to Webhook node, and set respond with to JSON.
For the response body, use an expression that builds a small object, with one field called summary. The Basic LLM Chain puts its answer in a field called text, so the value is dollar json dot text. Now your API returns clean, predictable JSON.
Quick reference
- Basic LLM Chain + Gemini (saved credential)
- Prompt: summarize {{ $json.body.text }}
- Add “Respond to Webhook” → Respond With: JSON
PROMPT
Summarize the text below in 3 short
bullet points. Plain language.
Return only the bullet points.
Text: {{ $json.body.text }}RESPONSE BODY
{{ { "summary": $json.text } }}Test it, then go live
Let's test it from the terminal with curl. You could also use Postman, or any tool you like.
While n8n is listening, send a POST request to the test URL.
Set the content type header to application JSON,
and send a JSON body with one field, text, containing anything long: an article, an email, or meeting notes.
A few seconds later, the response arrives: a JSON object with your three bullet point summary. You just built an AI API.
Now activate the workflow. From this moment, the production URL, with just webhook in the path, works all the time, even with your browser closed.
This is the most common webhook mistake, so remember it. The test URL only works while you're actively listening in the editor. The production URL only works when the workflow is active. Give other apps the production URL.
Quick reference
curl -X POST https://n8n.yourdomain.com/webhook-test/summarize \
-H "Content-Type: application/json" \
-d '{"text": "Paste any long article or email here..."}'
{"summary": "- Point one\n- Point two\n- Point three"}Secure your webhook
Right now, anyone who finds your URL can use your AI, and your Gemini quota. Let's lock it down.
Open the Webhook node, and set authentication to Header Auth.
Create a credential. The name is the header callers must send. I'm using X dash API dash key. The value is a long random key, which you can generate with openssl, just like in the last episode.
Now any request without the right header is rejected before your workflow even runs. Callers simply add one extra header line to their request.
Next, validate the input. Add an If node after the webhook that checks whether body dot text exists, and isn't empty.
If it's missing, send a Respond to Webhook node with response code four hundred, and a clear error message, like text is required. Clear errors make your API pleasant for other developers to use, including future you.
Quick reference
- Webhook → Authentication: Header Auth
- Credential: name X-API-Key, value = long random key
- Callers must send the header, or get 403
- Validate input: If node checks body.text exists
- Missing? Respond with code 400 + a clear message
CALL WITH THE KEY
curl -X POST .../webhook/summarize \
-H "X-API-Key: YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "..."}'Pro tips for webhook APIs
Five tips to make your webhook APIs production quality.
One. Keep responses fast. If a job takes more than a few seconds, respond right away with a message like accepted, and do the slow work in a separate workflow.
Two. Use proper status codes. Two hundred for success, four hundred when the caller sent bad input, and five hundred when something broke on your side.
Three. Log every call. The executions tab already helps, and for anything client facing, append a row to a sheet or a database with the time, the caller, and the result.
Four. Limit the input size. Check the length of the text, and reject anything huge. Otherwise, one oversized request can use up your AI quota.
And five. Version your paths. When you change the response format, create summarize dash v two, instead of breaking every app that already uses the first version.
If you follow these five habits, your workflows stop being experiments, and start behaving like small, reliable services. That's exactly what clients and employers want to see, and it's a big part of moving from no-code user to automation engineer.
Quick reference
- Keep it fast: Respond quickly; move slow work to a second workflow
- Status codes: 200 success, 400 bad input, 500 something broke
- Log every call: Executions tab, or append a row to a sheet
- Limit the size: Cap text length so one request can't cost a fortune
- Version the path: summarize-v2 instead of breaking old callers
You built a secured AI API
Let's recap. You learned how requests work, called a real API with the HTTP Request node, built a webhook endpoint with an AI step and a JSON response, tested it with curl, and secured it with header authentication and input validation.
Remember the one line summary. HTTP Request means you call them. Webhook means they call you. Between the two, n8n can connect to almost anything with an API.
In the next episode, we give our AI agent something powerful: your own documents. We'll build RAG, so the agent answers from your PDFs and notes instead of guessing. The notes and every command from this video are linked in the description.
Quick reference
Any app → Webhook → AI Summarize → Respond
HTTP Request = you call them · Webhook = they call you
Practice
- Add a
languagefield to the request and make the AI answer in that language. - Return a 400 error with a clear message when
textis missing. - Call your new API from the Google Sheets node or a small HTML form.
Next episode
Episode 6: RAG, an AI agent that answers questions from your own documents.
Key takeaways
- HTTP Request node: you call an API. Webhook node: other apps call you
- Use the test URL while building and the production URL for other apps
- Protect webhooks with header auth, and cap input size so one request can't cost a fortune
- Respond fast with clear status codes: 200 success, 400 bad input, 500 something broke