[WEBJS] - Deletes a message from the chat
It deletes the message on the first request, but gives an error on the second request.
DELETE /api/{session}/chats/{chatId}/messages/{messageId}
{
"statusCode": 500,
"timestamp": "2026-02-09T01:24:10.131Z",
"exception": {
"message": "Cannot read properties of undefined (reading 'id')",
"name": "TypeError",
"stack": "TypeError: Cannot read properties of undefined (reading 'id')\n at evaluate (evaluate at WPage.evaluate (/var/www/vhosts/{domain}/app/dist/core/engines/webjs/WPage.js:13:36), <anonymous>:2:51)\n at #evaluate (/var/www/vhosts/{domain}/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:391:56)\n at async ExecutionContext.evaluate (/var/www/vhosts/{domain}/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:277:16)\n at async IsolatedWorld.evaluate (/var/www/vhosts/{domain}/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/IsolatedWorld.js:100:16)\n at async CdpFrame.evaluate (/var/www/vhosts/{domain}/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Frame.js:362:20)\n at async CdpPage.evaluate (/var/www/vhosts/{domain}/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Page.js:818:20)\n at async WPage.evaluate (/var/www/vhosts/{domain}/app/dist/core/engines/webjs/WPage.js:13:20)\n at async Message.delete (/var/www/vhosts/{domain}/app/node_modules/whatsapp-web.js/src/structures/Message.js:512:9)\n at async descriptor.value (/var/www/vhosts/{domain}/app/dist/core/abc/activity.js:9:20)"
},
"request": {
"path": "/api/{session}chats/{chatId}/messages/{messageId}",
"method": "DELETE",
"query": {}
},
"version": {
"version": "2025.2.1",
"engine": "WEBJS",
"tier": "PLUS",
"browser": "/usr/bin/google-chrome-stable"
}
}
Version
{
"version": "2025.2.1",
"engine": "WEBJS",
"tier": "PLUS",
"browser": "/usr/bin/google-chrome-stable"
}
@devlikepro please read my brother
WhatsApp changes the message id when a message is deleted. When a message is deleted, it needs to return the deleted message id; this point is very important.
The deleted message id remains under _data.protocolMessageKey._serialized when retrieving messages.
/api/{session}/chats/{chatId}/messages
We need to re-fetch messages each time to get a new message id, which significantly slows us down.
Hi! Could you explain a bit your case?
gives an error on the second request.
Do you run DELETE 2 times for the same message id?
Yes, it gives an error when I run DELETE twice. What I want is for it to return the deleted message id when the message is deleted.
It only returns the headers.
If you really want to have healthy methods, I can contact you so we can solve the errors.