Tuesday, March 3, 2015

How to find the Email Group Id in Eloqua?

 How to find the Email Group Id in Eloqua? 

This post will explain  how to find the Email Group Id in Eloqua

There will be different approach to find the Email Group id. Here. This post explains the approach used by me.
Use any of the REST client(here i am using Advance Rest Client)

Provide the below URL - https://secure.p03.eloqua.com/API/REST/1.0/assets/email/groups

Select the Http Method as GET

Provide the Authorization header

Authorization: Basic xxxxxxxxxxx

Replace xxxxxxxxxxx with base64 encoded string of companyName\userName:password

Send the request

The response will have all the Email Group id details - id and name of the Emial group can be found in the response.

{
  elements: [2]
  0:  {
         type: "ContactEmailSubscription"
         contactId: "1"
         emailGroup: {
             type: "EmailGroup"
             id: "1"
            depth: "minimal"
            description: ""
            name: "Sample1"
            permissions: "fullControl"
            updatedAt: "1423758721"
           updatedBy: "1"
        }
       isSubscribed: "true"
       updatedAt: "1423219686"
   }
  1:  {
         type: "ContactEmailSubscription"
         contactId: "1"
         emailGroup: {
             type: "EmailGroup"
             id: "2"
            depth: "minimal"
            description: ""
            name: "Sample2"
            permissions: "fullControl"
            updatedAt: "1423758721"
           updatedBy: "1"
        }
       isSubscribed: "true"
       updatedAt: "1423219686"
   }
  page: 1
 pageSize: 1000
 total: 2
}



Sunday, March 1, 2015

How to send the email through Java API in Eloqua

How to send the email through Java API in Eloqua

This post explains how to send the email through Eloqua API.

Create the required model classes:

public class EmailTestDeployment 

    public String contactId ;
    public String sendFromUserId ;
    public Email email;
    public String name;
    public String type;       

}

public class Email 
{
public int emailGroupId;
public RawHtmlContent htmlContent; 
public int id; 
public boolean isPlainTextEditable; 
public String name; 
public String plainText; 
public boolean sendPlainTextOnly; 
public String subject; 

}

public class RawHtmlContent 
{
    public String type;
    public String html;

}

RestClient class to connect to Eloqua:


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class RestClient
{
    private String authToken;
    private String baseUrl;       
    public RestClient(String user, String password, String url)
    {
       baseUrl = url;             
       String authString = user + ":" + password;
      authToken = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(authString.getBytes());           
    }             
                          
    public String execute(String uri, String method, String body)  throws Exception
    {
       String response ="";
       try
       {           
          URL url = new URL(baseUrl + uri);
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();                         
          conn.setInstanceFollowRedirects(false);
          conn.setRequestMethod(method.toString());
          conn.setRequestProperty("Content-Type", "application/json");
          conn.setRequestProperty("Accept", "application/json");
          System.out.println(authToken);
          conn.setRequestProperty("Authorization", authToken);         
                  
          if (method == "POST" || method == "PUT")
          {
              if(null != body){
                  conn.setDoOutput(true);
                  final OutputStream os = conn.getOutputStream();
                  os.write(body.getBytes());
                  os.flush();
                  os.close();
               }
           }
                      
           InputStream is = conn.getInputStream();
           BufferedReader rd = new BufferedReader(new InputStreamReader( is));
           String line; 
           while ((line = rd.readLine()) != null)
           {
               response += line;
           }           
           rd.close();
           conn.disconnect();
         }
         catch (Exception e)
         {
            throw e;
         }
       return response;
      }

}



How to find the id of the existing contact in Eloqua

How to find the id of the existing contact in Eloqua

This post will explain How to find the id of the existing contact in Eloqua

Login to Eloqua
Click on Contacts in main page
Search by entering *, this will return all the contacts.
Open the particular contact.
Select Field Details tab and select All Contact Fields in the drop down.


In the Eloqua Contact ID field ignore CTHOM and all the zeros, consider the last digits as contact id(e.g 109)


Saturday, February 28, 2015

How to subscribe the Contact to a EmailGroup through Java API in Eloqua

How to subscribe the Contact to a EmailGroup through Java API in Eloqua

This post explains how to create the contact in Eloqua through java.

Create the required model classes:

public class EmailGroup
{
public String type;
public String id;
public String depth;
public String description;
public String name;
public String updatedAt;
public String updatedBy;
}

public class Subscription
{
public EmailGroup emailGroup;
public String isSubscribed;
public String contactId;
public String  type;
}

