forked from starenka/mailjetv3
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathsegments_sample.py
More file actions
41 lines (33 loc) · 1.16 KB
/
segments_sample.py
File metadata and controls
41 lines (33 loc) · 1.16 KB
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
import json
import os
from mailjet_rest import Client
mailjet30 = Client(
auth=(os.environ.get("MJ_APIKEY_PUBLIC", ""), os.environ.get("MJ_APIKEY_PRIVATE", "")),
)
def create_your_segment():
"""POST https://api.mailjet.com/v3/REST/contactfilter"""
data = {
"Description": "Will send only to contacts under 35 years of age.",
"Expression": "(age<35)",
"Name": "Customers under 35",
}
return mailjet30.contactfilter.create(data=data)
def create_a_campaign_with_a_segmentation_filter():
"""POST https://api.mailjet.com/v3/REST/newsletter"""
data = {
"Title": "Mailjet greets every contact over 40",
"Locale": "en_US",
"Sender": "MisterMailjet",
"SenderEmail": "Mister@mailjet.com",
"Subject": "Greetings from Mailjet",
"ContactsListID": "$ID_CONTACTLIST",
"SegmentationID": "$ID_CONTACT_FILTER",
}
return mailjet30.newsletter.create(data=data)
if __name__ == "__main__":
result = create_your_segment()
print(f"Status Code: {result.status_code}")
try:
print(json.dumps(result.json(), indent=4))
except ValueError:
print(result.text)