Deleting messages

Since PubNub stores all messages in a time-series database, it doesn’t expose an API to directly update a message. However, clients can update messages (or soft delete them) by passing another version of the message using the Message Reactions feature.

Soft delete a message

Use the addMessageAction method to soft delete a message after it has been published by adding an action to it.

Soft deleting a message just attaches a delete flag to the message. Refer to hard delete if you want to permanently delete the message from Message Persistence for compliance reasons.

User ID / UUID

User ID is also referred to as UUID/uuid in some APIs and server responses but holds the value of the userId parameter you set during initialization.

channel: 'ch-1'
messageTimetoken: '15610547826970040',
action: {
type: 'deleted',
value: '.',
function(status, response) {

PubNub triggers events when messages are soft deleted using message actions. Users subscribed to the channel can receive these events and mark the message as deleted.

show all 17 lines

Hard delete a message

The deleteMessages method permanently deletes messages from Message Persistence in a given channel. You can delete a single message, or a range of messages.

The Delete Message API looks backwards in time. The start timetoken parameter should be more forward in time than the end parameter: end < start.

In the example below, the start and end timetoken parameter values are 1/10 nanosecond (last digit of timetoken) apart to delete the message stored at the end parameter's timetoken value.

Required setting in Admin Portal

You need to turn on the Enable Delete-From-History setting on your keyset in Admin Portal in order to hard delete messages.
We do not recommend heavy use of this API for performance reasons. Messages should be soft deleted when possible.

channel: 'chats.room1',
start: "15526611838554310",
end: "15526611838554309",
function (status, response) {
console.log(status, response);
Last updated on