WATI WhatsApp API¶
Overview¶
The WATI task integrates BaseCloud CRM with WATI's WhatsApp Business API platform, enabling automated WhatsApp messaging including templates, session messages, file sharing, and contact management.
Key Features:
- 5 Actions: Send messages, files, templates, update contacts, retrieve media
- Bearer Token Auth: Simple API key authentication
- Template Messaging: Pre-approved marketing templates with dynamic parameters
- Session Messaging: 24-hour conversational window
- Media Handling: Send files and retrieve media from WATI
- Contact Sync: Update contact attributes in WATI system
Use Cases:
- Automated lead follow-up with template messages
- Invoice delivery via WhatsApp with PDF attachments
- Customer support automation with session messaging
- Contact data synchronization between CRM and WATI
- Marketing campaigns with approved templates
Prerequisites¶
1. WATI Account¶
WATI Setup:
- Active WATI subscription: https://www.wati.io
- WhatsApp Business number configured in WATI
- Access to WATI Dashboard
- Message templates approved by WhatsApp
2. API Credentials¶
Obtain from WATI Dashboard:
- Log into WATI Dashboard
- Navigate to Settings → API or Integrations → API
- Copy API Endpoint URL (format:
https://live-server-XXXXX.wati.io) - Copy Access Token (Bearer token)
- Note: Each WATI account has unique endpoint and token
API Endpoint Format:
Access Token Format:
3. WhatsApp Number¶
- WhatsApp Business number must be active in WATI
- Number cannot be used simultaneously on other platforms
- Verify number is connected and operational in WATI Dashboard
4. Message Templates (Optional)¶
For Template Messaging:
- Create templates in WATI Dashboard
- Submit for WhatsApp approval
- Wait for approval (usually 24-48 hours)
- Note template names for use in tasks
Configuration¶
Action 1: send_session_message¶
Send text message within 24-hour conversational window.
| Field | Required | Description | Example |
|---|---|---|---|
| wati_action | Yes | Must be "send_session_message" | send_session_message |
| API Endpoint | Yes | WATI server URL | https://live-server-12345.wati.io |
| Access Token | Yes | Bearer token | Bearer eyJhbGci... |
| whatsappNumber | Yes | Recipient number (no + symbol) | 27821234567 |
| messageText | Yes | Message content | Hello {{client_name}}, your order is ready! |
Output Variables:
task_23001_run // true/false
task_23001_run_text // "Successfully sent message."
task_23001_response // Full WATI API response
How It Works:
- Validates required fields (endpoint, token, number, text)
- Constructs URL:
POST {endpoint}/api/v1/sendSessionMessage/{number}?messageText={text} - Adds Authorization header with Bearer token
- Sends message via WATI API
- Returns success status and API response
24-Hour Window:
- Session messages only work within 24 hours of last customer message
- Outside window, use
send_template_messageinstead - WATI returns error if session expired
Action 2: send_template_message¶
Send pre-approved WhatsApp template message (works anytime).
| Field | Required | Description | Example |
|---|---|---|---|
| wati_action | Yes | Must be "send_template_message" | send_template_message |
| API Endpoint | Yes | WATI server URL | https://live-server-12345.wati.io |
| Access Token | Yes | Bearer token | Bearer eyJhbGci... |
| whatsappNumber | Yes | Recipient number | 27821234567 |
| template_name | Yes | Approved template name | welcome_new_customer |
| parameter_name_1 | No | First parameter name | customer_name |
| parameter_value_1 | No | First parameter value | {{client_first_name}} |
| parameter_name_2 | No | Second parameter name | order_number |
| parameter_value_2 | No | Second parameter value | {{order_id}} |
Add as many parameter pairs as needed
Output Variables:
task_23001_run // true/false
task_23001_run_text // "Successfully sent message."
task_23001_response // Full WATI API response with message ID
How It Works:
- Validates required fields
- Collects all
parameter_name_Xandparameter_value_Xpairs - Builds parameter array matching template placeholders
- Constructs URL:
POST {endpoint}/api/v1/sendTemplateMessage?whatsappNumber={number} - POST body:
- Returns success with message ID
Template Parameters:
Templates defined in WATI use placeholders like {{customer_name}}. Parameter names must match exactly.
Example template:
Requires 3 parameters: customer_name, order_number, delivery_date
Action 3: send_session_file¶
Send file/media within 24-hour conversational window.
| Field | Required | Description | Example |
|---|---|---|---|
| wati_action | Yes | Must be "send_session_file" | send_session_file |
| API Endpoint | Yes | WATI server URL | https://live-server-12345.wati.io |
| Access Token | Yes | Bearer token | Bearer eyJhbGci... |
| whatsappNumber | Yes | Recipient number | 27821234567 |
| file_url | Yes | Public URL to file | {{task_36001_document_url}} |
| caption | No | File caption/description | Your invoice for {{month}} |
Output Variables:
task_23001_run // true/false
task_23001_run_text // "Successfully sent file."
task_23001_response // Full WATI API response
How It Works:
- Validates required fields
- Downloads file from
file_url - Creates FormData with file and caption
- Uploads via:
POST {endpoint}/api/v1/sendSessionFile/{number} - WATI processes and sends to recipient
Supported File Types:
- Images: JPG, PNG, GIF (max 5MB)
- Videos: MP4, 3GP (max 16MB)
- Documents: PDF, DOC, DOCX, XLS, XLSX, PPT (max 100MB)
- Audio: MP3, OGG, AMR (max 16MB)
File URL Requirements:
- Must be publicly accessible (no authentication)
- HTTPS preferred
- Valid content type
- File size within WhatsApp limits
Action 4: update_contact¶
Update contact attributes in WATI system.
| Field | Required | Description | Example |
|---|---|---|---|
| wati_action | Yes | Must be "update_contact" | update_contact |
| API Endpoint | Yes | WATI server URL | https://live-server-12345.wati.io |
| Access Token | Yes | Bearer token | Bearer eyJhbGci... |
| whatsappNumber | Yes | Contact number | 27821234567 |
| parameter_name_1 | No | Attribute name | first_name |
| parameter_value_1 | No | Attribute value | {{client_first_name}} |
| parameter_name_2 | No | Second attribute | email |
| parameter_value_2 | No | Second value | {{client_email}} |
Add as many parameter pairs as needed
Output Variables:
task_23001_run // true/false
task_23001_run_text // "Successfully updated contact."
task_23001_response // Updated contact object
How It Works:
- Collects all
parameter_name_Xandparameter_value_Xpairs - Builds custom attributes array
- Sends to:
POST {endpoint}/api/v1/updateContactAttributes/{number} - POST body:
- Returns updated contact data
Common Attributes:
first_name,last_name- Contact namesemail- Email addresscompany- Company namecity,country- Location data- Custom attributes defined in WATI
Action 5: get_media¶
Retrieve media file from WATI and upload to Azure storage.
| Field | Required | Description | Example |
|---|---|---|---|
| wati_action | Yes | Must be "get_media" | get_media |
| API Endpoint | Yes | WATI server URL | https://live-server-12345.wati.io |
| Access Token | Yes | Bearer token | Bearer eyJhbGci... |
| file_url | Yes | WATI media URL with fileName param | https://live-server-12345.wati.io/media/123?fileName=image.jpg |
Output Variables:
task_23001_run // true/false
task_23001_run_text // "Successfully fetched media."
task_23001_response // Full file object
task_23001_response.id // File database ID
task_23001_response.owner_id // BaseCloud owner ID
task_23001_response.file_url // Azure Blob Storage URL
task_23001_response.file_name // Sanitized filename (basecloud_wa_*)
task_23001_response.size // File size in bytes
task_23001_response.contentType // MIME type
How It Works:
- Validates file URL has
fileNamequery parameter - Extracts filename from URL
- Downloads file from WATI:
GET {file_url}with Authorization header - Sanitizes filename:
basecloud_wa_{original_filename} - Uploads to Azure Blob Storage (owner-specific container)
- Creates database record in
filestable - Returns Azure URL and file metadata
Use Case:
When customer sends image/document via WhatsApp:
- Webhook trigger receives media URL from WATI
- Use
get_mediaaction to download and store - Azure URL can be used in other tasks (attach to email, save to client record, etc.)
Real-World Examples¶
Example 1: Automated Lead Follow-Up¶
Scenario: When lead submits form, send WhatsApp welcome message with company info.
Workflow:
-
Trigger: Website Form Submission
-
Task: New Client - Create Lead
-
Task: WATI - Send Template Message
wati_action: send_template_message API Endpoint: https://live-server-12345.wati.io Access Token: Bearer {{stored_wati_token}} whatsappNumber: {{task_55001_phone}} template_name: new_lead_welcome parameter_name_1: first_name parameter_value_1: {{task_55001_first_name}} parameter_name_2: company_name parameter_value_2: BaseCloud CRM -
Task: Edit Client - Tag
-
Task: Workflow Note
Result: Instant WhatsApp engagement with new leads using approved template.
Example 2: Invoice Delivery with PDF¶
Scenario: When invoice is created, send PDF via WhatsApp with payment link.
Workflow:
-
Trigger: CRM Event - Invoice Created
-
Task: Generate PDF Invoice
-
Task: If Condition - Has WhatsApp Number
-
Task (Inside If): WATI - Send Session File
-
Task (Inside If): Delay 5 seconds
-
Task (Inside If): WATI - Send Session Message
-
Task: Workflow Note
Result: Customers receive invoice PDF and payment link directly on WhatsApp for easy payment.
Example 3: Contact Data Synchronization¶
Scenario: Keep WATI contact attributes synchronized with CRM client data.
Workflow:
-
Trigger: CRM Event - Client Updated
-
Task: If Condition - Has WhatsApp
-
Task (Inside If): WATI - Update Contact
wati_action: update_contact API Endpoint: https://live-server-12345.wati.io Access Token: Bearer {{wati_token}} whatsappNumber: {{client_whatsapp_number}} parameter_name_1: first_name parameter_value_1: {{client_first_name}} parameter_name_2: last_name parameter_value_2: {{client_last_name}} parameter_name_3: email parameter_value_3: {{client_email}} parameter_name_4: company parameter_value_4: {{client_company_name}} parameter_name_5: city parameter_value_5: {{client_city}} parameter_name_6: status parameter_value_6: {{client_status}} -
Task: Workflow Note
Result: WATI always has latest client data for personalized messaging and segmentation.
Example 4: Marketing Campaign with Templates¶
Scenario: Send promotional message to all active clients using approved template.
Workflow:
-
Trigger: Manual Button - Launch Campaign
-
Task: MySQL Query - Get Active Clients
-
Task: Loop - Process Each Client
-
Task (Inside Loop): WATI - Send Template Message
wati_action: send_template_message API Endpoint: https://live-server-12345.wati.io Access Token: Bearer {{wati_token}} whatsappNumber: {{loop_item_whatsapp_number}} template_name: special_offer_announcement parameter_name_1: customer_name parameter_value_1: {{loop_item_first_name}} parameter_name_2: loyalty_points parameter_value_2: {{loop_item_loyalty_points}} parameter_name_3: offer_code parameter_value_3: SAVE20 -
Task (Inside Loop): Delay 2 seconds
-
Task (Inside Loop): MySQL - Log Campaign
-
Task: Email - Campaign Summary
Result: Bulk WhatsApp marketing with personalized messages and compliance tracking.
Example 5: Customer Support with Media¶
Scenario: Customer sends image via WhatsApp, automatically create support ticket with image.
Workflow:
- Trigger: WATI Webhook - Message Received
-
Condition: Message has media
-
Task: Match to Client
-
Task: WATI - Get Media
-
Task: MySQL - Create Support Ticket
-
Task: WATI - Send Session Message
-
Task: Email - Alert Support Team
Result: Seamless support ticket creation from WhatsApp messages with media attachment.
Troubleshooting¶
Error: "No API endpoint provided"¶
Cause: API Endpoint field is empty
Solutions:
- Obtain endpoint from WATI Dashboard → Settings → API
- Format:
https://live-server-XXXXX.wati.io(no trailing slash) - Verify URL is accessible (test in browser)
Error: "No Access Token provided"¶
Cause: Access Token field is empty
Solutions:
- Copy full token from WATI Dashboard
- Include "Bearer " prefix:
Bearer eyJhbGci... - Store in Variable task for reuse
- Check token hasn't expired (regenerate if needed)
Error: "No whatsappNumber provided"¶
Cause: Recipient number field is empty
Solutions:
- Provide number with country code, no + symbol:
27821234567 - Verify number exists in client record
- Check variable reference:
{{client_whatsapp_number}} - Validate number format (digits only)
Session Message Failed (Outside 24-Hour Window)¶
Cause: Attempting session message without active conversation
Solutions:
- Use
send_template_messageinstead (works anytime) - Check last customer message timestamp in WATI
- Customer must message first to open 24-hour window
- Use template for initial outreach
Template Not Found¶
Cause: Template name doesn't exist or not approved
Solutions:
- Verify template exists in WATI Dashboard → Templates
- Check template status is "Approved" (not Pending/Rejected)
- Match exact template name (case-sensitive)
- Wait for WhatsApp approval if recently submitted
Template Parameters Mismatch¶
Cause: Parameter names don't match template placeholders
Solutions:
- Check template definition in WATI Dashboard
- Match parameter names exactly:
{{customer_name}}requiresparameter_name_1: customer_name - Provide all required parameters
- Order doesn't matter, names must match
File Upload Failed¶
Cause: File URL inaccessible or invalid format
Solutions:
- Verify URL is publicly accessible (no authentication)
- Use HTTPS URLs when possible
- Check file size within limits (images 5MB, documents 100MB)
- Ensure valid file extension
- Test URL in browser first
Media Retrieval Error: "Invalid filepath within URL"¶
Cause: get_media file_url missing fileName query parameter
Solutions:
- WATI media URLs include
fileName:https://...?fileName=image.jpg - Don't construct URLs manually - use from webhook
- Verify
{{task_46001_media_url}}contains full URL with params
Contact Update Not Reflecting¶
Cause: Attribute names don't match WATI custom fields
Solutions:
- Check custom attribute names in WATI Dashboard → Settings → Custom Attributes
- Use exact spelling and casing
- Create custom attributes in WATI first
- Standard fields:
first_name,last_name,email,company
Rate Limiting / 429 Errors¶
Cause: Sending messages too quickly
Solutions:
- Add Delay tasks between messages in loops (2-5 seconds)
- WATI has rate limits (varies by plan)
- Implement exponential backoff for retries
- Contact WATI support to increase limits
Best Practices¶
Authentication Security¶
- Store Credentials Securely:
- Use Variable task to store API Endpoint and Access Token
- Reference variables:
{{wati_api_endpoint}},{{wati_access_token}} -
Never hardcode in automation tasks
-
Token Management:
- Rotate tokens periodically
- Use separate tokens for dev/staging/production
- Monitor token usage in WATI Dashboard
Template Design¶
- Plan Templates:
- Design templates for common scenarios (welcome, invoice, reminder)
- Keep templates short and actionable
-
Include clear call-to-action
-
Parameter Naming:
- Use descriptive parameter names:
customer_name, notparam1 - Document parameter mappings in workflow notes
-
Validate parameter values before sending
-
Approval Process:
- Submit templates for approval before building workflows
- Test with approved templates first
- Keep rejected template reasons for future submissions
Message Strategy¶
- Session vs Template:
- Use session messages for ongoing conversations (cheaper)
- Use templates for initial outreach and marketing
-
Track conversation status to choose appropriately
-
Timing:
- Respect customer time zones
- Avoid late night/early morning sends
-
Use Timer triggers for scheduled campaigns
-
Opt-In Compliance:
- Maintain opt-in status in CRM (
whatsapp_opt_infield) - Provide unsubscribe mechanism
- Respect opt-out immediately
File Handling¶
- File URLs:
- Generate PDFs with public URLs (PDF task Type 36)
- Use Azure/S3 signed URLs for temporary access
-
Verify URLs accessible before sending
-
File Sizes:
- Compress images before sending (max 5MB)
- Split large documents if needed
-
Provide fallback (email) for large files
-
Media Storage:
- Use
get_mediato archive customer-sent files - Store Azure URLs in client records
- Set retention policies for media
Error Handling¶
- Validation:
- Check required fields before WATI task
- Use If Conditions to verify data exists
-
Provide fallback workflows for failures
-
Logging:
- Always add Workflow Notes for WATI actions
- Include message IDs, recipients, template names
-
Log failures for troubleshooting
-
Retries:
- Implement retry logic for transient failures
- Use exponential backoff (delay 5s, 15s, 30s)
- Alert admins after 3 failed attempts
Performance¶
- Rate Limiting:
- Add 2-second delays in bulk sending loops
- Monitor WATI usage dashboard
-
Schedule large campaigns during off-peak
-
Caching:
- Cache template list (reload periodically)
- Store contact attributes locally
- Minimize API calls where possible
FAQ¶
Q: Can I use WATI and WhatsApp Business simultaneously?
A: No, WhatsApp number can only be connected to one platform at a time. Choose WATI or Meta WhatsApp Business Cloud API.
Q: What's the difference between session and template messages?
A: - Session Messages: Free text, requires active conversation (24-hour window) - Template Messages: Pre-approved, can send anytime, costs per message
Q: How do I get templates approved?
A: Create template in WATI Dashboard → Submit for WhatsApp review → Wait 24-48 hours for approval.
Q: Can I send messages without templates outside 24-hour window?
A: No, WhatsApp requires approved templates for initial outreach and messaging outside conversation windows.
Q: What file types can I send?
A: Images (JPG, PNG, GIF), videos (MP4), documents (PDF, DOC, XLS, PPT), audio (MP3, OGG).
Q: How do I handle opt-outs?
A: Maintain whatsapp_opt_in field in CRM. Check before sending. Provide "Reply STOP to opt out" in templates.
Q: Can I schedule messages for later?
A: Use Timer Trigger to schedule automation runs at specific times/dates.
Q: What happens if recipient number is invalid?
A: WATI returns error in response. Check {{task_23001_response}} for error details.
Q: Can I send bulk messages?
A: Yes, use Loop task with delays. Ensure compliance with WhatsApp policies and opt-ins.
Q: How do I track message delivery?
A: WATI provides delivery status in webhook responses. Set up webhook trigger to capture delivery events.
Q: Can I receive messages from customers?
A: Yes, use WATI Webhook Trigger to handle incoming messages.
Q: What's the cost per message?
A: Varies by WATI plan. Session messages usually free, template messages charged per send.
Related Tasks¶
- WhatsApp Business - Alternative using Meta's official API
- Email - Fallback communication channel
- SMS - Alternative text messaging
- PDF - Generate documents to send
- Loop - Bulk message sending
- If Statement - Message routing logic
- Delay - Rate limiting in loops
- Webhook In - Receive WATI webhooks
Technical Details¶
- Type ID: 23
- Function:
taskWATI()in automationService.js (lines 5448-5744) - API Version: WATI API v1
- Authentication: Bearer Token
- Output Prefix:
task_23001_* - Rate Limits: Varies by WATI plan
- Session Window: 24 hours from last customer message