Bash | Elastic Email


Authentication

To provide valid authentication and start using our API, you will need an API key. To generate your API key, enter settings on your Elastic Email account and go to Settings -> Manage API Keys -> Create or you can also click on the link: 

https://elasticemail.com/account#/settings/new/create-api

Ceater API key

At this point, you can set custom permissions and optional access for your API key. 

Security tip: The restriction forces the API Key to work only with an IP or IP range that will be specified in this field.

Create API key 2

Once you create your API key, keep it safe as it will be used for every API call you make in order to identify you and confirm your account’s credentials. You can create either up to 15 or an unlimited amount of API keys based on your pricing plan. 

Your API key should be sent inside the header with the parameter name ‘x-elasticemail-apikey’ and your API key as a value.

Installation and Usage

Installation

Our official downloadable Bash library is available on GitHub.

Bash

The first step is to install the development environment on Windows. On Linux and iOS, bash is installed. 

The generated bash-completion script can be either directly loaded to the current Bash session using:

Copied!

source ElasticEmail.bash-completion

Alternatively, the script can be copied to the /etc/bash-completion.d (or on OSX with Homebrew to /usr/local/etc/bash-completion.d):

Copied!

sudo cp ElasticEmail.bash-completion /etc/bash-completion.d/ElasticEmail

OS X

On OSX you might need to install bash-completion using Homebrew:

Copied!

brew install bash-completion

and add the following to the ~/.bashrc:

Copied!

if [ -f $(brew --prefix)/etc/bash_completion ]; then
  . $(brew --prefix)/etc/bash_completion
fi

Zsh

In Zsh, the generated _ElasticEmail Zsh completion file must be copied to one of the folders under the $FPATH variable.

Quick start guide

In this section, we will tell you the steps to start sending emails with our email API.

1. Register a free account

Register and activate your Elastic Email account to get access to our product.

2. Verify your domain

Follow the instructions on our settings page to verify your domain and start sending with us.

3. Create an API Key

Go to your setting to generate an API Key to add to your code later.

4. Install our libraries

Install our Bash library as explained in the Installation and usage section.

5. Send your first email with API

Now it’s time to send your first test email with API to make sure that everything is set up correctly after downloading the library and the authentication process.

Copied!

host=https://api.elasticemail.com
 
apiKey=YOUR_API_KEY
 
apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey
 
apiMethod=emailsPost
 
json='{
        Recipients: [
            { 
                Email: "MeowWow ", 
                Fields: {
                    name: "MeowWow"
                }
            }
        ],
        Content: {
            Body: [
                {
                    ContentType: "HTML",
                    Charset: "utf-8",
                    Content: "My test email content ;)"
                },
                {
                    ContentType: "PlainText",
                    Charset: "utf-8",
                    Content: "Hi {name}!"
                }
            ],
            From: "MyEmail ",
            Subject: "Bash EE lib test"
        }
    }'
 
echo $json | ./ElasticEmail --host $host --content-type json $apiMethod - $apiKeyHeader

Code Samples

Once you have sent the test email with our API, you can start sending transactional emails and perform various operations directly through your app. We have prepared for you some code samples for most essential actions, including managing contacts and lists, creating templates, and sending and tracking emails. Thanks to them, your integration with our API will be an even easier and more pleasant experience.
In case any of the following snippets are changed in the meantime, the most recent version of this API Library is available on GitHub.

It’s a Bash script so it’s a program to be run by Unix shell. On Linux (eg. Ubuntu) there’s no need to install anything additional.

Create a new file eg. script.sh

Download the lib from the ElasticEmail repository and make sure the script has executable rights

Copied!

$ chmod u+x ElasticEmail

Managing Contacts

In this section, we will walk you through managing the contacts on your account using the Bash library.

Add Contacts

To add contacts to your account, you will need Access Level: ModifyContacts.

Put the following code into your file.

Load library using the following line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define a method that will be used:

Copied!

apiMethod=contactsPost

Specify an existing list name, otherwise, new contacts will be added to all contacts.

Copied!

listname="New list"

Create an array with new contacts.

You can pass an array with up to 1000 contacts.

The Email field is mandatory, the rest is optional.

Copied!

json='[{
        Email: "johnsmith@domain.com",
        FirstName: "John",
        LastName: "Smith"
    }]'

