Skip to content

Lesson 4 of 5 · 10 min

Let the brain act with webhook actions

Create a custom action so the brain can act in any system through n8n, and verify the signature of each call before doing anything with it.

The ready-made integrations cover email, calendar, HubSpot, WhatsApp and spreadsheets. For everything else (creating an invoice in Siigo, recording a payment in the ERP, looking up a balance) there's the custom action: a new brain tool that calls a webhook in your automation. The brain decides what to do and when; your automation takes care of how to do it in the client's system.

What you'll achieve

  • Create a custom action with a good description and just the right data.
  • Build an n8n flow that verifies the Zunous signature and doesn't process the same call twice.
  • Reply to the brain with a result that is recorded in the log.

Create the action in the Console

Only an admin can do this.

  1. In Autonomous Mode, go to Custom actions and click New action.
  2. Name: lowercase letters, numbers and _, for example crear_factura. The brain will see it as the tool accion.crear_factura.
  3. Webhook URL: the one n8n, Make, Power Automate or Zapier gives you. It must start with https://, use port 443 and a public domain.
  4. What it does and when to use it: 10 to 500 characters. This is the most important part, because the brain reads it to decide. Example: "Creates an invoice in Siigo when a customer accepts a proposal and already has a registered NIT (tax ID)".
  5. Data it sends: one per line, in the form name:type:description. The types are texto (text), numero (number) or si_no (yes/no); add an asterisk at the end of the name if it's required, for example nit*:texto:Customer's NIT. Up to 15 fields.
  6. Choose the Type: "Action" if it changes something in the system, or "Lookup" if it only fetches information. A lookup doesn't go through drafts and doesn't count toward the plan.
  7. Choose the Autonomy level (start at Draft), the Daily call cap (1 to 1,000, default 50) and, if you want, the Skills that can use it. If you don't select any, all of them use it.
  8. Click Create action.

The Console shows the Signing secret, which starts with whsec_, only once. Store it as a credential in your automation. If it's lost, click New signing secret and update it in the flow. Each brain supports up to 20 actions.

What your automation receives

Zunous sends a POST with a JSON body and these headers:

HeaderWhat it's for
Zunous-EventThe action, for example accion.crear_factura
Zunous-DeliveryUnique ID of the delivery; it repeats if Zunous retries
Zunous-TimestampTimestamp in seconds
Zunous-SignatureThe signature, in the form v1= followed by a hexadecimal value

The body includes accion, organizacion, brain, ejecucion, aprobada_por (the email of whoever approved, or null if the brain acted on its own), datos (only the fields you defined) and, on test calls, "prueba": true.

Verify the signature in n8n

Anyone who knows the URL could call it. The signature proves the call comes from Zunous and that nobody changed the content. Build the flow like this:

  1. Webhook node, POST method, with the Raw Body option turned on to receive the body exactly as it arrived.
  2. Crypto node, action Hmac, type SHA256, encoding hex. The text to sign is the timestamp, a period and the raw body: <Zunous-Timestamp>.<body>. The key is the full secret, including whsec_, stored as a credential.
  3. IF node that continues only if v1= plus the result equals the Zunous-Signature header, and if the timestamp is no more than 5 minutes old.
  4. A step that stores the Zunous-Delivery (for example in a data table or a spreadsheet) and discards deliveries it has already seen. That way a retry doesn't create two invoices.
  5. If prueba is true, respond without touching the real system.
  6. The step that does the work, for example creating the invoice.
  7. Respond to Webhook node with code 200 and a JSON with a resultado field.

Reply to the brain

  • Respond 2xx when you're done. If you return a JSON with resultado, the brain reads that text (up to 2,000 characters) and it's recorded in the log. Example: {"resultado": "Invoice FV-1023 created for $1,200,000"}.
  • Respond 4xx if the data isn't usable. The action is marked as an error, the brain knows it and Zunous doesn't retry.
  • If you respond 5xx, don't respond within 10 seconds or the network fails, Zunous retries once after one second, with the same Zunous-Delivery. If it fails again, the brain receives the error.
  • Zunous doesn't follow redirects: a 3xx response counts as an error.

Before using it for real, click Send test on the action's card. Zunous calls your webhook with sample data and "prueba": true, without counting toward the cap, and the Console shows you what your automation responded.

Practice

Muebles Roble S.A.S., a furniture maker in Envigado, uses Siigo and wants the Collections Brain to record payment agreements:

  1. Create the registrar_acuerdo action with the description "Records in Siigo a payment agreement accepted by the customer, with the number of installments and the amount of each installment".
  2. Define the data: nit*:texto:Customer's NIT, factura*:texto:Invoice number, cuotas*:numero:Number of installments, valor_cuota*:numero:Amount of each installment in pesos.
  3. Type "Action", level Draft, cap of 20 per day, skill negociar_acuerdo_pago.
  4. Build the n8n flow with the seven steps above and store the whsec_… secret as a credential.
  5. Click Send test and confirm the Console shows your resultado.
  6. Change one character of the secret in n8n, test again and check that the IF node stops the call.

Check what you learned

1. Which part of the custom action does the brain use to decide when to call it?

2. Your automation received the same call twice with the same Zunous-Delivery. What do you do?

3. What do you respond if the data the brain sent isn't usable, for example a NIT that doesn't exist?