Table of Contents

Assign a List to a Marketing Email

Legacy Newsletter

Request

1
curl -X POST https://api.sendgrid.com/api/newsletter/recipients/add.json -F api_user=SENDGRID_USERNAME -F api_key=SENDGRID_PASSWORD -F 'name=SendGrid_Test' -F 'list=Test List'

Response

1
2
3
{
  "message": "success"
}

Marketing Campaigns

First, we need to get the list_id:

Request

1
2
3
4
5
curl --request GET \
--url https://api.sendgrid.com/v3/contactdb/lists \
--header 'accept: application/json' \
--header 'authorization: Bearer SENDGRID_API_KEY' \
--header 'content-type: application/json'

Response

1
2
3
4
5
6
7
8
9
{
  "lists": [
    {
      "id": 1,
      "name": "the jones",
      "recipient_count": 1
    }
  ]
}

Add lists to a new campaign:

Request

1
2
3
4
5
6
curl --request POST \
--url https://api.sendgrid.com/v3/campaigns \
--header 'accept: application/json' \
--header 'authorization: Bearer SENDGRID_API_KEY' \
--header 'content-type: application/json' \
--data '{"sender_id": 124451, "title":"SendGrid_Test", "subject":"Test Subject", "plain_content": "Text Content", "html_content": "<html><body>HTML content</body></html>", "list_ids":[1,2]}'

Response

1
2
3
4
5
6
7
8
9
10
11
12
13
{
  "id": 986724,
  "title": "SendGrid_Test",
  "subject": "Test Subject",
  "sender_id": 124451,
  "list_ids": [
    1,
    2
  ],
  "html_content": "<html><body>HTML content</body></html>",
  "plain_content": "Text Content",
  "status": "Draft"
}

If you have a campaign id, you can update a campaign with that list (Note that this will overwrite the current list_ids):

Request

1
2
3
4
5
6
curl --request PATCH \
--url https://api.sendgrid.com/v3/campaigns/{campaign_id} \
--header 'accept: application/json' \
--header 'authorization: Bearer SENDGRID_API_KEY' \
--header 'content-type: application/json' \
--data '{"title":"SendGrid_Test_2", "subject":"Test Subject", "plain_content": "Text Content", "html_content": "<html><body>HTML content</body></html>", "list_ids":[1,2]}'

Response

1
2
3
4
5
6
7
8
9
10
11
12
13
{
  "id": 986724,
  "title": "SendGrid_Test_2",
  "subject": "Test Subject",
  "sender_id": 124451,
  "list_ids": [
    1,
    2
  ],
  "html_content": "<html><body>HTML content</body></html>",
  "plain_content": "Text Content",
  "status": "Draft"
}

Get all lists assigned to a particular Marketing Email

Legacy Newsletter

Request

1
curl -X POST https://api.sendgrid.com/api/newsletter/recipients/get.json -F api_user=SENDGRID_USERNAME -F api_key=SENDGRID_PASSWORD -F 'name=SendGrid_Test'

Response

1
2
3
4
5
[
  {
    "list": "Training Contacts"
  }
]

Marketing Campaigns

Get all of your campaigns and view the lists on each:

Request

1
2
3
4
5
curl --request GET \
--url https://api.sendgrid.com/v3/campaigns \
--header 'accept: application/json' \
--header 'authorization: Bearer SENDGRID_API_KEY' \
--header 'content-type: application/json'

Response

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{
  "result": [
    {
      "id": 986724,
      "title": "March Newsletter",
      "subject": "New Products for Spring!",
      "sender_id": 124451,
      "list_ids": [
        110,
        124
      ],
      "segment_ids": [
        110
      ],
      "categories": [
        "spring line"
      ],
      "suppression_group_id": 42,
      "custom_unsubscribe_url": "",
      "ip_pool": "marketing",
      "html_content": "<html><head><title></title></head><body><p>Check out our spring line!</p></body></html>",
      "plain_content": "Check out our spring line!",
      "status": "Draft"
    },
    {
      "id": 986723,
      "title": "February Newsletter",
      "subject": "Final Winter Product Sale!",
      "sender_id": 124451,
      "list_ids": [
        110,
        124
      ],
      "segment_ids": [
        110
      ],
      "categories": [
        "winter line"
      ],
      "suppression_group_id": 42,
      "custom_unsubscribe_url": "",
      "ip_pool": "marketing",
      "html_content": "<html><head><title></title></head><body><p>Last call for winter clothes!</p></body></html>",
      "plain_content": "Last call for winter clothes!",
      "status": "Sent"
    }
  ]
}