And finally, you can use the lib to make an api call:

Copied!

echo $json | ./ElasticEmail --host $host --content-type json $apiMethod - $apiKeyHeader listnames="$listname"

Delete contacts

If you want to delete a contact, you will need Access Level: ModifyContacts.

To delete a contact, put the following code into your file.

Load library using the following line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define a method that will be used:

Copied!

apiMethod=contactsDeletePost

Define JSON with emails to delete:

Copied!

json='{ 
        Emails: ["johnsmith@domain.com2"]
    }'

And finally, you can use the lib to make an api call:

Copied!

echo $json | ./ElasticEmail --host $host --content-type json $apiMethod - $apiKeyHeader

Upload Contacts

If you want to upload contacts, you will need Access Level: ModifyContacts.

Put the following code into your file.

Load library using the following line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define endpoint path:

Copied!

apiMethodUrl="$host/v4/contacts/import"

Create options with a file name with its encoding. Optionally a list name to which contacts should be added, otherwise contacts will be added to all contacts.

Copied!

file="@contacts.csv"

encodingName="utf-8"

And finally, you can use the lib to make an API call:

Copied!

curl -F file=$file   -H "$apiKeyHeader"   -X POST "$apiMethodUrl?encodingName=$encodingName&listName=$listNameEncoded"

Export Contacts

If you want to export the selected contact to a downloadable file, you will need Access Level: Export.

Put the following code into your file.

Load library using the following line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define a method that will be used:

Copied!

apiMethod=campaignsPost

Specify options:

  • fileFormat – specify format in which file should be created, options are: “Csv” “Xml” “Json”.
  • emails – select contacts to export by providing array of emails
  • fileName – you can specify file name of your choice

Other options:

  • rule – eg. rule=Status%20=%20Engaged – Query used for filtering
  • compressionFormat – “None” “Zip”
Copied!

fileName="exported.csv"
fileFormat="Csv"
compressionFormat="Zip"

Define emails to be exported:

Copied!

emails=("johnsmith@domain.com" "karol.szczycinski@elasticemail.com")

Let’s transform it to format required by the lib emails=value1 emails=value2 emails=...:

Copied!

emailsParams=""

for email in "${emails[@]}"
do
    emailsParams="emails=\"$email\" $emailsParams "
done

And finally, you can use the lib to make an api call:

Copied!

./ElasticEmail --host $host $apiMethod $apiKeyHeader fileFormat="$fileFormat" fileName="$fileName" compressionFormat="$compressionFormat" $emailsParams

Managing Lists

In this section, we will walk you through managing your contact list on your account using the Bash library.

Add List

To add a list, you will need Access Level: ModifyContacts.

Put the following code into your file. 

Load library using the following line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define a method that will be used:

Copied!

apiMethod=listsPost

Create a JSON object with details about the new list. Only ListName is required.

You can also define if to allow unsubscription from the list and pass an email array of existing contacts on your account to add them to the list during list creation.

Copied!

json='{
        ListName: "Best contacts",
        AllowUnsubscribe: true,
        Emails: ["johnsmith@domain.com"]
    }'

And finally, you can use the lib to make an api call:

Copied!

echo $json | ./ElasticEmail --host $host --content-type json $apiMethod - $apiKeyHeader

Load List

To load a list, you will need Access Level: ViewContacts.

Put the following code into your file. 

Load library using the following line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define a method that will be used:

Copied!

apiMethod=listsByNameGet

The only thing you need to specify is a list name

Copied!

listName="test name 3[]??[]Special_characters!@#$%^&*()222"

But in case when your name contains some special URL characters you need to properly encode it first. For example you can use Bash engine and encodeURIComponent from JavaScript language for doing that or use other way of your preference:

Copied!

listNameEncoded=$(node -p "encodeURIComponent('$listName')") # output: "%5B%5D%3F%3F%5B%5DSpecial_characters%21%40%23%24%25%5E%26%2A%28%29222%0A"

And finally, you can use the lib to make an api call:

Copied!

./ElasticEmail --host $host $apiMethod name="$listNameEncoded" $apiKeyHeader

Delete List

To remove a contact list from your account, you will need Access Level: ModifyContacts.

Put the following code into your file.

Load library using the following line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define a method that will be used:

Copied!

apiMethod=listsByNameDelete

The only thing you need to specify is a list name

