This workflow demonstrates a fundamental pattern for securing a webhook by requiring an API key. It acts as a gatekeeper, checking for a valid key in the request header before allowing the request to proceed.
Secured Webhook node receives an incoming POST request. It expects an API key to be sent in the x-api-key header.Check API Key node takes the key from the incoming request's header.Get API Key) which acts as a mock database.Registered API Keys node) and filters it to find a match for the key that was provided.API Key Identified node routes the execution to the "success" path, returning a 200 OK response with the identified user's ID.401 Unauthorized error.This pattern separates the public-facing endpoint from the data source, which is a good security practice.
Setup time: ~2 minutes
This workflow is designed to be a self-contained example.
X-N8N-Auth, Value: my-secret-password). Select this credential in all four webhook/HTTP Request nodes.Registered API Keys node. This is your mock database. Edit the array to include the user_id and api_key pairs you want to authorize.Test Secure Webhook node to send a request.
x-api-key header to an invalid key to see the 401 Unauthorized error.For Production: Replace the mock database part of this workflow (the Get API Key webhook and Registered API Keys node) with a real database node like Supabase, Postgres, or Baserow to look up keys.