You can also get a single campaign to view the lists:

Request

1
2
3
4
5
curl --request GET \
--url https://api.sendgrid.com/v3/campaigns/{campaign_id} \
--header 'accept: application/json' \
--header 'authorization: Bearer SENDGRID_API_KEY' \
--header 'content-type: application/json'

Response

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
  "id": 986724,
  "title": "March Newsletter",
  "subject": "New Products for Spring!",
  "sender_id": 124451,
  "list_ids": [
    110,
    124
  ],
  "segment_ids": [
    110
  ],
  "categories": [
    "spring line"
  ],
  "suppression_group_id": 42,
  "custom_unsubscribe_url": "",
  "ip_pool": "marketing",
  "html_content": "<html><head><title></title></head><body><p>Check out our spring line!</p></body></html>",
  "plain_content": "Check out our spring line!",
  "status": "Draft"
}

Remove assigned lists from a Marketing Email

Legacy Newsletter

Request

1
curl -X POST https://api.sendgrid.com/api/newsletter/recipients/delete.json -F api_user=SENDGRID_USERNAME -F api_key=SENDGRID_PASSWORD -F 'name=SendGrid_Test' -F 'list=Test'

Response

1
2
3
{
  "message": "success"
}

Marketing Campaigns

Get the ID of the campaign to Edit:

Request

1
2
3
4
5
curl --request GET \
--url https://api.sendgrid.com/v3/campaigns \
--header 'accept: application/json' \
--header 'authorization: Bearer SENDGRID_API_KEY' \
--header 'content-type: application/json'

Response

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{
  "result": [
    {
      "id": 986724,
      "title": "March Newsletter",
      "subject": "New Products for Spring!",
      "sender_id": 124451,
      "list_ids": [
        110,
        124
      ],
      "segment_ids": [
        110
      ],
      "categories": [
        "spring line"
      ],
      "suppression_group_id": 42,
      "custom_unsubscribe_url": "",
      "ip_pool": "marketing",
      "html_content": "<html><head><title></title></head><body><p>Check out our spring line!</p></body></html>",
      "plain_content": "Check out our spring line!",
      "status": "Draft"
    },
    {
      "id": 986723,
      "title": "February Newsletter",
      "subject": "Final Winter Product Sale!",
      "sender_id": 124451,
      "list_ids": [
        110,
        124
      ],
      "segment_ids": [
        110
      ],
      "categories": [
        "winter line"
      ],
      "suppression_group_id": 42,
      "custom_unsubscribe_url": "",
      "ip_pool": "marketing",
      "html_content": "<html><head><title></title></head><body><p>Last call for winter clothes!</p></body></html>",
      "plain_content": "Last call for winter clothes!",
      "status": "Sent"
    }
  ]
}

Then we can edit the campaign:

Request

1
2
3
4
5
6
curl --request PATCH \
--url https://api.sendgrid.com/v3/campaigns/{campaign_id} \
--header 'accept: application/json' \
--header 'authorization: Bearer SENDGRID_API_KEY' \
--header 'content-type: application/json' \
--data '{"title":"SendGrid_Test_2", "subject":"Test Subject", "plain_content": "Text Content", "html_content": "<html><body>HTML content</body></html>", "list_ids":[]}'

Response

1
2
3
4
5
6
7
8
9
10
11
12
13
{
  "id": 986724,
  "title": "SendGrid_Test_2",
  "subject": "Test Subject",
  "sender_id": 124451,
  "list_ids": [
    110,
    124
  ],
  "html_content": "<html><body>HTML content</body></html>",
  "plain_content": "Text Content",
  "status": "Draft"
}