n8n HTTP Request and Webhooks: A Practical Guide
The n8n HTTP Request node calls any REST API: you set the method, URL, authentication and JSON body, and the response flows into the next node. Incoming events are handled by the Webhook node: an external service POSTs to its URL and starts the workflow. This guide walks through the n8n HTTP Request node with a live example: the 0x.cloud API, which n8n uses to watch your balance and create servers on demand.
Everything here works on n8n Cloud and self-hosted n8n. Need an instance? Follow install n8n on a VPS.
n8n HTTP Request Node: The Fields That Matter
| Field | What to set |
|---|---|
| Method | GET, POST, PUT, PATCH, DELETE, HEAD or OPTIONS |
| URL | the API endpoint, for example https://0x.cloud/v1/balance |
| Authentication | Predefined Credential Type if n8n has one for the service, otherwise Generic Credential Type |
| Send Body | on for POST/PUT, Body Content Type: JSON |
| Options | Timeout, Never Error, Include Response Headers and Status, Pagination |
Full reference: n8n HTTP Request docs.
Bearer Key Authentication
Most APIs, 0x.cloud included, expect Authorization: Bearer KEY. In n8n:
- Authentication: Generic Credential Type.
- Generic Auth Type: Header Auth.
- Create a credential: Name
Authorization, ValueBearer 0x_live_your_key.
The key is stored in n8n's encrypted credentials and stays out of workflow exports. For 0x.cloud, create a dedicated n8n key with minimal scopes and a monthly spend cap, as shown in API key permissions.
Import cURL for a Fast Start
If the API docs show a curl example, click Import cURL in the node, paste it and click Import. n8n fills in the method, URL, headers and body. Importing overwrites the node's settings and turns numbers and true/false into strings, so switch the body to Using JSON when types matter.
Workflow 1: Watch Your Balance
Goal: check your 0x.cloud balance daily and ping Telegram when it drops below $5.
- Schedule Trigger: every day at 09:00.
- HTTP Request: GET
https://0x.cloud/v1/balance, Header Auth with a key that only hasbilling.read. The response looks like{"data": {"balance_usd": "12.50", ...}}. - IF on the number from the response:
{{ Number($json.data.balance_usd) }} is less than 5
- Telegram (true branch): "0x.cloud balance: $X. Top up so servers keep running."
Set this key's spending to disabled: even if it leaks, nobody can buy anything with it. Instead of polling daily you can subscribe to the balance.low event (see the webhook section below).
Workflow 2: n8n Create Server on Demand
Goal: spin up a 6-hour temporary server from a webhook, but only if the price fits the budget.
- Webhook: POST, a long random path instead of
new-server. Request body:{"plan": "s1-2"}. - HTTP Request named "Quote": POST
https://0x.cloud/v1/servers, body Using JSON:
{
"plan": "{{ $json.body.plan }}",
"billing_cycle": "hourly",
"ttl_hours": 6,
"dry_run": true
}
- IF:
{{ Number($json.monthly_usd) }}is less than or equal to 10. - HTTP Request "Create": POST to the same URL, body without
dry_runbut with the quote from the "Quote" node (valid for 10 minutes):
{
"plan": "{{ $('Quote').item.json.plan }}",
"billing_cycle": "hourly",
"ttl_hours": 6,
"pricing_fingerprint": "{{ $('Quote').item.json.pricing_fingerprint }}"
}
- Respond to Webhook: return
{{ $json.data.id }}. Do not send the root password back to the caller.
ttl_hours deletes the server automatically after 6 hours and returns the unused remainder to your balance. This key needs servers.read and servers.create, and its monthly spend cap protects you from a bug in the condition: past it the API answers 402 key_spend_limit_reached and charges nothing. Every endpoint and field is in the API quickstart.
You do not have to wire the nodes by hand: an AI agent can draft the workflow for import.
Build an n8n workflow JSON: Webhook (POST, random path) → HTTP Request "Quote" with dry_run and ttl_hours 6 to https://0x.cloud/v1/servers → IF monthly_usd ≤ 10 → HTTP Request to create with the pricing_fingerprint from the "Quote" node → Respond to Webhook with the server ID and no password. Use a Header Auth credential named 0x.cloud. No keys inside the JSON.
n8n Webhook: Receive Events From 0x.cloud
0x.cloud sends events to n8n via webhooks, for example server.created, server.running, server.deleted, balance.low and balance.credited. Setup:
- Add a Webhook node: HTTP Method POST, Path set to a long random string.
- Copy the Production URL, like
https://n8n.example.com/webhook/ox-events-7f3k.... - Publish the workflow: the production URL only accepts requests once published.
- Register the URL with 0x.cloud. Through the API this takes a key with
webhooks.write:
curl -s https://0x.cloud/v1/webhooks \
-H "Authorization: Bearer $OX_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://n8n.example.com/webhook/ox-events-7f3k", "events": ["server.created", "server.deleted", "balance.low"]}'
The response includes a whsec_... secret, shown only once: save it in your n8n credentials.
5. Send a ping test event (POST https://0x.cloud/v1/webhooks/{id}/test) and check the run in the Executions tab.
Every event arrives as a POST with the body {"id": "evt_...", "event": "server.created", "created_at": "...", "data": {...}}. Branch the workflow with a Switch node on {{ $json.body.event }}. 0x.cloud expects a 2xx response within 8 seconds or it retries (6 attempts over about 14 hours), so the same event can arrive twice: deduplicate on id.
| URL | When it works | Where you see data |
|---|---|---|
| Test URL | 120 seconds after Listen for Test Event | right in the editor |
| Production URL | after the workflow is published | Executions tab |
Details in the n8n Webhook node docs. The webhook URL must be reachable from the internet over HTTPS; self-hosted n8n needs a domain and a certificate, covered in the install guide.
Secure the Webhook
- Use a long random path instead of
test: the webhook URL effectively works as a password. - Verify the signature. 0x.cloud sends
X-0x-Signature: t=<unix>,v1=<hex>, wherev1is an HMAC-SHA256 oft + "." + request bodykeyed with yourwhsec_...secret. Turn on the Raw Body option in the Webhook node, then add a Code node:
// self-hosted n8n: requires NODE_FUNCTION_ALLOW_BUILTIN=crypto
const crypto = require('crypto');
const secret = 'whsec_...'; // better: read from an environment variable
const sig = Object.fromEntries(
$input.first().json.headers['x-0x-signature'].split(',').map(p => p.split('='))
);
const raw = (await this.helpers.getBinaryDataBuffer(0, 'data')).toString('utf8');
const expected = crypto.createHmac('sha256', secret).update(`${sig.t}.${raw}`).digest('hex');
const fresh = Math.abs(Date.now() / 1000 - Number(sig.t)) < 300;
if (expected !== sig.v1 || !fresh) throw new Error('bad signature');
return [{ json: JSON.parse(raw) }];
- Ignore event types you did not subscribe to.
Where to Run n8n
These workflows need n8n running 24/7, or webhooks and schedules are missed. Run them on n8n Cloud or on your own n8n that is reachable over HTTPS. 0x.cloud servers have no public IP address, so an n8n on one of them cannot open its editor in your browser or receive webhooks. Everything the API offers automation is on VPS with API.
Common Errors and Fixes
| Symptom | Cause | Fix |
|---|---|---|
401 in HTTP Request |
key without Bearer, extra space, Predefined instead of Generic |
Generic Credential Type → Header Auth, Bearer key |
422 after Import cURL |
numbers and true became strings |
body in Using JSON mode |
| Production URL returns 404 | workflow not published | publish it |
| Test URL catches nothing | not listening, or the 120 seconds ran out | click Listen for Test Event and resend |
409 price_changed on the "Create" node |
more than 10 minutes since the quote, or parameters changed | run the nodes back to back and keep plan and billing_cycle identical |
| 422 when registering the webhook with 0x.cloud | URL is not https or not public | use a domain with a certificate; localhost and private IPs are rejected |
| node stops on an API error you want to handle | non-2xx responses stop the workflow by default | Options → Never Error, then IF on the status |
| webhook never reaches self-hosted n8n | no HTTPS or not reachable | domain, certificate, N8N_WEBHOOK_URL in n8n settings |
FAQ
How do I send a Bearer token in the HTTP Request node? Set Authentication to Generic Credential Type, pick Header Auth, and create a credential with Name Authorization and Value Bearer followed by a space and your key. The key lives in n8n credentials, not in the node.
What is the difference between the Test URL and Production URL? The Test URL listens for 120 seconds after you click Listen for Test Event and shows data in the node. The Production URL works once the workflow is published, and runs appear in the Executions tab.
Can I paste a curl command into n8n? Yes. In the HTTP Request node click Import cURL, paste the command and click Import. Numbers and booleans become strings, so switch the body to Using JSON when types matter.
How do I create a server from n8n? Use two HTTP Request nodes: the first POSTs to /servers with dry_run: true and gets the price and a pricing_fingerprint, the second repeats the request without dry_run and with that pricing_fingerprint. An IF node in between checks the budget.