Overview - what this Library is?
We want to provide our clients a way to use our system however they like. That is why we have introduced the Integration Libraries - a group of functions and declarations to help you implementing our API to your system.
How to download and implement the Library
After you have downloaded the library (which is a single .py file), you might want to put it in your Python directory to have a quick and easy access to it manually or through your own code.
You will be using the import functionality to access any classes and methods that you need. Here's an example of such import. Insert this line of code at the beginning of your script:
from ElasticEmailClient import ApiClient, Account, Email
How to start working with the Library on your project
Whether you want to send an email or modify your template, you can do so by using the specific class under which the relevant methods can be found. You can refer to the ApiTypes class to create the desired object that would be used as a parameter in some calls.
The responses are being held as the dictionaries. Many of them are the representations of classes that you can find in the ApiTypes class or our API documentation. Use whichever source you like to read the response and use it however you like - print it on the screen or log in your database.
First of all, we need to setup an ApiKey, that is the unique identifier of your account. You can do this in two ways:
First option: open up ElasticEmailClient.py in your editor. Then, in the ApiClient class, you can find two fields: apiKey and apiUri. Change the former's value to your ApiKey available to you here. Don't mind the apiUri field, it is best to leave it untouched.
Second option: simply overwrite the apiKey field's value of the ApiClient class at the start of your code. Remember to import the ApiClient class first:
from ElasticEmailClient import ApiClient ApiClient.apiKey = '11111111-2222-3333-4444-555555555555'
This can also be used to swap between the accounts while your program is running, so you can keep this line in mind.
Some basic API calls made using this Library
An example of loading info about your own account and displaying the price per email:
from ElasticEmailClient import ApiClient, Account ApiClient.apiKey = '11111111-2222-3333-4444-555555555555' accountResponse = Account.Load() try: print (accountResponse['priceperemail']) # what a deal! except TypeError: print ('Server returned an error: ', accountResponse)
One of many ways to save your contacts:
from ElasticEmailClient import ApiClient, Contact ApiClient.apiKey = '11111111-2222-3333-4444-555555555555' contacts =  contacts.append("firstname.lastname@example.org") contactResponse = Contact.QuickAdd(contacts) print (contactResponse)
Sending an email:
from ElasticEmailClient import ApiClient, Email ApiClient.apiKey = '11111111-2222-3333-4444-555555555555' contacts =  contacts.append("email@example.com") subject = 'Your subject' fromEmail = 'Your Email' fromName = 'Your Company Name' bodyText = 'Text body' bodyHtml = '<h1>Html body</h1>' emailResponse = Email.Send(subject, fromEmail, fromName, to = contacts, bodyText = bodyText, bodyHtml = bodyHtml) try: print ('MsgID to store locally: ', emailResponse['messageid'], end='\n') # Available only if sent to a single recipient print ('TransactionID to store locally: ', emailResponse['transactionid']) except TypeError: print ('Server returned an error: ', emailResponse)
All code samples are licensed under MIT license.