WhatsApp chats: read, send and take screenshots by API
Read the chats of each linked WhatsApp number, open one with its whole history and files, send a text or a file, and take a screenshot of the conversation as WhatsApp Web shows it. The same is in the console: Devices, a WhatsApp number, Chats.
- Only one-to-one chats: groups, broadcasts, the status feed and channels are left out.
- A chat's key is its number's digits without +. When WhatsApp hides a person's number, the chat can be read but not written to (kind: hidden_number).
- Files and screenshots come back in the JSON answer, base64. A file you download is at most 32 MB; a file you send, 16 MB.
- Only your own numbers, with your own API key; the number must be linked and online.
A screenshot opens the chat in WhatsApp Web on the number, and that marks it as read, as opening it on the phone would.
Your numbers and their chats
List your WhatsApp numbers, then a number's chats, newest first: the number always, the name saved on the phone when there is one, the person's own WhatsApp name, unread messages and the last message.
GET /v1/echo/whatsapp/devicesGET /v1/echo/whatsapp/devices/{id}/chats?limit=200A chat's messages
The newest messages, up to limit (5000 at most), oldest first: who sent each (sender: me or peer), its type, its text or caption, the time, the ticks of your own messages, and for a file its type, name, size and a small preview. complete: true means the whole chat as WhatsApp has it.
GET /v1/echo/whatsapp/devices/{id}/chats/{id}/messages?limit=100A message's file
Ask for a file by its message's id. WhatsApp may no longer have old files (410 media_unavailable).
GET /v1/echo/whatsapp/devices/{id}/chats/{id}/mediaA chat's profile picture
The person's WhatsApp profile picture as WhatsApp shows it to this number: JPEG, PNG or WebP, base64, 300 kB at most. picture is null when there is none or the person hides it from this number. Kept for 6 hours. 240 a minute.
GET /v1/echo/whatsapp/devices/{id}/chats/{id}/pictureSend a text or a file
From this number to this chat, the usual way: the message is queued, uses your WhatsApp units and keeps the daily limits; send an Idempotency-Key. A file goes with its type and name, base64; the text becomes its caption. To write to a new number, use this path with that number's digits, or POST /v1/echo/messages as always.
A file goes through WhatsApp Web's own attach button, as a person sends it: the chat is opened on the number's WhatsApp Web (WhatsApp marks it as read), the file and its caption are sent, and its ticks follow as usual. If WhatsApp Web does not show it as sent, the message fails with send_unconfirmed and is not sent again on its own.
POST /v1/echo/whatsapp/devices/{id}/chats/{id}/messagesA screenshot of the conversation
mode chat: the conversation pane at its newest messages; mode screen: the whole WhatsApp Web window, 1600 x 1000. A PNG, base64. Six a minute.
message_id (optional, an id from the messages list): the picture shows that message. When it is one of the conversation's last 4 messages the pane stays at its newest messages, as without it (at_message: bottom); an older message is loaded and placed in the middle of the pane (at_message: scrolled). A message WhatsApp Web cannot show answers 404 message_not_found.
POST /v1/echo/whatsapp/devices/{id}/chats/{id}/screenshotOpen a chat in WhatsApp
Opens the chat on the number's WhatsApp Web, as opening it on the phone does: WhatsApp loads the whole conversation, and marks it as read (the person sees blue ticks). Reading the messages through this API marks nothing as read; this does. 12 a minute.
POST /v1/echo/whatsapp/devices/{id}/chats/{id}/openToday's room in a chat
How many more messages this number can send to this person today. Each reply from the person that day adds 2 to the limit for that chat: with 5 a day, one sent leaves 4, and a reply then leaves 6.
GET /v1/echo/whatsapp/devices/{id}/chats/{id}/room