Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Create a Campaign



API Overview

api-overview page anchor
(warning)

Legacy Marketing Campaigns

You are viewing the Legacy Marketing Campaigns API reference. For guidance migrating to the current version of Marketing Campaigns, see Migrating from Legacy Marketing Campaigns

(information)

Info

For the most up-to-date information on the Sender Identities API, please visit the new Marketing Campaigns Single Sends API.

The Campaigns API allows you to create and manage marketing campaigns. You can create campaigns, manage campaign content, and schedule campaigns to be sent at a later time.


POST/v3/campaigns

Base url: https://api.sendgrid.com

This endpoint allows you to create a campaign.

In order to send or schedule the campaign, you will be required to provide a subject, sender ID, content (we suggest both html and plain text), and at least one list or segment ID. This information is not required when you create a campaign.


Authentication

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

on-behalf-ofstringOptional

The on-behalf-of header allows you to make API calls from a parent account on behalf of the parent's Subusers or customer accounts. You will use the parent account's API key when using this header. When making a call on behalf of a customer account, the property value should be "account-id" followed by the customer account's ID (e.g., on-behalf-of: account-id <account-id>). When making a call on behalf of a Subuser, the property value should be the Subuser's username (e.g., on-behalf-of: <subuser-username>). See On Behalf Of for more information.

SchemaExample
Property nameTypeRequiredDescriptionChild properties
titlestringrequired

The display title of your campaign. This will be viewable by you in the Marketing Campaigns UI.


subjectstring or nullOptional

The subject of your campaign that your recipients will see.


sender_idinteger or nullOptional

The ID of the "sender" identity that you have created. Your recipients will see this as the "from" on your marketing emails.


list_idsarray[integer] or nullOptional

The IDs of the lists you are sending this campaign to. You can have both segment IDs and list IDs


segment_idsarray[integer] or nullOptional

The segment IDs that you are sending this list to. You can have both segment IDs and list IDs. Segments are limited to 10 segment IDs.


categoriesarray[string] or nullOptional

The categories you would like associated to this campaign.


suppression_group_idinteger or nullOptional

The suppression group that this marketing email belongs to, allowing recipients to opt-out of emails of this type.


custom_unsubscribe_urlstring or nullOptional

This is the url of the custom unsubscribe page that you provide for customers to unsubscribe from your suppression groups.


ip_poolstring or nullOptional

The pool of IPs that you would like to send this email from.


html_contentstring or nullOptional

The HTML of your marketing email.


plain_contentstring or nullOptional

The plain text content of your emails.


editorenum<string>Optional

The editor used in the UI.

Possible values:
codedesign
201400401
SchemaExample
Property nameTypeRequiredDescriptionChild properties
titlestring

The display title of your campaign. This will be viewable by you in the Marketing Campaigns UI.


subjectstring or null

The subject of your campaign that your recipients will see.


sender_idinteger or null

The ID of the "sender" identity that you have created. Your recipients will see this as the "from" on your marketing emails.


list_idsarray[integer] or null

The IDs of the lists you are sending this campaign to. You can have both segment IDs and list IDs


segment_idsarray[integer] or null

The segment IDs that you are sending this list to. You can have both segment IDs and list IDs. Segments are limited to 10 segment IDs.


categoriesarray[string] or null

The categories you would like associated to this campaign.


suppression_group_idinteger or null

The suppression group that this marketing email belongs to, allowing recipients to opt-out of emails of this type.


custom_unsubscribe_urlstring or null

This is the url of the custom unsubscribe page that you provide for customers to unsubscribe from your suppression groups.


ip_poolstring or null

The pool of IPs that you would like to send this email from.


html_contentstring or null

The HTML of your marketing email.


plain_contentstring or null

The plain text content of your emails.


editorenum<string>

The editor used in the UI.

Possible values:
codedesign

statusstring

The status of your campaign.


idinteger

Create a Campaign

create-a-campaign page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
curl

_40
const client = require('@sendgrid/client');
_40
client.setApiKey(process.env.SENDGRID_API_KEY);
_40
_40
const data = {
_40
"id": 986724,
_40
"title": "May Newsletter",
_40
"subject": "New Products for Summer!",
_40
"sender_id": 124451,
_40
"list_ids": [
_40
110,
_40
124
_40
],
_40
"segment_ids": [
_40
110
_40
],
_40
"categories": [
_40
"summer line"
_40
],
_40
"suppression_group_id": 42,
_40
"custom_unsubscribe_url": "",
_40
"ip_pool": "marketing",
_40
"html_content": "<html><head><title></title></head><body><p>Check out our summer line!</p></body></html>",
_40
"plain_content": "Check out our summer line!",
_40
"status": "Draft"
_40
};
_40
_40
const request = {
_40
url: `/v3/campaigns`,
_40
method: 'POST',
_40
body: data
_40
}
_40
_40
client.request(request)
_40
.then(([response, body]) => {
_40
console.log(response.statusCode);
_40
console.log(response.body);
_40
})
_40
.catch(error => {
_40
console.error(error);
_40
});


Rate this page: