Skip to main content
Messages are removed from the database shortly after they’re delivered, so you will not be able to retrieve a message after. This endpoint is intended to be used for accessing messages that are in the process of being delivered/retried.

Retrieve a message

import { Client } from "@upstash/qstash";

const client = new Client({ token: "<QSTASH_TOKEN>" });
const messages = client.messages
const msg = await messages.get("msgId");

Cancel/delete a message

import { Client } from "@upstash/qstash";

const client = new Client({ token: "<QSTASH_TOKEN>" });

await client.messages.delete("msgId");

Cancel messages in bulk

Cancel many messages at once or cancel all messages
import { Client } from "@upstash/qstash";

const client = new Client({ token: "<QSTASH_TOKEN>" });

// cancel two messages at once
const result = await client.messages.delete([
  "message-id-1",
  "message-id-2",
]);

console.log(result.cancelled); // 2

// cancel all messages
const result2 = await client.messages.delete({});
console.log(result2.cancelled); // number of cancelled messages

Cancel messages with filters

Cancel all messages matching specific filters such as flowControlKey, url, queueName, and more.
import { Client } from "@upstash/qstash";

const client = new Client({ token: "<QSTASH_TOKEN>" });

// cancel all messages with a specific flow control key
const result = await client.messages.delete({
  flowControlKey: "my-flow-key",
});

console.log(result.cancelled); // number of cancelled messages

// cancel with multiple filters
const result2 = await client.messages.delete({
  flowControlKey: "my-flow-key",
  url: "https://example.com",
  queueName: "my-queue",
  label: "my-label",
  fromDate: "1640995200000",
  toDate: "1672531200000",
});

console.log(result2.cancelled); // number of cancelled messages