Copied!

listName="test name 3[]??[]Special_characters!@#$%^&*()222"

But in case when your name contains some special URL characters you need to properly encode it first. For example you can use Bash engine and encodeURIComponent from JavaScript language for doing that or use other way of your preference:

Copied!

listNameEncoded=$(node -p "encodeURIComponent('$listName')") # output: "%5B%5D%3F%3F%5B%5DSpecial_characters%21%40%23%24%25%5E%26%2A%28%29222%0A"

And finally, you can use the lib to make an api call:

Copied!

./ElasticEmail --host $host $apiMethod name="$listNameEncoded" $apiKeyHeader

Creating Templates

An email template is a body of email prepared and saved under a given name. In this section, you will get to know how to add and load email templates.

Add Template

To add a template, you will need Access Level: ModifyTemplates.

Put the following code into your file.

Load library using the following line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define a method that will be used:

Copied!

apiMethod=templatesPost

Create an object with details about the new template:

  • Name – the name of your template by which it can be identified and used
  • Subject – specify the default subject for this template
  • Body – specify actual body content eg. in HTML, PlainText or both
  • TemplateScope – specify scope, “Personal” template won’t be shared, “Global” template can be shared with your sub accounts.
Copied!

json='{
    Name: "My new template",
    Subject: "Default subject",
    Body: [{
        ContentType: "HTML",
        Charset: "utf-8",
        Content: "My template"
    }],
    TemplateScope: "Personal",
}'

And finally, you can use the lib to make an api call:

Copied!

echo $json | ./ElasticEmail --host $host --content-type json $apiMethod - $apiKeyHeader

Load Template

To load existing template details, you will need Access Level: ViewTemplates.

Put the following code into your file.

Load library using the following line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define a method that will be used:

Copied!

apiMethod=templatesByNameGet

The only thing you need to specify is a template name

Copied!

templateName="test name 3[]??[]Special_characters!@#$%^&*()222"

But in case when your name contains some special URL characters you need to properly encode it first. For example you can use Bash engine and encodeURIComponent from JavaScript language for doing that or use other way of your preference:

Copied!

templateNameEncoded=$(node -p "encodeURIComponent('$templateName')") # output: "%5B%5D%3F%3F%5B%5DSpecial_characters%21%40%23%24%25%5E%26%2A%28%29222%0A"

And finally, you can use the lib to make an api call:

Copied!

./ElasticEmail --host $host $apiMethod name="$templateNameEncoded" $apiKeyHeader

Delete Template

To delete a template, you will need Access Level: ModifyTemplates.

Put the following code into your file.

Load library using the following line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define a method that will be used:

Copied!

apiMethod=templatesByNameDelete

The only thing you need to specify is a template name

Copied!

templateName="test name 3[]??[]Special_characters!@#$%^&*()222"

But in case when your name contains some special URL characters you need to properly encode it first. For example you can use Bash engine and encodeURIComponent from JavaScript language for doing that or use other way of your preference:

Copied!

templateNameEncoded=$(node -p "encodeURIComponent('$templateName')") # output: "%5B%5D%3F%3F%5B%5DSpecial_characters%21%40%23%24%25%5E%26%2A%28%29222%0A"

And finally, you can use the lib to make an api call:

Copied!

./ElasticEmail --host $host $apiMethod name="$templateNameEncoded" $apiKeyHeader

Sending Emails

In this section, we will tell you how you can start sending emails using the Bash library. You will get to know how to send bulk and transactional emails.

Send Transactional Emails

To send transactional emails, you will need Access Level: SendHttp.

Put the following code into your file.

Load library using the following line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define a method that will be used:

Copied!

apiMethod=emailsTransactionalPost

First, you need to specify email details:

  • email recipients
  • email content:
    • body parts – in HTML, PlainText or in both
    • from email – it needs to be your validated email address
    • email subject
Copied!

json='{
        Recipients: {
            To: ["johnsmith@domain.com"]
        },
        Content: {
            Body: [
                {
                    ContentType: "HTML",
                    Charset: "utf-8",
                    Content: "<strong>Mail content.<strong>"
                },
                {
                    ContentType: "PlainText",
                    Charset: "utf-8",
                    Content: "Mail content."
                }
            ],
            From: "myemail@domain.com",
            Subject: "Example transactional email"
        }
    }'

