Overview
This node defines a custom function that can be called by other nodes in an n8n workflow using the "CallFunction" mechanism. It allows users to create reusable, named functions with defined parameters that can be invoked elsewhere in workflows. The node registers itself as a callable function and waits for calls from "CallFunction" nodes, passing input data through and returning results asynchronously.
Common scenarios where this node is beneficial include:
- Encapsulating complex logic or calculations into reusable functions.
- Sharing common processing steps across multiple workflows or parts of a workflow.
- Creating modular workflows where specific tasks are implemented as callable functions.
Practical example:
- A workflow has a function node named "CalculateDiscount" that accepts parameters like
priceanddiscountRate. Other workflows or nodes can call this function to get the discounted price without duplicating the calculation logic.
Properties
| Name | Meaning |
|---|---|
| 🏷️ To name your function, rename this Function node in your workflow. | Notice instructing users to rename the node to set the function's name. |
| Function Description | Optional text describing what the function does; shown in the CallFunction dropdown for easier selection. |
| Parameters | Collection of parameters the function accepts. Each parameter includes: |
| - Parameter Name (required): The name identifier of the parameter. | |
| - Type: Data type of the parameter (Array, Boolean, Number, Object, String). | |
| - Required: Whether the parameter must be provided when calling the function. | |
| - Default Value: Optional default value if none is provided. | |
| - Description: Explanation of what the parameter does. | |
| ⚠️ IMPORTANT: Add a 'Return from Function' node or your function will run forever! | Notice reminding users to add a ReturnFromFunction node to properly return values and avoid hanging calls. |
Output
The node outputs the input data it receives during workflow execution unchanged (passes through input items). When triggered as a callable function, it emits an item containing:
json: An object combining:- The original input JSON merged with the function parameters passed in the call.
- A special
_functionCallobject containing metadata about the call such as call ID, function name, and timestamp. - After the function completes, a
_functionReturnfield with the returned value from the ReturnFromFunction node.
binary: Any binary data from the input is passed through unchanged.
This output structure enables downstream nodes to access both the original data and the function call context, as well as the eventual return value.
Dependencies
- Requires an API key credential or similar authentication to connect to Redis for managing function calls and worker registration.
- Uses Redis for function call queuing, notifications, and result storage.
- Depends on internal modules for function registry management, lifecycle management, and logging.
- No external HTTP APIs are directly called by this node.
Troubleshooting
- Missing Function Name: If the node's name is not set, it throws an error requiring the function name. Solution: Rename the node to give the function a unique name.
- Required Parameter Missing: If a required parameter is not provided when the function is called, an error is thrown specifying which parameter is missing. Solution: Ensure all required parameters are supplied.
- No ReturnFromFunction Node: Without a ReturnFromFunction node downstream, the function call will hang indefinitely because it waits for a return value. Solution: Add a ReturnFromFunction node to provide the return value.
- Redis Configuration Missing: Errors occur if Redis configuration is unavailable or incorrect. Solution: Configure Redis connection settings properly in n8n environment.
- JSON Parsing Errors: If input or item data cannot be parsed as JSON, errors are thrown. Solution: Verify that inputs are valid JSON or correctly formatted objects.
- Worker Registration Issues: Problems unregistering or registering workers may cause race conditions or stale workers. Solution: Restart workflows or n8n instance to clear stale workers.