Core n8n Nodes: HTTP Request, Set, IF, Merge & Code Node Explained
⚡ n8n Workflow Automation T3 · Core Nodes
Core n8n Nodes: HTTP Request, Set, IF, Merge & Code Node Explained

Five core nodes form the backbone of every n8n workflow: the HTTP Request node calls any REST API with full control over method, URL, headers, body, and query params plus built‑in credential management and a 300‑second default timeout; the Set node adds, renames, and removes JSON fields through both manual mapping and a JavaScript mode with Generate Custom Fields; the IF node evaluates conditions with 10 operators combined via AND or OR logic (not mixed); the Merge node consolidates streams through four modes with five join types in Combine mode; and the Code node executes JavaScript (Node.js 18) or native Python with two execution modes. [1] [2]

300s
HTTP Request Default Timeout [1]
2
Set Node Editing Modes [3]
10
IF Comparison Operators [4]
5
Combine Merge Join Types [5]
Node Primary Role Key Operation Output
HTTP Request Call external APIs GET, POST, PUT, PATCH, DELETE JSON, text, binary, HTML
Set Edit JSON fields Add, modify, delete fields Transformed items
IF Binary branching Evaluate condition → true/false 2 output branches
Merge Combine streams Append, Combine, SQL Query, Choose Branch Unified stream
Code Custom logic JavaScript / Python execution Any JSON structure

How do you configure the HTTP Request node to call any REST API with headers, body, and auth?

The HTTP Request node supports all standard HTTP methods—GET, POST, PUT, PATCH, DELETE, HEAD, and OPTIONS—and provides dedicated sections for Query Parameters, Headers, and Body configuration. Built‑in authentication options include Basic Auth, Bearer Token, API Key, and OAuth, selectable from a dropdown rather than requiring manual header construction. The node also accepts cURL imports for rapid prototyping. [1] [6]

The default timeout is 300 seconds, configurable per node in the Options panel. For unstable or rate‑limited APIs, configure retry behavior via the Retry on Fail toggle in node Settings—this enables automatic re‑execution with configurable max retries and wait intervals [1]. Use Query Parameters for dynamic values (e.g., user_id → {{ $json.user_id }}) rather than appending them directly to the URL, which can be unreliable with expressions [7]. For JSON payloads in POST requests, set the Content‑Type header to application/json and construct the body in the Body section; for form‑encoded data, select Form-Data or x-www-form-urlencoded as the body content type. For complex API integrations lacking a native n8n node, the community Better HTTP Request node adds configurable retry logic for specific status codes (default: 429, 500, 502, 503, 504) with up to 10 retry attempts and configurable delay. For the complete expression reference used in dynamic headers and URL parameters, see the n8n Expression Node reference.

How does the Set node add, rename, and remove JSON fields using manual and JavaScript modes?

The Set node (formerly Edit Fields) provides two editing approaches. In Manual Mapping, you define individual fields with name, type (string, number, boolean, or array), and value—static or dynamic expressions ({{ $json.orderTotal * 1.2 }}). The node supports dot‑notation for nested objects: setting address.city creates the nested structure automatically. Enable Keep Only Set to drop unlisted fields and enforce a strict schema. [3] [8]

Since n8n version 1.92.0, the Set node also supports a Generate Custom Fields JavaScript mode. This feature allows defining field generation logic programmatically, where your JavaScript code returns an object whose properties become the output fields. This is especially useful when constructing fields dynamically from upstream data or when maintaining a reusable JSON schema that returns exactly the fields needed. The JavaScript must return a valid object containing fieldName: value pairs—n8n then applies the same output processing as manual mapping. Both modes support referencing data from multiple upstream nodes simultaneously using the expression editor’s data tree [9]. For complex transformations beyond what the Set node can handle, see the n8n Code Node transformation guide.

⚡ Set vs Code Quick Decision: Use the Set node for simple field assignments, renaming, or removal. Switch to the Code node when your transformation requires loops, conditionals, or complex nested restructuring. The Set node’s JavaScript mode bridges the gap for dynamic field generation without requiring a full Code node [3].

How does the IF node evaluate conditions with AND/OR logic and route data to true/false branches?

The IF node evaluates one or more conditions against each incoming data item and routes matching items to the true output and non‑matching items to the false output. It supports 10 comparison operators—equals, not equals, greater than, less than, larger or equals, smaller or equals, contains, not contains, exists, empty—across five data types: String, Number, Date & Time, Boolean, and Array/Object. [4] [10]

