Publishing is great for sending one message at a time, but sometimes you want to send a batch of messages at once.

This can be useful to send messages to a single or multiple destinations. QStash provides the batch endpoint to help you with this.

If the format of the messages are valid, the response will be an array of responses for each message in the batch. When batching topics, the response will be an array of responses for each destination in the topic. If one message fails to be sent, that message will have an error response, but the other messages will still be sent.

Batching messages with destinations

You can also send messages to the same destination!

Batching messages with topics

If you have a topic, you can batch send with the topic as well.

Batching messages with headers and body

You can provide custom headers and a body for each message in the batch.

The response for this will look like

[

  [

    {

      "messageId": "msg_...",

      "url": "https://mytopic-endpoint1.com"

    },

    {

      "messageId": "msg_...",

      "url": "https://mytopic-endpoint2.com"

    }

  ],

  {

    "messageId": "msg_..."

  },

  {

    "messageId": "msg_..."

  }

]