This guide will walk you through the process of loading details about an existing campaign in your account using the PHP library. Example details you can get are like: name, status, recipients, subject etc.
Required Access Level: ViewCampaigns
When using Elastic Email, when you send an email to any group of contacts we call that a "campaign".
Put the below code to your file.
Load library using below line:
require_once(__DIR__ . '/vendor/autoload.php');
Generate and use your API key (remember to check a required access level):
define('MY_APIKEY', 'YOUR_API_KEY');
$config = ElasticEmail\Configuration::getDefaultConfiguration()->setApiKey('X-ElasticEmail-ApiKey', MY_APIKEY);
Create an instance of CampaignsApi that will be used to delete a campaign.
$apiInstance = new ElasticEmail\Api\CampaignsApi(
new GuzzleHttp\Client(),
$config
);
The only thing you need to specify is a campaign name
Find out more by checking our API's documentation: https://elasticemail.com/developers/api-documentation/rest-api#operation/campaignsGet
$name = "My Campaign 1";
$response = $apiInstance->campaignsGet($name);
require_once(__DIR__ . '/vendor/autoload.php');
define('MY_APIKEY', 'YOUR_API_KEY');
$config = ElasticEmail\Configuration::getDefaultConfiguration()->setApiKey('X-ElasticEmail-ApiKey', MY_APIKEY);
$apiInstance = new ElasticEmail\Api\CampaignsApi(
new GuzzleHttp\Client(),
$config
);
$name = 'My Campaign 1';
try {
$response = $apiInstance->campaignsGet($name);
} catch (Exception $e) {
echo 'Exception when calling CampaignsApi->campaignsGet: ', $e->getMessage(), PHP_EOL;
}