Multiple conditions are combined via the Combine field: select AND to require all conditions to be true, or OR to require at least one condition to be true. A single IF node cannot mix AND and OR simultaneously—if mixed logic is required, chain two IF nodes in sequence [10]. For advanced string matching, the node supports regex operations (e.g., email validation with ^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$) and case‑insensitive comparison via the Case Sensitive toggle. For multi‑way routing with three or more distinct outcomes—such as routing support tickets by category or orders by status—switch to the IF & Switch node branching guide.

How does the Merge node combine data streams with Append, Combine, SQL, and Choose Branch modes?

The Merge node provides four operation modes. Append stacks all input items sequentially—input 1 items first, then input 2, supporting up to 10 upstream connections (chain multiple Merge nodes for more). Combine merges two inputs by Matching Fields, Position, or All Possible Combinations. SQL Query runs arbitrary SQL (via AlaSQL) over input tables named input1, input2, etc. Choose Branch waits for both inputs then outputs only the selected branch. [5] [11]

Combine > Matching Fields supports five output types: Keep Matches (inner join), Keep Non‑Matches, Keep Everything (outer join), Enrich Input 1 (left join), and Enrich Input 2 (right join). When fields with the same name clash across inputs, the default behavior prioritizes Input 2; you can change this via Options > Clash Handling, or preserve all values with Always Add Input Number to Field Names. For nested objects, choose Deep Merge (merge all property levels) or Shallow Merge (top‑level properties only). The canonical Split → Process → Merge pattern uses conditional nodes (IF/Switch) to branch, processes each path independently, then reunifies with Merge for a clean output. For the complete pattern guide, see the n8n Node Configuration Hub.

How do you use $input, $json, $itemIndex, and execution modes in the Code node?

The Code node provides two execution modes controlling how data flows in. Run Once for All Items (default) executes once, receiving all items via $input.all() as an array—ideal for aggregation, counting, or cross‑item comparisons. Run Once for Each Item executes separately per item, accessing data through $input.item.json (shorthand: $json)—best for independent transformations. [2] [12]

Six built‑in variables provide data access across modes: $input.all(), $input.first(), $input.last(), $json (shorthand for $input.item.json in Each Item mode), $binary, $itemIndex (0‑based), $workflow, $execution, and $prevNode. JavaScript execution runs on Node.js 18 with support for Promises, async/await, console.log() debugging (requires CODE_ENABLE_STDOUT=true on self‑hosted), and external npm modules via NODE_FUNCTION_ALLOW_EXTERNAL. Native Python execution (version 3.10+) was introduced in n8n 1.63.0, replacing the legacy Pyodide‑based Python introduced in 1.0. The Python mode runs in a sandboxed subprocess and requires the n8n-python package installed on the host. For self‑hosted Docker deployments, use the n8nio/n8n:latest image—the Python runtime is bundled in the container since version 1.63.0 [13]. Both languages must return an array of objects, each containing a json key: return [{ json: { key: "value" } }]. For complete transformation patterns including flatMap expansion of nested arrays, Luxon date formatting, and AJV JSON Schema validation, see the n8n Code Node transformation examples.

⚠️ Common Code Node Pitfall: In “Run Once for All Items” mode, returning a raw array without wrapping each element in { json: {...} } produces the error “A ‘json’ property isn’t an object.” Always return return [{ json: { key: "value" } }]— an array of objects, each with a json key [12].

How do you build a complete workflow combining all five core nodes?

A canonical five‑node pipeline chains: HTTP Request calls an API and returns a JSON array; a Code node in “Run Once for All Items” mode aggregates or transforms the data; a Set node reshapes fields (rename temp_c to temperature, add a processed_at timestamp); an IF node checks a computed field (e.g., temperature > 30 for heat alerts); and a Merge node in Append mode reunifies the true and false branches into a single output stream. [14] [6]

This pattern—pull data, compute, reshape, branch on logic, reunify—appears in marketing analytics, DevOps monitoring, e‑commerce reporting, and customer support dashboards. For paginated API endpoints, add a Set node to initialize a page counter before the HTTP Request node, then loop with an IF node checking whether results exist; for rate‑limited APIs, insert a Wait node between batches. For complete production‑grade pipeline patterns including error handling and retry logic, see the n8n Node Configuration Hub.

References

This guide is for informational purposes only. For the most current and authoritative information, always refer to the official n8n website (n8n.io) and the n8n documentation. Node parameters, defaults, and features may change over time.

Leave a Reply

Your email address will not be published. Required fields are marked *