Email dispatch from Eloqua using the REST API (Eloqua 9).

A problem we encountered a little while back was attempting to CC people on emails sent to a list of contacts.

We were looking to send a dynamic email with custom content (sales targets with some conditional paragraphs) to a list of contacts, with a copy of each email also going to a sales manager so that everyone had a copy of the targets contained in the email. Eloqua doesn’t allow an email to be CC’d, and with the emails containing data specific to each contact also needing to go to the sales manager, this presented us with a challenge.

After reading some of the information on Topliners, the Eloqua Community, and particularly some of the excellent contributions by Fred Sakr, we found our answer. The sends would all be created using PHP and a MySQL database, then created dynamically in Eloqua and sent out. Below is an example of how we did a single send with a CC, but this can easily be built out into a loop to cover a list of contacts. It is based on the request script written by Fred, found on GitHub.

Firstly, we establish connection to our Eloqua instance, using our normal login credentials.

$user = USERNAME
$password = PASSWORD
$baseUrl = "";
$eloquaRequest = new EloquaRequest($site, $user, $password, $baseUrl);

We define and initialise three objects to hold our data.

class Email
public $name;
public $id;
public $subject;
public $htmlContent;
public $isTracked;
public $emailFooterId;

class Deployment
public $contactId;
public $email;
public $name;
public $type;

class HTMLContent
public $type;
public $html;

Initialise two of the objects, then later we initiliase the deployment object for each individual send.

$myHTML = new HTMLContent();
$email = new Email();

So now the email can be assembled in HTML using PHP based on our requirements for the current contact, and saved as a variable called $email_content. All images would be remotely linked but URL’s can go in normally, eg, they will be tracked using the setting ‘isTracked’ as below.

$email_content = "API Testing Script";

We then put it together in the objects.

$myHTML->type = 'RawHtmlContent';
$myHTML->html = $email_content;

$email->subject = SUBJECT LINE
$email->htmlContent = $myHTML; //our myHTML object with content in it.
$email->emailFooterId = 40; //our blank footer with tracking, this could be whatever you choose.
$email->encodingId = 3; //UTF8 encoding
$email->emailHeaderId = 558; //our blank header, our email content contains everything we need.
$email->isTracked = true; //ensures all URLs are 'eloqua-ised' and tracked
$email->emailGroupId = FOLDER ID //this is the folder in Eloqua you create to hold the created emails.

To find the header id, go to Email Details, and open up the header as if to edit it. In the URL bar you’ll see something like %26EmailHeaderID%3D558&Title= near the end of the URL, the ID for mine is 558. The %3D before the number is just a URL encoded equals sign, so the ID is after it.

The footer can be found the same way, looking for %26EmailFooterID%3D40&Title= in the URL. In this case my footer ID is 40.

The find the folder ID, make the folder, then just hover over it and you should see the function that’s going to be triggered in your status bar, the folder id is the number in the brackets of ‘EmailCampaign_Edit(XXX)’.

NOTE : I will be updating this very shortly with how to acquire all the necessary ID’s in Eloqua 10, along with any other changes to the process.

So we now have an object containing everything we need to create the email in Eloqua.

To create the object, and print it out, you use.

$response = $eloquaRequest->post('assets/email', $email);

It’s important to return a response at this point even if you don’t write it to screen because you need the newly created email’s ID. So after the response use the following to update your email object with the new ID :

$email->id = $response->id;

The email is now created in Eloqua and the email object contains all thats needed to use in the deployment (the previous email settings like footer, header etc won’t affect the deployment now the email has been created so they can be left in).

To send it to someone, you need to have the users Eloqua contact ID (you can’t just send to an email, they need to be an existing subscribed contact).

We have a script here that looks up users contact ID’s based on their email, but for simplicity we’ll just assume that its an individual with the contact ID ‘CSEAG000012345678’. Before you can do the send the ID needs to be formatted slightly differently, so just remove the ‘CSEAG’, and leave the rest.

Now we can add some variables into our deployment object.

$deployment = new Deployment();
$deployment->email = $email; //our email object
$deployment->type = "EmailTestDeployment";
$deployment->contactId = "000012345678";

Send it.

$eloquaRequest->post('assets/email/deployment', $deployment);

Your email has now been sent out as a quicksend to the first contact, so to send to the second :


$deployment = new Deployment();
$deployment->email = $email; //our email object
$deployment->type = "EmailTestDeployment";
$deployment->contactId = ANOTHER CONTACT ID;

$eloquaRequest->post('assets/email/deployment', $deployment);

A little bit of tidying up.


And thats it, a quite unusual problem solved.