Skip to content
NEWMarketplace and the trig8n Agent: sell what you build, and get plans and changes that are tested before you see them. See what is new

Library / Security & Compliance

Security & Compliance

Secure a Public Webhook with Auth and Validation

When a request hits the webhook, it checks the authorization header and required fields, then replies with 200, 400 or 401 accordingly.

What it does

## 🔐 Secure Webhook – Summary *This workflow protects a public webhook with authentication and payload validation.* --- #### 🧩 Why use it? - ✅ Ensure only trusted clients can call your workflow (via Bearer token). - ✅ Validate that all expected fields are present in the request body. - ✅ Return helpful and consistent JSON responses (200, 400, 401). --- #### ⚙️ How it works: 1. Webhook – Entry point for external POST requests. 2. Configuration – Defines config.bearerToken and config.requiredFields. 3. Check Authorization Header – Compares incoming Bearer token with config. 4. 401 Unauthorized – Returned if the token is missing or incorrect. 5. Has required fields? – JS code checks for required fields in the request body. 6. 400 Bad Request – Returned if any required field is missing. 7. Create Response & 200 OK – Returns a custom success message. --- #### 🛠 Setup Instructions: - Set your desired Bearer token in config.bearerToken. - For each required field, set a key in config.requiredFields *(e.g., config.requiredFields.message)*. *👉 The value doesn't matter, only the keys are checked.* - Replace the Add workflow nodes here node with your own workflow logic. - Edit the Create Response node to build your response. --- 📌 *Great for building secure, reusable webhook endpoints for APIs, forms, or 3rd-party services.*

The steps

  1. Check Authorization Header
  2. 401 Unauthorized
  3. 200 OK
  4. Configuration
  5. Webhook
  6. Has required fields?
  7. Check Valid Request
  8. 400 Bad Request
  9. Create Response
  10. Add workflow nodes here
  11. Error Handler
  12. Stopanderror 1
  13. Stopanderror 2
  14. Stopanderror 3

31 steps in total.

Similar automations