Skip to contentSkip to navigationSkip to topbar
On this page

Create a batch ID



API Overview

api-overview page anchor

The Cancel Scheduled Sends API allows you to cancel or pause the send of one or more emails using a batch ID.

A batch_id groups multiple scheduled mail/send requests together with the same ID. You can cancel or pause all of the mail/send requests associated with a batch ID up to 10 minutes before the scheduled send time by passing a batch_id to the "Cancel or pause a scheduled send" endpoint.

For a guide on creating a batch_id, assigning it to a scheduled send, and modifying the send, see "Canceling a Scheduled Send".

The Cancel Scheduled Sends API also make it possible to validate a batch_id and retrieve all scheduled sends as an array.

When a batch is canceled, all messages associated with that batch will stay in your sending queue. When their send_at value is reached, they will be discarded.

When a batch is paused, all messages associated with that batch will stay in your sending queue, even after their send_at value has passed. This means you can remove a pause status, and your scheduled send will be delivered once the pause is removed. Any messages left with a pause status that are more than 72 hours old will be discarded as Expired.


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.


Authentication

authentication page anchor
Property nameTypeRequiredDescription
Authorizationstringrequired
Default: Bearer <<YOUR_API_KEY_HERE>>

on-behalf-ofstringOptional

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.

Create a batch IDLink to code sample: Create a 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
});

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.