šŸ†˜ URGENT: WhatsApp Flow Endpoint - "Response body is not Base64 encoded" Error

Platform: Self-hosted n8n 1.108.1
Issue: WhatsApp Flow endpoint validation failing
Error: ā€œResponse body is not Base64 encodedā€ + ā€œFailed to decrypt responseā€

:bullseye: What I’m Trying to Achieve

Building a WhatsApp Flow endpoint for Meta’s WhatsApp Business Manager that:

  • Handles ping/health check requests

  • Processes encrypted Flow submissions (INIT, data_exchange)

  • Returns properly encrypted Base64 responses per Meta’s specification

:wrench: Current Setup

  • Self-hosted n8n with Docker Compose + Traefik

  • SSL enabled at https://n8n.srv977544.hstgr.cloud

  • Environment variables set:

    text
    

    N8N_ENABLE_RAW_EXECUTION=true NODE_FUNCTION_ALLOW_BUILTIN=fs,crypto,path,os

  • Private key mounted correctly (PKCS#8 encrypted format)

  • Workflow structure: Webhook → Code Node → Respond to Webhook

:collision: The Problem

WhatsApp Flow validation keeps failing with:

  1. ā€œResponse body is not Base64 encodedā€ - Even when returning Base64 strings

  2. ā€œFailed to decrypt responseā€ - WhatsApp can’t decrypt my encrypted responses

:test_tube: What I’ve Tried

Attempt 1: Raw Base64 Response

javascript

returnencryptedData.toString('base64');// n8n error: not array format

Attempt 2: JSON Wrapped Response

javascript

return[{ json: { base64Response: encrypted.toString('base64') } }];// Respond to Webhook: {{$json.base64Response}}

Attempt 3: Different Encryption Approaches

  • Random AES keys for ping → WhatsApp can’t decrypt

  • Simple Base64 JSON for ping → ā€œnot Base64 encodedā€ error

  • Using WhatsApp’s provided AES keys → still fails

:clipboard: Current Code Structure

javascript

constitems = $input.all();constbody = items[0].json; // For ping requests if(body.action === 'ping' || !body.encrypted_flow_data) { constresponseData = { version: "3.0", data: { status: "active" } }; // What format should this return???} // For encrypted requests // RSA decrypt AES key → AES-GCM decrypt → process → encrypt response

:thinking: Key Questions

  1. Response format: Should ping responses be simple Base64-encoded JSON or encrypted data?

  2. n8n compatibility: How to return raw Base64 strings that WhatsApp expects?

  3. Encryption keys: For ping responses, what keys should I use if none provided?

  4. Meta specification: Anyone successfully implemented WhatsApp Flow endpoints in n8n?

:link: Meta Documentation Reference

Following: https://developers.facebook.com/docs/whatsapp/flows/guides/implementingyourflowendpoint

:folded_hands: Looking For

  • Working n8n WhatsApp Flow implementation examples

  • Encryption strategy for ping vs encrypted requests

  • Response format that passes Meta validation

  • Environment variable configurations that work

Has anyone successfully implemented WhatsApp Flow endpoints (not regular WhatsApp messaging) with n8n? Any insights on the proper encryption/response format would be hugely appreciated!

Tags: #whatsapp-flow #encryption #base64 #meta-api #webhook-response

I faced a similar headache when working with file/image uploads in n8n — the platform often wraps or misformats binary/Base64 data, which leads to errors like the one you’re seeing (not Base64 encoded).

I wrote a blog explaining how to correctly handle binary ↔ Base64 data in n8n, and return it in the raw format that external APIs (like Meta’s WhatsApp Flow) expect. While it doesn’t cover the RSA/AES-GCM crypto part, the Base64 response formatting piece should help you clear that specific error.

https://medium.com/@rupaliofficialmail/how-to-handle-image-uploads-in-n8n-forms-binary-file-fix-d4cd2cab469d

1 Like