RestClient class to connect to Eloqua:

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class RestClient
{
    private String authToken;
    private String baseUrl;    
    public RestClient(String user, String password, String url)
    {
       baseUrl = url;          
       String authString = user + ":" + password;
      authToken = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(authString.getBytes());        
    }          
                       
    public String execute(String uri, String method, String body)  throws Exception
    {
       String response ="";
       try
       {        
          URL url = new URL(baseUrl + uri);
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();                      
          conn.setInstanceFollowRedirects(false);
          conn.setRequestMethod(method.toString());
          conn.setRequestProperty("Content-Type", "application/json");
          conn.setRequestProperty("Accept", "application/json");
          System.out.println(authToken);
          conn.setRequestProperty("Authorization", authToken);      
               
          if (method == "POST" || method == "PUT")
          {
              if(null != body){
                  conn.setDoOutput(true);
                  final OutputStream os = conn.getOutputStream();
                  os.write(body.getBytes());
                  os.flush();
                  os.close();
               }
           }
                   
           InputStream is = conn.getInputStream();
           BufferedReader rd = new BufferedReader(new InputStreamReader( is));
           String line;
           while ((line = rd.readLine()) != null)
           {
               response += line;
           }        
           rd.close();
           conn.disconnect();
         }
         catch (Exception e)
         {
            throw e;
         }
       return response;
      }
}



How to get the Subscriptions of a Contact through through Java API in Eloqua

How to get the Subscriptions of a Contact through through Java API in Eloqua

This post explains how to create the contact in Eloqua through java.

Create the required  model classes:

public class SubscriptionResponse
{
public List<Subscription> elements;
}

public class Subscription
{
public EmailGroup emailGroup;
public String isSubscribed;
}

public class EmailGroup
{
public String type;
public String id;
public String depth;
public String description;
public String name;
public String updatedAt;
public String updatedBy;
}

RestClient class to connect to Eloqua:

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class RestClient
{
    private String authToken;
    private String baseUrl;    
    public RestClient(String user, String password, String url)
    {
       baseUrl = url;          
       String authString = user + ":" + password;
      authToken = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(authString.getBytes());        
    }          
                       
    public String execute(String uri, String method, String body)  throws Exception
    {
       String response ="";
       try
       {        
          URL url = new URL(baseUrl + uri);
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();                      
          conn.setInstanceFollowRedirects(false);
          conn.setRequestMethod(method.toString());
          conn.setRequestProperty("Content-Type", "application/json");
          conn.setRequestProperty("Accept", "application/json");
          System.out.println(authToken);
          conn.setRequestProperty("Authorization", authToken);      
               
          if (method == "POST" || method == "PUT")
          {
              if(null != body){
                  conn.setDoOutput(true);
                  final OutputStream os = conn.getOutputStream();
                  os.write(body.getBytes());
                  os.flush();
                  os.close();
               }
           }
                   
           InputStream is = conn.getInputStream();
           BufferedReader rd = new BufferedReader(new InputStreamReader( is));
           String line;
           while ((line = rd.readLine()) != null)
           {
               response += line;
           }        
           rd.close();
           conn.disconnect();
         }
         catch (Exception e)
         {
            throw e;
         }
       return response;
      }
}



Saturday, February 14, 2015

How to create the contact in Eloqua through java

How to create the contact in Eloqua through java

This post explains how to create the contact in Eloqua through java.

Create the model class for Contact:

public class Contact
{
 public String accountName;
 public String address1;
 public String address2;
 public String address3;
 public String businessPhone;
 public String city;
 public String country;
 public String firstName;
 public String emailAddress;
 public String id;
 public boolean isBounceback;
 public boolean isSubscribed;
 public String lastName;
 public String salesPerson;
 public String title;
 public String type;
 public String name;

}

RestClient class to connect to Eloqua:

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class RestClient
{
 private String authToken;
 private String baseUrl;

 public RestClient(String user, String password, String url)
 {
  baseUrl = url;
  String authString = user + ":" + password;
  authToken = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(authString.getBytes());        }

 public String execute(String uri, String method, String body)  throws Exception
 {
  String response ="";
  try
  {
   URL url = new URL(baseUrl + uri);
   HttpURLConnection conn = (HttpURLConnection) url.openConnection();

   conn.setInstanceFollowRedirects(false);
   conn.setRequestMethod(method.toString());
   conn.setRequestProperty("Content-Type", "application/json");
   conn.setRequestProperty("Accept", "application/json");
         conn.setRequestProperty("Authorization", authToken);    
       
         if (method == "POST" || method == "PUT")
         {
          if(null != body){
    conn.setDoOutput(true);
          final OutputStream os = conn.getOutputStream();
                os.write(body.getBytes());
                os.flush();
                os.close();
          }
         }
       
         InputStream is = conn.getInputStream();
         BufferedReader rd = new BufferedReader(new InputStreamReader( is));

          String line;
         while ((line = rd.readLine()) != null)
         {
             response += line;
         }      
         rd.close();
         conn.disconnect();
  }
  catch (Exception e)
  {
   throw e;
  }
        return response;
 }
}




