Error 131047 WhatsApp API: Message Outside 24-Hour Window
How to fix WhatsApp Business API error 131047 when the conversation window expires after 24 hours
What is Error 131047?
Error 131047 is one of the most common errors in the WhatsApp Business API. It occurs when you try to send a free-form message to a user after 24 hours since their last message.
The error message usually looks like this:
{
"error": {
"message": "Re-engagement message",
"type": "OAuthException",
"code": 131047,
"fbtrace_id": "..."
}
}
Why Does This Happen?
Meta implemented a 24-hour conversation window policy to protect users from spam. Here's how it works:
- When the user sends a message, a 24-hour window opens
- During this window, you can send free-form messages (text, image, video, etc.)
- The window refreshes every time the user sends a new message
- After 24 hours without user response, the window closes and you can only use templates
How to Fix It
Solution 1: Use Message Templates
The only way to start a conversation or re-engage a user outside the 24-hour window is by using a Message Template approved by Meta.
// Example of sending a template with Node.js
const response = await fetch(
`https://graph.facebook.com/v18.0/${phoneNumberId}/messages`,
{
method: 'POST',
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
messaging_product: 'whatsapp',
to: recipientPhone,
type: 'template',
template: {
name: 'hello_world', // your approved template name
language: {
code: 'en_US'
}
}
})
}
);
Solution 2: Check Conversation Status
Before sending messages, verify if the window is still open:
// Store the timestamp of the user's last message
const lastUserMessage = await getLastUserMessageTime(userId);
const now = Date.now();
const hoursSinceLastMessage = (now - lastUserMessage) / (1000 * 60 * 60);
if (hoursSinceLastMessage > 24) {
// Use template
await sendTemplateMessage(userId);
} else {
// Can use free-form message
await sendFreeFormMessage(userId);
}
Solution 3: Implement a Fallback System
async function sendMessage(userId, message) {
try {
// Try to send free-form message
await sendFreeFormMessage(userId, message);
} catch (error) {
if (error.code === 131047) {
// Fallback to template
console.log('Window expired, using template...');
await sendTemplateMessage(userId);
} else {
throw error;
}
}
}
Conversation Types and Costs
As of 2025, Meta categorizes conversations into:
| Type | Description | Cost | |------|-------------|------| | Service | User-initiated | Cheapest | | Utility | Transactional templates | Medium | | Marketing | Promotional templates | Most expensive | | Authentication | Verification codes | Medium |
Best Practices
- Respond quickly: Try to respond within the 24h window
- Create useful templates: Have approved templates for re-engagement
- Monitor windows: Implement tracking for when each conversation expires
- Be relevant: Only re-engage users who really need the information
Conclusion
Error 131047 is not a bug, it's a user protection feature. The solution is to understand the WhatsApp API window system and use approved Message Templates when needed.
If you need help implementing WhatsApp Business API integrations, contact me for specialized consulting.