And finally, you can use the lib to make an API call:

Copied!

echo $json | ./ElasticEmail --host $host --content-type json $apiMethod - $apiKeyHeader

Send Bulk Emails

Put the following code to your file to send a bulk email, meaning a single email sent to a large group at once.

You will need Access Level: SendHttp.

Load library using the following line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define a method that will be used:

Copied!

apiMethod=emailsPost

First, you need to specify email details:

  • email recipients:
    • this example demonstrates merge fields usage, for each recipient {name} will be changed to the recipient’s name
  • email content:
    • body parts – in HTML, PlainText or in both
    • from email – it needs to be your validated email address
    • email subject
Copied!

json='{
        Recipients: [
            { 
                Email: "johnsmith@domain.com", 
                Fields: {
                    name: "John"
                }
            }
        ],
        Content: {
            Body: [
                {
                    ContentType: "HTML",
                    Charset: "utf-8",
                    Content: "<strong>Hi {name}!<strong>"
                },
                {
                    ContentType: "PlainText",
                    Charset: "utf-8",
                    Content: "Hi {name}!"
                }
            ],
            From: "myemail@domain.com",
            Subject: "Example transactional email"
        }
    }'

And finally, you can use the lib to make an API call:

Copied!

echo $json | ./ElasticEmail --host $host --content-type json $apiMethod - $apiKeyHeader

Managing Campaigns

Add Campaign

To add your first campaign using the Bash library, you will need Access Level: ModifyCampaigns. Mind that when using Elastic Email, when you send an email to any group of contacts, we call it a “campaign”.

To add a campaign, put the following code into your file.

Load library using the following line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define a method that will be used:

Copied!

apiMethod=contactsExportPost

Create an example campaign object:

  • Name: defines campaign name by which you can identify it later
  • Recipients: define your audience
  • Content: define your message details
  • Status: define the status in which the campaign should be created

Send will be triggered immediately or postponed, depending on the given options. Because we define Status as Draft, in this case, it will be postponed and the campaign will be added to drafts.

Copied!

json='{ 
    Name: "my new campaign2", 
    Status: "Draft", 
    Recipients: { 
        ListNames: ["my list name"]
    },
    Content: [{
            From: "myemail@domain.com",
            ReplyTo: "myemail@domain.com",
            TemplateName: "hello_template",
            Subject: "Hello"
        }]
    }'

And finally, you can use the lib to make an api call:

Copied!

echo $json | ./ElasticEmail --host $host --content-type json $apiMethod - $apiKeyHeader

Load Campaign

To load details about a campaign list in your account using the Perl library, you will need Access Level: ViewCampaigns. Mind that when using Elastic Email, when you send an email to any group of contacts, we call it a “campaign”.

To load a campaign, put the following code into your file.

Load library using the following line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define a method that will be used:

Copied!

apiMethod=campaignsByNameGet

The only thing you need to specify is a campaign name

Copied!

campaignName="example";

But in the case when your name contains some special URL characters you need to properly encode it first. For example, you can use Bash engine and encodeURIComponent from JavaScript language for doing that or use another way of your preference:

Copied!

campaignName="[]??[]Special_characters!@#$%^&*()222"

campaignNameEncoded=$(node -p "encodeURIComponent('$campaignName')") # output: "%5B%5D%3F%3F%5B%5DSpecial_characters%21%40%23%24%25%5E%26%2A%28%29222%0A"

And finally, you can use the lib to make an api call:

Copied!

./ElasticEmail --host $host $apiMethod name="$campaignNameEncoded" $apiKeyHeader

Update Campaign

To update existing campaigns in your account using the Bash library, you will need Access Level: ModifyCampaigns. Mind that when using Elastic Email, when you send an email to any group of contacts, we call it a “campaign”.

To update a campaign, put the following code into your file.

Load library using the following line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define a method that will be used:

Copied!

apiMethod=campaignsByNamePut

Define what campaign to update:

Copied!

campaignName="my new campaign"

Create an example campaign object:

  • Name: defines campaign name by which you can identify it later
  • Recipients: define your audience
  • Content: define your message details
  • Status: define the status in which the campaign should be created

Send will be triggered immediately or postponed, depending on the given options. Because we define Status as Draft, in this case, it will be postponed and the campaign will be added to drafts.

