-
Notifications
You must be signed in to change notification settings - Fork 3
/
uploadContacts.py
38 lines (30 loc) · 1.24 KB
/
uploadContacts.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
import ElasticEmail
from ElasticEmail.apis.tags import contacts_api
# 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'
"""
Upload contacts
Example api call that adds new contacts by uploading csv file.
Required columns in CSV file: Email.
Suggested columns in CSV file: AllowUnsubscribe, Status, ConsentDate, ConsentIP, ConsentTracking.
Example CSV file content:
Email
john@domain.com
"""
with ElasticEmail.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = contacts_api.ContactsApi(api_client)
query_params = {
'listName': "example list", # str | Name of an existing list to add these contacts to (optional)
'encodingName': "utf-8", # str | In what encoding the file is uploaded (optional)
}
body = dict(
file = open('./files/contacts.csv', 'rb'),
)
try:
api_instance.contacts_import_post(query_params=query_params, body=body)
print("Contacts uploaded.")
except ElasticEmail.ApiException as e:
print("Exception when calling ContactsApi->contacts_import_post: %s\n" % e)