Skip to content

Latest commit

 

History

History
99 lines (65 loc) · 2.6 KB

loadCampaign.md

File metadata and controls

99 lines (65 loc) · 2.6 KB

Load Campaign

This guide will walk you through the process of loading details about an existing campaign in your account using the Bash library. Example details you can get are like: name, status, recipients, subject etc.

Required Access Level: ViewCampaigns

Find out more by checking our API's documentation: https://elasticemail.com/developers/api-documentation/rest-api#operation/campaignsGet

What's a campaign?

When using Elastic Email, when you send an email to any group of contacts we call that a "campaign".

Preparation

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 ElasticEmail repository https://github.com/ElasticEmail/elasticemail-bash and make sure the script has executable rights

$ chmod u+x ElasticEmail

Let's dig into the code

Put the below code to your file.

In the first line indicate that it's a bash script:

#!/bin/bash

Variable for host value:

host=https://api.elasticemail.com

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

apiKey=YOUR_API_KEY

and create header variables for api key:

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

Define a method that will be used:

apiMethod=campaignsByNameGet

The only thing you need to specify is a campaign name

campaignName="example";

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:

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:

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

The whole code to copy and paste:

#!/bin/bash

host=https://api.elasticemail.com

apiKey=YOUR_API_KEY

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

apiMethod=campaignsByNameGet

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"

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

Run the code

bash script.sh