SSE Trigger Extended

Triggers the workflow when Server-Sent Events occur with support for custom headers

Overview

This node listens to Server-Sent Events (SSE) from a specified SSE endpoint URL and triggers the workflow whenever an event is received. It supports authentication methods including Bearer token and custom header authentication, as well as sending additional custom headers with the connection request.

Common scenarios where this node is beneficial include:

  • Real-time monitoring of server events such as notifications, logs, or status updates.
  • Integrating live data streams into workflows without polling.
  • Reacting instantly to changes pushed by external services that support SSE.

Practical example:

  • Listening to a stock price update stream and triggering actions when prices change.
  • Receiving real-time alerts from a monitoring system and automating incident responses.

Properties

Name Meaning
SSE Endpoint The URL of the SSE endpoint to connect to and listen for Server-Sent Events.
Authentication Method to authenticate with the SSE endpoint. Options: Bearer Auth (uses a bearer token), Header Auth (custom header key-value), or None (no authentication).
Credentials The credentials used for authentication if Bearer Auth or Header Auth is selected.
Send Custom Headers Whether to send additional custom headers along with the SSE connection request, in addition to authentication headers.
Specify Headers How to specify the custom headers to send: either using individual key-value fields or providing a JSON object representing headers.
Header Parameters When specifying headers via key-value pairs, this allows adding multiple custom header name-value pairs.
Headers (JSON) When specifying headers via JSON, this field contains the JSON object representing all headers to send.
Options Additional options for the SSE connection:
- Connection Timeout (ms): Time to wait before aborting the connection attempt.
- Retry Attempts: Number of times to retry on failure.
- Retry Delay (ms): Delay between retries.

Output

The node outputs JSON objects representing each SSE event received. Each output item includes:

  • The parsed event data (attempted JSON parsing; if invalid JSON, raw string data is included).
  • Metadata about the event under $metadata, containing:
    • eventType: The SSE event type (default "message" if not specified).
    • lastEventId: The last event ID sent by the server.
    • origin: The SSE endpoint URL.
    • timestamp: ISO timestamp when the event was processed.
    • retry: The retry time suggested by the server for reconnection.

If an error occurs (e.g., connection failure or invalid JSON in headers), the output will contain an error field describing the issue along with relevant metadata.

The node does not output binary data.

Dependencies

  • Requires an active internet connection to reach the specified SSE endpoint.
  • If authentication is enabled, requires appropriate API credentials configured in n8n (an API key or token credential).
  • Uses standard Fetch API with AbortController for HTTP requests.
  • No additional external libraries beyond those bundled with n8n are required.

Troubleshooting

  • Invalid JSON in Headers: If specifying custom headers as JSON, ensure the JSON is valid. An error message like Invalid JSON in headers: ... indicates malformed JSON input.
  • Connection Failures: Errors such as HTTP 4xx/5xx or network errors will trigger retries based on configured retry attempts and delay. After max retries, an error event is emitted.
  • Timeouts: If the connection does not establish within the specified timeout, it will abort and retry.
  • Authentication Issues: Ensure correct credentials are provided and valid for the chosen authentication method.
  • No Events Received: Verify the SSE endpoint URL is correct and actively sending events. Also check network connectivity and firewall settings.

Links and References

Discussion