Skip to main content

Block or Unblock a Contact

Agent Skill

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.

info

Requires a WhatsApp Business API (WABA) channel connected to your 2Chat account. See How to connect WABA to 2Chat.

WhatsApp only lets you block recent contacts

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​

ParameterDescriptionExample
from_numberYour WABA number, in E.164 format. The leading + is optional — both +15550001111 and 15550001111 are accepted. Required.+15550001111
to_numberThe 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​

# 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'

Response​

Contact blocked:

{
"success": true,
"blocked": true
}

Contact unblocked:

{
"success": true,
"blocked": false
}
FieldDescription
successtrue when WhatsApp accepted the change
blockedThe 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."
}
Statuserror_codeWhen
400WABA_BLOCK_WINDOW_CLOSEDThe contact hasn't messaged this number in the last 24 hours, or the number isn't a WhatsApp user
400WABA_BLOCK_OWN_NUMBERto_number is your own WABA number
400WABA_BLOCKLIST_FULLThe number reached WhatsApp's limit of blocked contacts
400WABA_BLOCK_FAILEDWhatsApp 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.