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

Sending emails using the Eloqua API, updated for Eloqua 10.

To follow on from my last post, we’ve now been sending out CC’d emails using Eloqua 10, and it’s been a straightforward changeover, with only a couple of alterations to our code.

I think the simplest way to illustrate this is to just update the previous code, so…

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

$site = YOUR COMPANY NAME
$user = USERNAME
$password = PASSWORD
$baseUrl = "https://secure.eloqua.com/API/REST/1.0";
$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;
     public $folderId;
     public $emailGroupId; //we now have a group id as well, so this variable will add the emails to the group as well as the one above doing the folder where they are listed
}

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 https://community.oracle.com/community/topliners/ but with the additional querystring ‘?elqtrack=true’ appended to them and they will be tracked using the setting ‘isTracked’ as below. So an url would be like :

http://www.google.co.uk?elqtrack=true

$email_content = 'API Testing Script, with a <a href="https://community.oracle.com/community/topliners/?elqtrack=true">tracked url</a>';

We then put it together in the objects.

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

$email->name = NAME TO SAVE EMAIL AS IN ELOQUA
$email->subject = SUBJECT LINE
$email->htmlContent = $myHTML; //our myHTML object with content in it.
$email->emailFooterId = 36; //our blank footer with tracking, this could be whatever you choose.
$email->emailHeaderId = 17; //our blank header, our email content contains everything we need.
$email->isTracked = true; //ensures all URLs are 'eloqua-ised' and tracked
$email->folderId = FOLDER ID //this is the folder in Eloqua you create to hold the created emails.
$email->emailGroupId = EMAIL GROUP ID //this is the group in Eloqua you create to hold the created emails.

A lot of the ID’s for groups, folders etc are now hidden in Eloqua 10, so I have written a couple of scripts that will list them all which you can see here.

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

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 has now been 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 ‘CSEAT000012345678’. Before you can do the send the ID needs to be formatted slightly differently, so just remove the ‘CSEAT’, and leave the rest.

Now we can add some variables into our deployment object.

For Eloqua 10, the above paragraph is the same but I’ve updated the ‘CSEAG’ prefix to match E10’s ‘CSEAT’.

$deployment = new Deployment();
$deployment->email = $email; //our email object
$deployment->name = NAME TO SAVE DEPLOYMENT AS IN ELOQUA
$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 :

unset($deployment);

$deployment = new Deployment();
$deployment->email = $email; //our email object
$deployment->name = NAME TO SAVE DEPLOYMENT AS IN ELOQUA
$deployment->type = "EmailTestDeployment";
$deployment->contactId = ANOTHER CONTACT ID;

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

A little bit of tidying up.

unset($myHTML);
unset($email);
unset($deployment);

And thats it, a quite unusual problem solved again, this time in Eloqua 10.