Ir para o conteúdo

Lição 5 · Triggers and Nodes

Webhooks and Forms in n8n

Receive data with the n8n Webhook and Form triggers: test and production URLs, response modes, authentication, signature checks and safe handling of incoming data.

A webhook is a web address that waits for another program to send it a request. When the request arrives, your workflow starts with the request's data. Webhooks let almost any service talk to n8n, even services without a dedicated node. The n8n Form trigger is a friendly cousin: it shows a web form to a person and starts the workflow when they submit it.

Test URL and production URL

The Webhook node gives you two addresses:

URL Used for How it listens
Test URL While building After you start listening for a test event, for a short window (about two minutes)
Production URL Real use After you publish the workflow

With the test URL, the incoming data appears in the editor. With the production URL, it does not; you inspect it in the Executions list. If a service says "404" or nothing happens, first check which URL you gave it and whether the workflow is published.

You can send a test request from your own terminal:

Terminal
# Read-only: replace the URL with your own test URL
curl -X POST "https://your-n8n.example.com/webhook-test/order-created" \
  -H "Content-Type: application/json" \
  -d '{"orderId": "A-1001", "total": 49.5}'

By default the node picks a random path. You can set your own path, including route parameters such as /orders/:id.

What arrives

The Webhook node outputs the parts of the request, typically headers, query parameters and body, as fields of one item. So an expression like this reads the body you sent:

TEXT
{{ $json.body.orderId }}

Open the node output to confirm the exact shape for your request before writing expressions. The docs list a maximum request size of 16 MB by default, which self-hosted users can change.

Choosing how to respond

The caller waits for an answer. The Respond setting decides when and what it receives:

  • Immediately: a quick acknowledgment, while the work continues.
  • When Last Node Finishes: the output of the final node.
  • Using 'Respond to Webhook' Node: you control the status code, headers and body from a specific point in the flow.
  • Streaming response: sends data as it is produced, with nodes that support streaming.

For slow jobs, answer immediately and do the work afterwards. Many senders retry if they wait too long, which creates duplicates.

Protect your webhook

A production URL is public to anyone who learns it. The Webhook node supports several authentication options, including Basic auth, Header auth, JWT auth and a login for users of your own instance, as well as none. Turn authentication on whenever the sender supports it. An IP allowlist option can limit who may call.

Many services also sign their requests: they compute a code from the raw body and a shared secret, and send it in a header. You recompute it and compare. This stand-in shows the idea with the standard library; the header names and exact recipe differ for every provider, so follow their documentation.

Python Stand-in: verify a signed webhook body

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

To check a signature you need the exact raw bytes that were sent. If your platform already parsed the JSON and you re-serialize it, spacing may differ and the check fails. Look at the node's options for keeping the raw body.

Collect data with a form

The n8n Form trigger builds a simple web page from the fields you define, such as text, number or dropdown. Like the webhook, it has a test URL and a production URL. Add more form pages to build multi-step forms.

A form is public input. Treat every value as untrusted:

  • require only the fields you need, and say what you will do with them;
  • check formats, such as an email address, before using them;
  • never place form text directly into SQL or shell commands;
  • add protection against spam if the form is public.
JS Stand-in: validate a form submission

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Behind a proxy

If you self-host behind a reverse proxy, n8n may show URLs that use the wrong host or port. Set the public webhook address with an environment variable (N8N_WEBHOOK_URL; older releases use WEBHOOK_URL), as covered in self-hosting.

Common mistakes

  • Giving a live service the test URL, which only listens briefly.
  • Publishing an unauthenticated webhook that can change data.
  • Trusting values from a request without validating them.

Testing a webhook calmly

Work in this order. Start listening on the test URL, send one request with curl or the sender's test button, then inspect the output. Add authentication and check that a request without it is refused. Only then publish and give the sender the production URL.

Practice

Plan a webhook that receives "order shipped" events. List the authentication method, the fields you require, what you reply when a field is missing and how you detect a repeated delivery.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. When does the production URL of a webhook work?

    The production URL goes live when you publish.
  2. 2. Why reply immediately for a slow job?

    A fast acknowledgment prevents retries while work continues.
  3. 3. What does a request signature help you confirm?

    A valid keyed hash shows the sender holds the secret and the body matches.
  4. 4. How should you treat form input?

    Anyone can send anything to a public form.

Summary

  • Webhooks start workflows from web requests; forms do it from people.
  • Use the test URL while building and the production URL after publishing.
  • Pick a response mode that fits how long the work takes.
  • Authenticate, verify signatures where possible and validate all input.

Next: Items and JSON Data

Seu progresso fica salvo neste navegador. Não precisa de conta.