-
Notifications
You must be signed in to change notification settings - Fork 3
/
addContacts.py
40 lines (35 loc) · 1.4 KB
/
addContacts.py
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
import ElasticEmail
from ElasticEmail.apis.tags import contacts_api
from ElasticEmail.model.contact_status import ContactStatus
from ElasticEmail.model.contact_payload import ContactPayload
from pprint import pprint
# Defining the host is optional and defaults to https://api.elasticemail.com/v4
configuration = ElasticEmail.Configuration()
# Configure API key authorization: apikey
configuration.api_key['apikey'] = 'YOUR_API_KEY'
"""
Add contacts
Example api call that adds new contacts.
Pass array with contact details to add up to 1000 contacts.
Specify a list name in options or add to all contacts.
"""
with ElasticEmail.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = contacts_api.ContactsApi(api_client)
contact_payload = [
ContactPayload(
Email="johnsmith@domain.com",
Status=ContactStatus("Active"),
FirstName="John",
LastName="Smith",
),
] # [ContactPayload]
list_names = [
"New list",
] # [str] | Names of lists to which the uploaded contacts should be added to (optional)
try:
# Add Contact
api_response = api_instance.contacts_post(body = contact_payload, query_params = {'listnames': list_names})
pprint(api_response)
except ElasticEmail.ApiException as e:
print("Exception when calling ContactsApi->contacts_post: %s\n" % e)