Skip to content

    Arabic or English · ↑↓ to move · Enter to open · Esc to close

    العربية
    On this page

    Connect Mursilat to n8n

    Send WhatsApp messages from n8n with the API and receive Mursilat events in a Webhook node with signature checks — with ready-to-import workflows.

    Ready-made files

    In n8n: Workflows → Import from file. Both are tested on n8n 2.47.2.

    1. Get an API key

    1. Your plan must include the API (Developer, Growth or Business), else 403 API_ACCESS_NOT_IN_PLAN.
    2. In Settings → API keys create a key with only the scopes you need: numbers:read, messages:send, messages:read, links:write, plus webhooks:read and webhooks:write to set the webhook through the API.
    3. The key (wsl_live_…) is shown once: copy it right away.

    2. The n8n credential

    FieldValue
    Credential typeValueHeader Auth
    NameValueAuthorization
    ValueValueBearer wsl_live_…

    In every HTTP Request node: Authentication = Generic Credential Type → Header Auth. Base URL: https://mursilat.com/api/v2, so GET /v2/me is https://mursilat.com/api/v2/me; try it first.

    3. Send from n8n

    1. Settings: set your numberId, the customer to (with country code) and the template name and language.
    2. Send template: POST /v2/messages with type: "template" and the Idempotency-Key header (required): the workflow uses n8n-{{ $execution.id }}-template so a retry never sends twice.
    3. Create tracked link: POST /v2/links returns a tracked wa.me link; chats started from it send conversation.attributed.
    Send template — body
    {
      "numberId": "cm1…",
      "to": "201001234567",
      "type": "template",
      "template": { "name": "order_shipped", "language": "ar", "params": ["Mona", "1042"] }
    }

    Outside the 24-hour window only approved templates can be sent (409 CLOUD_API_WINDOW_CLOSED). For many recipients use POST /v2/campaigns with content.type: "template" instead of an n8n loop. The API has no contacts endpoints (privacy): keep customers in your own store from webhook events.

    4. Receive events in n8n

    1. Webhook node: POST, path mursilat, Respond = Using 'Respond to Webhook' Node, and Raw Body = ON.
    2. Activate the workflow and copy the Production URL (public https on port 443; localhost and port 5678 are refused).
    3. Register it: PUT /v2/webhook with {"url": "…/webhook/mursilat", "events": null} (or per number: PUT /v2/numbers/{numberId}/webhook). The secret is returned the first time only; lost it? POST /v2/webhook/rotate-secret.
    4. Give n8n the secret: env var MURSILAT_WEBHOOK_SECRET (self-hosted, with NODE_FUNCTION_ALLOW_BUILTIN=crypto) or inside the Code node (n8n Cloud).
    5. Test with POST /v2/webhook/test and check GET /v2/webhooks/deliveries.

    5. Verify the signature

    Compute HMAC-SHA256 of "<t>.<raw body>" with the secret, compare it with v1 of X-Wasla-Signature in constant time, and reject a t older than 5 minutes. Answer 2xx within 10 seconds and drop duplicates by id.

    // Node.js + Express. Use the RAW body: JSON.parse → JSON.stringify changes bytes and breaks the signature.
    import crypto from 'node:crypto';
    import express from 'express';
    
    const app = express();
    const SECRET = process.env.WASLA_WEBHOOK_SECRET;
    const seen = new Set(); // use Redis/DB in production
    
    function verifyWaslaSignature(rawBody, header, secret, toleranceSec = 300) {
      if (!header || !secret) return false;
      const parts = {};
      for (const pair of header.split(',')) {
        const i = pair.indexOf('=');
        if (i > 0) parts[pair.slice(0, i).trim()] = pair.slice(i + 1).trim();
      }
      const t = parts.t;
      const v1 = parts.v1;
      if (!/^\d+$/.test(t || '') || !/^[0-9a-f]{64}$/i.test(v1 || '')) return false;
      // Reject old (replayed) or far-future timestamps.
      if (Math.abs(Math.floor(Date.now() / 1000) - Number(t)) > toleranceSec) return false;
      const expected = crypto
        .createHmac('sha256', secret)
        .update(t + '.')
        .update(rawBody) // the RAW bytes exactly as received, not re-serialized JSON
        .digest();
      const received = Buffer.from(v1, 'hex');
      return received.length === expected.length && crypto.timingSafeEqual(received, expected);
    }
    
    app.post('/webhooks/mursilat', express.raw({ type: 'application/json' }), (req, res) => {
      if (!verifyWaslaSignature(req.body, req.get('X-Wasla-Signature'), SECRET)) {
        return res.status(401).send('invalid signature');
      }
      const event = JSON.parse(req.body.toString('utf8'));
      res.sendStatus(200); // answer fast (within 10s); do the work after
    
      if (seen.has(event.id)) return; // retries reuse the same event id
      seen.add(event.id);
      if (event.type === 'interactive.reply') {
        console.log(event.data.reference, '→', event.data.reply.id);
      }
    });
    
    app.listen(3000);

    6. Common errors

    ErrorFix
    401 API_KEY_REQUIREDFixHeader Authorization with value Bearer wsl_live_….
    403 SCOPE_REQUIREDFixAdd the missing scope (details.required) to the key.
    403 IP_NOT_ALLOWEDFixn8n calls from an IP outside the key allowlist.
    400 IDEMPOTENCY_KEY_REQUIREDFixSend Idempotency-Key on POST /v2/messages, /v2/campaigns and /v2/otp.
    409 CLOUD_API_WINDOW_CLOSEDFixSend a template.
    409 TEMPLATE_NOT_APPROVEDFixWrong template name / language, or not APPROVED yet.
    422 SAFETY_SUPPRESSEDFixThe customer opted out.
    429 RATE_LIMITEDFixWait Retry-After seconds.
    URL_PRIVATE_ADDRESS / URL_PORT_NOT_ALLOWEDFixUse a public https URL on port 443.
    n8n answers 401FixRaw Body is off, the secret is wrong, or the server clock is off.