Block or Unblock a Contact
Automate this endpoint with an AI agent using the 2chat-whatsapp-waba skill:
npx skills add 2ChatCo/agent-skills -s 2chat-whatsapp-waba
Block a contact on one of your WABA numbers, or unblock them.
A blocked contact can't message that number, and messages you send to them fail. WhatsApp doesn't tell them they were blocked. The block applies to one WABA number: the same contact can still write to your other numbers.
Only API keys created by an admin can block or unblock contacts, like in the live chat. A key created by an operator gets a 403.
Requires a WhatsApp Business API (WABA) channel connected to your 2Chat account. See How to connect WABA to 2Chat.
You can only block a contact who messaged your number in the last 24 hours. Check it first with Conversation Window: if last_inbound_message_at is older than 24 hours, the block is refused with WABA_BLOCK_WINDOW_CLOSED. Unblocking has no time limit.
Endpoints
POST https://api.p.2chat.io/open/waba/block/{from_number}/{to_number}
DELETE https://api.p.2chat.io/open/waba/block/{from_number}/{to_number}
POST blocks the contact and DELETE unblocks them. Both are idempotent: blocking a contact that is already blocked succeeds.
Authentication
Send your API key in the X-User-API-Key header. See Authentication.
Path parameters
| Parameter | Description | Example |
|---|---|---|
from_number | Your WABA number, in E.164 format. The leading + is optional — both +15550001111 and 15550001111 are accepted. Required. | +15550001111 |
to_number | The contact's phone number, in E.164 format (the leading + is optional). For a contact who hides their phone number, use their WhatsApp user ID instead, as it appears in their messages (e.g. US.13491208655302741918). Required. | +15552223333 |
Invocation
- cURL
- Python
- JavaScript
- PHP
# Block
curl --request POST \
--url 'https://api.p.2chat.io/open/waba/block/+15550001111/+15552223333' \
--header 'X-User-API-Key: your_api_key_here'
# Unblock
curl --request DELETE \
--url 'https://api.p.2chat.io/open/waba/block/+15550001111/+15552223333' \
--header 'X-User-API-Key: your_api_key_here'
import requests
from_number = "+15550001111"
to_number = "+15552223333"
url = f"https://api.p.2chat.io/open/waba/block/{from_number}/{to_number}"
headers = {
"X-User-API-Key": "your_api_key_here"
}
# Block
response = requests.post(url, headers=headers)
print(response.json())
# Unblock
response = requests.delete(url, headers=headers)
print(response.json())
const axios = require('axios');
const fromNumber = '+15550001111';
const toNumber = '+15552223333';
const url = `https://api.p.2chat.io/open/waba/block/${fromNumber}/${toNumber}`;
const headers = { 'X-User-API-Key': 'your_api_key_here' };
// Block
axios.post(url, null, { headers })
.then(response => console.log(response.data))
.catch(error => console.error(error.response?.data));
// Unblock
axios.delete(url, { headers })
.then(response => console.log(response.data))
.catch(error => console.error(error.response?.data));
<?php
$fromNumber = '+15550001111';
$toNumber = '+15552223333';
$ch = curl_init("https://api.p.2chat.io/open/waba/block/{$fromNumber}/{$toNumber}");
// Use 'DELETE' to unblock
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-User-API-Key: your_api_key_here'
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
Response
Contact blocked:
{
"success": true,
"blocked": true
}
Contact unblocked:
{
"success": true,
"blocked": false
}
| Field | Description |
|---|---|
success | true when WhatsApp accepted the change |
blocked | The contact's state on this number after the call |
Blocked contacts are also marked in the 2Chat live chat, where an agent can unblock them from the conversation.
Error responses
Errors return a 4xx status and a JSON body in the shape:
{
"error": true,
"error_code": "WABA_BLOCK_WINDOW_CLOSED",
"error_message": "Only contacts who messaged this number in the last 24 hours can be blocked."
}
| Status | error_code | When |
|---|---|---|
400 | WABA_BLOCK_WINDOW_CLOSED | The contact hasn't messaged this number in the last 24 hours, or the number isn't a WhatsApp user |
400 | WABA_BLOCK_OWN_NUMBER | to_number is your own WABA number |
400 | WABA_BLOCKLIST_FULL | The number reached WhatsApp's limit of blocked contacts |
400 | WABA_BLOCK_FAILED | WhatsApp refused the change for another reason. Retry later |
400 | — | from_number or to_number is not a valid E.164 number, or WhatsApp returned another error (error_message starts with Meta:) |
403 | — | Your API key was created by an operator, or it's limited to some channels and from_number is not one of them |
404 | — | from_number is not a WABA number on your account |
429 | — | Too many block or unblock requests. Wait a few minutes and retry |
Sending to a blocked contact
Messages sent to a blocked contact with Send WABA Message fail with WhatsApp error 130403. Unblock the contact first.