Create a batch ID



Using the Cancel Scheduled Sends API, you can cancel or pause sending one or more groups of emails. SendGrid defines these multiple scheduled send requests together as batches identified with a batch_id.

With this API, you can perform the following tasks on scheduled emails:

  • Define and validate the ID for a batch of messages.
  • Retrieve, update, pause, resume, or cancel a scheduled send.

Cancelling or pausing a batch of messages include the following conditions:

  • You can't pause or cancel more than 10 different batches at one time.
  • You can't pause or cancel a batch later than 10 minutes before the scheduled send_at time.
  • When you cancel or pause a batch, all messages associated with that batch stay in your sending queue.
  • When a cancelled batch reaches its send_at time, SendGrid discards the messages.
  • When a paused batch reaches its send_at time, SendGrid retains the messages. When you resume a paused batch, SendGrid delivers your scheduled send.
  • When a paused batch passes 72 hours after its send_at time, SendGrid discards the messages as Expired.

To cancel a scheduled send of a single message, consult Canceling a Scheduled Send.


POST/v3/mail/batch

Base url: https://api.sendgrid.com (for global users and subusers)

Base url: https://api.eu.sendgrid.com (for EU regional subusers)

This operation allows you to generate a new mail batch ID.

Once a batch ID is created, you can associate it with a mail send by passing it in the request body of the Mail Send operation. This makes it possible to group multiple requests to the Mail Send operation by assigning them the same batch ID.

A batch ID that's associated with a mail send can be used to access and modify the associated send. For example, you can pause or cancel a send using its batch ID. See the Scheduled Sends API for more information about pausing and cancelling a mail send.


Property nameTypeRequiredDescription
Authorizationstringrequired
Default: Bearer <<YOUR_API_KEY_HERE>>

on-behalf-ofstring

Optional

Use the on-behalf-of header to make API calls for a particular Subuser through the parent account. You can use this header to automate bulk updates or to administer a Subuser without changing the authentication in your code. You will use the parent account's API key when using this header.

201400401403404405500

Batch ID success response.

SchemaExample
Property nameTypeRequiredDescriptionChild properties
batch_idstring

A mail batch ID.

1
const client = require("@sendgrid/client");
2
client.setApiKey(process.env.SENDGRID_API_KEY);
3
4
const request = {
5
url: `/v3/mail/batch`,
6
method: "POST",
7
};
8
9
client
10
.request(request)
11
.then(([response, body]) => {
12
console.log(response.statusCode);
13
console.log(response.body);
14
})
15
.catch((error) => {
16
console.error(error);
17
});