Ir para o conteúdo

Lição 10 · APIs and Integrations

The HTTP Request Node: Call Any API

Call APIs with the n8n HTTP Request node: methods, URLs, query parameters, headers, JSON bodies, response status codes, timeouts and safe handling of replies.

Many services do not have a dedicated n8n node, and sometimes a node lacks the operation you need. The HTTP Request node can call almost any web API. If you understand HTTP basics, you can connect nearly anything.

Anatomy of a request

A request has five parts

Method GET, POST, PATCH...
URL Which resource
Headers Extra information
Body Data you send
1 / 2
Method Typical meaning
GET Read data
POST Create or trigger something
PUT / PATCH Replace / partly change
DELETE Remove

Always check the API's own documentation. Services differ in paths, field names and rules.

A typical configuration

TEXT
Method:  GET
URL:     https://api.example.com/v1/orders
Query:   status = open
         limit  = 50
Headers: Accept: application/json
Auth:    a saved credential

Put values that change in expressions, such as {{ $json.customerId }}. Add query parameters with the node's fields rather than gluing text into the URL, so special characters are encoded correctly.

For a POST with a JSON body, enter the fields or write JSON that includes expressions. Make sure text values are quoted and escaped. Building the body with the node's key and value fields avoids broken JSON when a value contains a quote.

Many API docs show a curl example. The node has an Import cURL option that fills in its settings from a command. It replaces the current settings and treats parameter values as text, so check numbers and true/false values. Afterwards, remove any secret keys that got pasted into plain fields and use a credential instead.

Reading status codes

Range Meaning What to do
2xx Success Continue
3xx Redirect Usually followed automatically; check options
400 Bad request Fix your data
401 / 403 Not authenticated or not allowed Check credential and permissions
404 Not found Check URL and ID
429 Too many requests Slow down and retry later
5xx Server problem Retry with care

By default, error status codes make the node fail. There are options to receive the full response, including status code and headers, or to avoid failing on error codes so you can branch yourself. Read error handling before choosing.

Safe request building

This stand-in builds URLs and bodies with the standard library, without sending anything. Notice how special characters are encoded.

Python Stand-in: build a request without sending it

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.

Handling responses

If the API returns JSON, the node usually gives you items you can use directly. Some APIs wrap results, for example { "data": [ ... ] }, so add Split Out on data. Set a timeout so a slow service does not hang your workflow. For files, tell the node to receive a binary response.

JS Stand-in: decide what to do from a status code

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

No output.

Security with outgoing requests

If a URL comes from user input, an attacker might point it at internal services on your network. This is called server-side request forgery (SSRF). Do not let users choose arbitrary hosts. Check against an allowlist, and use n8n's SSRF protection settings on self-hosted instances; see security. Do not send data to services you have not approved.

Common mistakes

  • Typing a secret into a header field in plain text. Use credentials.
  • Building JSON by concatenating strings.
  • Retrying a POST blindly, which may create two records.

Try a request outside n8n

When a request fails, remove n8n from the equation. Send the same request with a tool such as curl from a safe machine, using a test key. If it fails there too, the problem is the request or your permissions. If it works there but not in n8n, compare the exact URL, headers and body in the node's settings and output. Check for stray spaces in the URL, a missing Content-Type header and a body sent as a form when the API expects JSON.

Also decide what your workflow needs from the reply. If it needs only an ID, extract that field into a clean record. Passing a large raw response through every later node makes executions bigger, slows debugging and may store data you did not need to keep.

Practice

Read the documentation of any public API you are allowed to use, or imagine one for orders. Write the method, URL, query parameters, headers and authentication for these three tasks: list open orders, create a note on one order and delete a test record. For each, say which status codes you expect, which ones should be retried and which should stop the workflow. Mark which requests are safe to repeat. Only then configure the node, starting with the read-only request and test data. Delete comes last, with a test record you created yourself.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. What does status 429 usually mean?

    429 asks you to slow down.
  2. 2. Why use the node's query parameter fields?

    The node encodes special characters, so URLs stay valid.
  3. 3. Why is it risky to let users supply any URL for a request?

    That is server-side request forgery.

Summary

  • The HTTP Request node connects n8n to almost any API.
  • Set method, URL, parameters, headers, body and a credential.
  • Status codes tell you whether to continue, fix or retry.
  • Encode values properly, set timeouts and guard against unsafe URLs.

Next: Credentials and Authentication

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