Saturday, February 7, 2015

How to activate the Campaign in Eloqua through java

How to activate the Campaign in Eloqua through java

This post explains how to activate the Eloqua campaign through java.

RestClient class to connect to Eloqua:

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class RestClient
{
    private String authToken;
    private String baseUrl;       
    public RestClient(String user, String password, String url)
    {
       baseUrl = url;             
       String authString = user + ":" + password;
      authToken = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(authString.getBytes());           
    }             
                          
    public String execute(String uri, String method, String body)  throws Exception
    {
       String response ="";
       try
       {           
          URL url = new URL(baseUrl + uri);
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();                         
          conn.setInstanceFollowRedirects(false);
          conn.setRequestMethod(method.toString());
          conn.setRequestProperty("Content-Type", "application/json");
          conn.setRequestProperty("Accept", "application/json");
          conn.setRequestProperty("Authorization", authToken);         
                  
          if (method == "POST" || method == "PUT")
          {
              if(null != body){
                  conn.setDoOutput(true);
                  final OutputStream os = conn.getOutputStream();
                  os.write(body.getBytes());
                  os.flush();
                  os.close();
               }
           }
                      
           InputStream is = conn.getInputStream();
           BufferedReader rd = new BufferedReader(new InputStreamReader( is));
           String line; 
           while ((line = rd.readLine()) != null)
           {
               response += line;
           }           
           rd.close();
           conn.disconnect();
         }
         catch (Exception e)
         {
            throw e;
         }
       return response;
      }
}



Friday, February 6, 2015

How to update the html content of Email template in Eloqua through java

How to update the html content of Email template in Eloqua through java

This post explains how to update the html content of the Eloqua email through java.

Create the model class for Email:

public class Email
{            
public int emailGroupId;
public RawHtmlContent htmlContent;
public Integer id;
public boolean isPlainTextEditable;
public String name;
public String plainText;
public boolean sendPlainTextOnly;
public String subject;
}
public class RawHtmlContent
{
 public String type;
 public String html;
}

Create the html template with place holder for dynamic content and place the template in the same location of the below java classes.

sample-template.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <body>
      ${content}
   </body>
</html>

RestClient class to connect to Eloqua

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class RestClient
{
    private String authToken;
    private String baseUrl;      
    public RestClient(String user, String password, String url)
    {
       baseUrl = url;            
       String authString = user + ":" + password;
      authToken = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(authString.getBytes());          
    }            
                         
    public String execute(String uri, String method, String body)  throws Exception
    {
       String response ="";
       try
       {          
          URL url = new URL(baseUrl + uri);
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();                        
          conn.setInstanceFollowRedirects(false);
          conn.setRequestMethod(method.toString());
          conn.setRequestProperty("Content-Type", "application/json");
          conn.setRequestProperty("Accept", "application/json");
          conn.setRequestProperty("Authorization", authToken);        
                 
          if (method == "POST" || method == "PUT")
          {
              if(null != body){
                  conn.setDoOutput(true);
                  final OutputStream os = conn.getOutputStream();
                  os.write(body.getBytes());
                  os.flush();
                  os.close();
               }
           }
                     
           InputStream is = conn.getInputStream();
           BufferedReader rd = new BufferedReader(new InputStreamReader( is));
           String line;
           while ((line = rd.readLine()) != null)
           {
               response += line;
           }          
           rd.close();
           conn.disconnect();
         }
         catch (Exception e)
         {
            throw e;
         }
       return response;
      }
}



Saturday, January 31, 2015

403 Forbidden/403 XSRF Protection Failure error while invoking Eloqua Send mail API

403 Forbidden/403 XSRF Protection Failure error while invoking Eloqua Send mail API

We will be receiving 403 Forbidden/ 403 XSRF Protection Failure error while invoking the Eloqua Send mail API - /api/rest/1.0/assets/email/deployment

Verify whether the user has the role "Engage Users", if not add the "Engage Users" security group to the user and Save the changes.


If the Engage Users role is already added then clear the browser cookies and try again.