Sending Eloqua Email from Salesforce Using REST API

Eloqua integrates with Salesforce using REST Client API to send emails. We are using Salesforce Apex Code to send Eloqua emails.

Eloqua integrates with Salesforce using REST Client API to send emails. We are using Salesforce Apex Code to send Eloqua emails. First, we have to install Advanced REST Client API tool as a Plug-in for browser extension, and use this tool to test sending the Eloqua emails. The Eloqua API authentication uses base-64 encoded value and it should be passed in every API call as part of the authorization header.

Basic Email Processing in Eloqua API Method:
There are two ways to send email using the Eloqua API:

Email Test Deployment:
To send an Email using the first method, we have to choose an existing Email in Eloqua from a Contact.

The sample JSON Request process as follows,
End Point URL :
Method : POST
Header : Authorization: Basic XXX
The ‘XXX’ value is an authorization token. This token will be generated by using Base64encoder method. Convert UserName\CompanyName and Password to a base64encoder value i.e., Authorization token.

  1. Ex: username1\companyname
  2. password123

Body : It is a JSON format.

"contactId" :"00000123", // Eloqua Contact ID
"sendFromUserId":"123", // Eloqua User ID of the Sender
"id":"123", // Eloqua assest Email Id
"name":"SampleEmail", // Eloqua asset Email name
"name":"Sample Test Deployment", // Email deployment name
"type":"EmailTestDeployment" // Email deployment type

Content–Type : appliation/json

Email Inline Deployment:
In this method, we have to create our own custom content to send email to one or many contacts, but that email content won’t be stored in Eloqua asset. The email is sent to contact(s) through Eloqua.

The sample JSON Request process as follows,
End Point URL :
Method : POST
Header : Authorization: Basic XXX
Body : It is a JSON format,

“contacts”:[	// Adding a list of Eloqua contacts.
“id”:”0000123” // Eloqua contact id
“sendFromUserId”:”123”, // Eloqua user id
“htmlContent”:{ // Html content body
“type”:”RasHtmlContent”,				 “html”:”<html><head></head><body>Test</body</html>”
 “isPlainTextEditable”:”fase”, // The text content is editable or not
 “name”:”Sample Email”, // Email name
“subject”:”Test Sample” // Emil subject content
“name”:”Sample Deploymnet”, // Email deployment name

Content–Type : appliation/json

Finally, click the Send button and you will see the response of the call.

The below is the screenshot as REST API Call,


Implementing API Call into SFDC Apex Code:
We want to send email through Eloqua from Salesforce, because there are some limitations with sending email process in Salesforce.

The sample Apex Code,
First, create an Apex class and declare a variable to store Eloqua credentials. Then, get an authorization token by using based64encode method.

String userName = 'abc'+'\'+'company';
String passWord = 'abc1';
Blob headerValue = Blob.valueOf(userName+':'+passWord);
String authorize = 'Basic '+EncodingUtil.base64Encode(headerValue);

Then, query a list of contacts from Contact Object which contains the field values of Eloqua Contact Id and Email, and these values are added into a wrapper class instance list.

List<WrapperClass.ContactList> conts = new List<WrapperClass.ContactList>();
	for(Contact con : contacts) // Queried the list of contacts stored in 'contacts' variable.
	WrapperClass.ContactList cons = new WrapperClass.ContactList();
	cons.emailAddress = con.Email; // Contact field Email Id = con.Eloqua_Person_ID__c; // Custom field in contact object.

To query an Email Template content from a Custom Object,

String contentBody;

Add an Email Template’s values into wrapper class variables for converting a JSON format into the content body and then pass it to setBody() method.

WrapperClass wrapp = new WrapperClass(); = 'Sending Email'; // Email Name
wrapp.sendFromUserId = '123' // Eloqua User ID
wrapp.type = 'EmailInlineDeployment'; // Email Type
wrapp.contacts = conts; // List of contants

WrapperClass.HtmlContent htmlCont = new WrapperClass.HtmlContent();
htmlCont.type = 'RawHtmlContent'; // Html type
htmlCont.html = '<html><body><h1>Hi,</h1><br>Sample Test Content<br><h2>Thanks</h2></body></html>';

WrapperClass.Emails emailCont = new WrapperClass.Emails(); = 'Sample Test Email'; // Email Template Name
emailCont.subject = 'Welcome!!!'; // Email subject line
emailCont.htmlContent = htmlCont; = emailCont;
contentBody = JSON.serializePretty(wrapp);

Now, construct a Http Request using REST API endpoint URL, send the email, and receive a HTTP Response back.

HttpRequest request=new HttpRequest();
            HttpResponse response=new HttpResponse();
            Http hp=new Http();
            sytem.debug('Response------'+response.getBody()); // Got the reponse body of the content

So, this functionality can be triggered by any event (for e.g. clicking a Button) in Salesforce, and emails can be sent to a list of contacts. If duplicate records exist in the list, then the email won’t be sent to any of the contacts.

The following is a wrapper class,

public class WrapperClass{
	public ContactList[] contacts;
	public Integer sendFromUserId; // sendFromUserId is a keyword
	public Emails email;
	public String name; // name is a keyword
	public String type; // type is a keyword
	public class ContactList{
	public Stirng id; // id is a keyword
	public String emailAddress; // emailAddress is a keyword
	public class Emails{
	public HtmlContent htmlContent;
	public String name; // name is a keyword
	public String subject; // subject is a keyword
	public class HtmlContent{
	public String type; // type is a keyword
	public String html; // html is a keyword

Note: The “Eloqua Engage” User License is required for the “Eloqua User” account that can send emails. The user credential is used in the authorization header.

Reference Links:
Eloqua REST API Authentication
Sending Email Using Eloqua REST API
Sending Email to Contact Using Eloqua REST API

About MST

At MST Solutions our cornerstone is to adapt, engage and create solutions which guarantee the success of our clients. The talent of our team and experiences in varied business verticals gives us an advantage over other competitors.

Recent Articles

Work with us.

Our people aren’t just employees, they are key to the success of our business. We recognize the strengths of each individual and allow them time and resources to further develop those skills, crafting a culture of leaders who are passionate about where they are going within our organization.