Skip to content

AWS End User Messaging Social - WhatsApp SendWhatsAppMessage InvalidParametersException

0

I'm implementing WhatsApp integration using AWS End User Messaging Social in a Python Lambda function. While I can successfully receive WhatsApp messages via SNS webhooks and create cases in my application, I'm unable to send WhatsApp messages back to customers due to persistent InvalidParametersException errors. Environment Details

Service: AWS End User Messaging Social Region: eu-central-1 Runtime: Python 3.13 Lambda boto3: Latest version Phone Number ID: I have a verified WhatsApp Business number with a phone number id

Current Setup

WhatsApp Business Account properly linked to AWS End User Messaging Social Receiving incoming messages works perfectly (webhook → SNS → Lambda → case creation) IAM permissions include: social-messaging:SendWhatsAppMessage, social-messaging:GetWhatsAppMessageMedia Phone number verified and active for receiving messages

The Issue When attempting to send WhatsApp messages using send_whatsapp_message(), I consistently get InvalidParametersException with varying error messages depending on the format used: Error Variations:

"Failed to parse WhatsApp message request" - with certain message formats "Invalid message version" - with different API versions

Code Attempts I've tried multiple combinations based on AWS documentation: Message Format Variations: python# Attempt 1: Base64-encoded bytes message_data = base64.b64encode(json.dumps(whatsapp_message).encode('utf-8'))

Attempt 2: Base64-encoded string

message_data = base64.b64encode(json.dumps(whatsapp_message).encode('utf-8')).decode('utf-8')

Attempt 3: JSON string

message_data = json.dumps(whatsapp_message)

Attempt 4: JSON bytes

message_data = json.dumps(whatsapp_message).encode('utf-8') API Versions Tested:

v20.0, v19.0, v18.0, v17.0, v16.0, v15.0, v14.0, v13.0

WhatsApp Message Structure: pythonwhatsapp_message = { "messaging_product": "whatsapp", "to": "254719123***", # Kenya phone number (cleaned, international format) "type": "text", "text": { "body": "Hi {name}, Thank you for contacting our support team" } } API Call: pythonresponse = social_messaging_client.send_whatsapp_message( originationPhoneNumberId="phone-number-id-{id}", metaApiVersion="v20.0", # Also tried v15.0, v18.0, etc. message=message_data ) What Works vs What Doesn't ✅ Working: Receiving WhatsApp messages via webhooks ✅ Working: Parsing incoming message data ✅ Working: Creating support cases from WhatsApp messages ❌ Not Working: Sending WhatsApp messages back to customers Questions

What is the correct message parameter format for send_whatsapp_message()? Should it be Base64-encoded bytes, Base64-encoded string, or raw JSON? Which metaApiVersion is supported by AWS End User Messaging Social? The documentation mentions v15.0, but I've seen references to v20.0 in Meta's documentation. Are there any specific requirements for the WhatsApp message structure when using AWS End User Messaging Social vs direct Meta WhatsApp Business API? Has anyone successfully implemented bidirectional WhatsApp messaging using AWS End User Messaging Social in Python? If so, could you share a working code example?

Use Case Context We're building a multi-channel customer support platform that handles:

Email support (working ✅) Web portal submissions (working ✅) WhatsApp support (partially working - can receive but not send)

The goal is to provide automatic acknowledgement messages when customers contact us via WhatsApp, and enable agents to reply from our dashboard. What I've Already Tried

Followed AWS End User Messaging Social documentation exactly Tested all combinations of message formats and API versions Verified IAM permissions and WhatsApp Business Account setup Confirmed phone number formatting (international format, 10-15 digits) Contacted AWS Support (got general guidance but no working example)

Any help or working examples would be greatly appreciated! This seems like it should be straightforward, but the documentation lacks specific Python implementation details for the message parameter format.

1 Answer
0
Accepted Answer

Update: I'm happy to report that our WhatsApp integration with AWS End User Messaging Social is now working perfectly!

What Fixed It: The issue was with the message parameter format. Despite the AWS documentation stating that the message should be a "Base64-encoded binary data object," the actual working format is: message = json.dumps(whatsapp_message) # Plain JSON string

Working Code Example:

pythonimport boto3
import json

social_messaging_client = boto3.client('socialmessaging')

whatsapp_message = {
    "messaging_product": "whatsapp",
    "to": "+123456****",  # Include + prefix with country code
    "type": "text",
    "text": {
        "body": "Thank you for contacting us!"
    }
}

response = social_messaging_client.send_whatsapp_message(
    originationPhoneNumberId="phone-number-id-your-id-here",
    metaApiVersion="v20.0",
    message=json.dumps(whatsapp_message)  # Key: JSON string, not Base64!
)

Key Points:

  • Message format: Use json.dumps() directly, not Base64 encoding
  • Phone format: Include the + prefix (e.g., +12345****)
  • API version: v20.0 works perfectly
  • Documentation gap: The official docs mention Base64 but the service expects JSON strings

For AWS Team: There appears to be a discrepancy between the official documentation and the actual API implementation. The documentation should be updated to reflect that the message parameter expects a JSON string, not Base64-encoded binary data. Hope this helps others implementing WhatsApp with AWS End User Messaging Social.

answered 9 months ago
AWS
SUPPORT ENGINEER
reviewed 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.