Copied!

json='{ 
    Name: "my campaign", 
    Status: "Draft", 
    Recipients: { 
        ListNames: ["my list name"]
    },
    Content: [{
            From: "myemail@domain.com",
            ReplyTo: "myemail@domain.com",
            TemplateName: "hello_template",
            Subject: "Hello"
        }]
    }'

And finally, you can use the lib to make an API call:

Copied!

echo $json | ./ElasticEmail --host $host --content-type json $apiMethod name="$campaignNameEncoded" - $apiKeyHeader

Delete Campaign

To delete an existing campaign, you will need Access Level: ModifyCampaigns. Mind that when using Elastic Email, when you send an email to any group of contacts, we call it a “campaign”.

To delete a campaign, put the following code into your file.

Load library using the following line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define a method that will be used:

Copied!

apiMethod=campaignsByNameDelete

The only thing you need to specify is a campaign name

Copied!

campaignName="[]??[]Special_characters!@#$%^&*()222"

But in case when your name contains some special URL characters you need to properly encode it first. For example you can use Bash engine and encodeURIComponent from JavaScript language for doing that or use other way of your preference:

Copied!

campaignNameEncoded=$(node -p "encodeURIComponent('$campaignName')") # output: "%5B%5D%3F%3F%5B%5DSpecial_characters%21%40%23%24%25%5E%26%2A%28%29222%0A"

And finally, you can use the lib to make an api call:

Copied!

./ElasticEmail --host $host $apiMethod name="$campaignNameEncoded" $apiKeyHeader

Tracking

In this section, we will walk you through the steps of managing actions related to email tracking. You will get to know how to load delivery and campaign statistics from your account using the Bash library.

Load Statistics

To load delivery statistics from your account, you will need Access Level: ViewReports.

Put the following code into your file.

Load library using the line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define a method that will be used:

Copied!

apiMethod=apiMethod=statisticsGet

First you need to specify a date range:

  • from date
  • to date – optional
Copied!

fromDate="2022-01-17T00:00:00"
toDate="2023-01-17T00:00:00"

Single date format: YYYY-MM-DDThh:mm:ss

And finally, you can use the lib to make an api call:

Copied!

./ElasticEmail --host $host $apiMethod name="$listNameEncoded" $apiKeyHeader

Load Channels Statistics

To load statistics for each channel from your account, you will need Access Level: ViewChannels.

Put the following code into your file.

Load library using the following line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define a method that will be used:

Copied!

apiMethod=apiMethod=statisticsChannelsGet

Campaigns statistics response is paginated you need to specify pagination options:

  • limit – maximum returned items, limit = 0 means to return everything till the end of the list
  • offset – how many items should be skipped from begging

Eg. to return the first 20 elements specify pagination options as follows

Copied!

{
    limit: 20,
    offset: 0,
};

Let’s fetch everything:

Copied!

const paginationOptions = {
    limit: 0,
    offset: 0,
};

And finally, you can use the lib to make an api call:

Copied!

./ElasticEmail --host $host $apiMethod name="$listNameEncoded" $apiKeyHeader

Load Campaigns Stats

To load statistics for each email campaign from your account, you will need Access Level: ViewChannels.

Put the following code into your file.

Load library using the following line:

Copied!

#!/bin/bash

Variable for host value:

Copied!

host=https://api.elasticemail.com

Use your API key (remember to check a required access level):

Copied!

apiKey=YOUR_API_KEY

and create header variables for api key:

Copied!

apiKeyHeaderName=X-ElasticEmail-ApiKey
apiKeyHeader=$apiKeyHeaderName:$apiKey

Define a method that will be used:

Copied!

apiMethod=apiMethod=statisticsCampaignsGet

Campaigns statistics response is paginated you need to specify pagination options:

  • limit – maximum returned items, limit = 0 means to return everything till the end of the list
  • offset – how many items should be skipped from begging

Eg. to return the first 20 elements specify pagination options as follows

Copied!

{
    limit: 20,
    offset: 0,
};

Let’s fetch everything:

Copied!

const paginationOptions = {
    limit: 0,
    offset: 0,
};

And finally, you can use the lib to make an api call:

Copied!

./ElasticEmail --host $host $apiMethod name="$listNameEncoded" $apiKeyHeader



Source link

Leave a Reply

Your email address will not be published.