Websocket icon

Websocket

Interact with ws stream

Actions2

Overview

This node allows interaction with WebSocket streams within an n8n workflow. Specifically, it supports sending messages over a WebSocket connection and closing an existing WebSocket connection. The "Close Connection" operation is used to terminate an active WebSocket connection that was previously established or received from a trigger node.

Common scenarios include:

  • Gracefully closing a WebSocket connection after completing data exchange.
  • Managing WebSocket lifecycle in workflows that require opening, using, and then closing connections dynamically.

For example, after receiving real-time updates via a WebSocket trigger, you might want to close the connection once certain conditions are met to free resources.

Properties

Name Meaning
Websocket Resource Field (Parameter Name) The name of the field in the incoming JSON that holds the WebSocket resource object. This must match the field set by the WebSocket trigger node (default: "ws").

Output

The output JSON contains:

  • A success boolean indicating whether the close operation was successful.
  • The original WebSocket resource object under the key specified by the "Websocket Resource Field" property.

Example output JSON structure:

{
  "success": true,
  "ws": { /* WebSocket resource object */ }
}

No binary data is output by this node.

Dependencies

  • Requires a valid WebSocket resource object passed into the node's input data under the specified field name.
  • Typically used in conjunction with a WebSocket trigger node that provides the WebSocket resource.
  • No external API keys or credentials are required for the close operation itself.

Troubleshooting

  • Error: "Execution error: No websocket resource received"
    This occurs if the input data does not contain the WebSocket resource under the specified field name.
    Resolution: Ensure the input JSON includes the WebSocket resource object under the exact field name configured in the node's property (e.g., "ws"). This usually means connecting this node directly after a WebSocket trigger node or another node that outputs the WebSocket resource.

  • If the connection fails to close properly, verify that the WebSocket resource is still valid and has not been closed or invalidated earlier in the workflow.

Links and References

Discussion