Skip navigation

As usage of the Eloqua API quickly rises, we continue to receive great feedback from those building on the Eloqua platform. It has recently come to our attention that PHP and the EloquaService WSDL don't play nice together!

 

While the other Eloqua WSDL files work fine, a parsing issue with PHP's native SOAP library causes conflicts with overlapping names.

 

Upon further testing, we were able to make things work by splitting the WSDL document into atomic methods - 1 WSDL doc for each method.

 

So far, the following WSDLs have been generated for EloquaService (attached to this post):

 

  • ListEntityTypes()
  • DynamicEntityService()

 

If you are attempting to use PHP to consume the EloquaService WSDL, and are running into problems:

1. Let us know which web methods you need - and we can generate WSDL documents for them.

2. Be assured that the existing SOAP API (version 1.2) will not change - such that you can rely on local copies of the WSDL documents (generated in step 1).

3. Utilize the SOAP lib extension class : ElqSoapClient

4. Be aware that any changes to our SOAP API (1.2) will require us to provide a new version (1.3) so that we don't alter/break your local WSDL copies.

 

The sample code provided below uses native PHP SOAP libraries, with minor extensions. This basically sets up the SOAP headers for the request (using PHP's SOAP header class).

 

<?php
print "SOAP API Sample - ListEntityTypes()<p>";

 

###
# Extension of SoapClient - Eloqua SOAP API
##
class ElqSoapClient extends SoapClient {

 

public function __construct($wsdl, $username, $password) {

# WSSE Security Namespace
$wsSecurityNS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";

# SOAP Username and Password variables
$soapVarUser = new SoapVar($username, XSD_STRING, NULL, $wsSecurityNS, NULL, $wsSecurityNS);
$soapVarPass = new SoapVar($password, XSD_STRING, NULL, $wsSecurityNS, NULL, $wsSecurityNS);

# WSSE Authentication SOAP var
$WsAuthentication = new WsAuthentication($soapVarUser, $soapVarPass);
$soapVarWsAuthentication = new SoapVar($WsAuthentication, SOAP_ENC_OBJECT, NULL, $wsSecurityNS, 'UsernameToken', $wsSecurityNS);

# WSSE Authentication Token
$WsToken = new WsToken($soapVarWsAuthentication);

# Authentication Headers
$soapVarWsToken = new SoapVar($WsToken, SOAP_ENC_OBJECT, NULL, $wsSecurityNS, 'UsernameToken', $wsSecurityNS);
$soapVarHeaderVal=new SoapVar($soapVarWsToken, SOAP_ENC_OBJECT, NULL, $wsSecurityNS, 'Security', $wsSecurityNS);
$soapVarWsHeader = new SoapHeader($wsSecurityNS, 'Security', $soapVarHeaderVal, true);

# Create client
parent::__construct($wsdl);
parent::__setSoapHeaders(array($soapVarWsHeader));

}

}

##
# Sample Code - List Entity Types
##

 

# WSDL document - List Entity Service
$wsdl = "/Users/fredericksakr/Sites/listEntityService.xml";

 

# Client Credentials
$username = "Eloqua\Fred.Sakr";
$password = "#######";

 

# Instantiate a new instance of the Soap client
$client = new ElqSoapClient($wsdl, $username, $password);

 

# List web service methods
print_r ($client->__getFunctions());

 

# Invoke SOAP Request : ListEntityTypes()
try
{
$response = $client->ListEntityTypes(array());
}
catch (Exception $e)
{
print ($e->getMessage());
}

 

 

# Print the response
print_r($response);


### Web Service Helper classes

###

# Authentication helper class
##
class WsAuthentication {
private $Username;
private $Password;

 

 

function __construct($username, $password)
{
$this->Username=$username;
$this->Password=$password;
}

 

}

 

###
# Web Service Token helper class
##
class WsToken {
private $UsernameToken;

function __construct ($innerVal)
{
$this->UsernameToken = $innerVal;
}


}
?>

Building Apps for Eloqua - AppCloud Framework and the Bulk API
Using Eloqua's REST API

General Information


AppCloud Developer Framework

 

Eloqua's Bulk API

 

AppCloud Certification Program

Getting Started

 

Core Objects

 

Languages

Legacy Technology Documentation

Eloqua SOAP APIs


Cloud Connectors


Cloud Components

We are no longer accepting submissions for Cloud Components.  Until further notice, existing components will continue to work as usual.  See AppCloud Developer Framework, above, for information on AppCloud Content.

Continuing along in our series of Eloqua API How-To posts, let's look at how to programmatically submit a form. 

 

We will assume that the code found Connecting to the Eloqua API - Generic Setupis being used to establish a connection to the Eloqua API.

 

This example uses the EloquaService API.  For more information on which API to use for specific functions, see my post Eloqua SOAP API - Which one do I use?.

 

Now for the code...

 

    class FormSubmit
    {
        static void Main()
        {
             try
            {
                EloquaInstance service = new EloquaInstance("Instance", "username", "password");

 

                //Build a Form Entity Type object

                //For this example, I am using a form that I have already created in Eloqua.

                EntityType entityType = new EntityType
                                            {
                                                ID = 16,
                                                Name = "TJsTestForm",
                                                Type = "Form"
                                            };

                //Create a new Array of Dynamic Entities
                DynamicEntity[] dynamicEntities = new DynamicEntity[1];

 

                // Create a new Dynamic Entity and add it to the Array of Entities
                dynamicEntities[0] = new DynamicEntity
                                         {
                                             EntityType = entityType,
         
                                             // Create a Dynamic Entity's Field Value Collection

                                             //My form contains 3 required fields, email, first, and last name
                                             FieldValueCollection = new DynamicEntityFields
                                                                        {
                                                                            {"EmailAddress", "cloud.help@eloqua.com"},
                                                                            {"FirstName", "Cloud"},
                                                                            {"LastName", "Help"},
                                                                            {"FormID", "16"}
                                                                        }
                                         };

 

                // Execute the request
                CreateResult[] result = service.ServiceProxy.Create(dynamicEntities);

 

                // Verify the status of the submit
                foreach (CreateResult t in result)
                {
                    // Successfull requests return a positive integer value for ID
                    if (t.ID != -1)
                    {
                        Console.WriteLine(String.Format("Form Submit Successful!"));
                    }
                    // Failed requests return a -1 integer value for ID
                    else
                    {
                        // Extract the Error Message and Error Code for each failed Create request
                        foreach (Error createError in t.Errors)
                        {
                            Console.WriteLine(String.Format("Code: {0}", createError.ErrorCode));
                            Console.WriteLine(String.Format("Message: {0}", createError.Message));
                        }
                    }
                }
            }


            // Customize your own error handling code
            catch (System.ServiceModel.FaultException ex)
            {
                // Catch Service Model Fault Exceptions
                Console.WriteLine(String.Format("Reason: {0}", ex.Reason));
                Console.WriteLine(String.Format("Fault Type: {0}", ex.GetType()));
                Console.WriteLine(String.Format("Fault Code: {0}", ex.Code.Name));
            }
            catch (Exception ex)
            {
                // Catch System Exceptions
                Console.WriteLine(String.Format("Exception Message: {0}", ex.Message));
            }

 

            // Wait for user input before stepping out.
            Console.WriteLine("Press any key to continue.");
            Console.ReadKey();
        }
    }

 

When the program is run, a console window will pop up showing the results of the query something like below:

 

Capture.PNG

In a previous post, I showed you how to Eloqua API How To: Query a Contact by Email Address.  In that example, we assumed that a contact already existed in Eloqua, but what if we want to create a new contact? 

 

In this example, I will show you how to create a new contact, then retrieve that contact to confirm that it was in fact saved in Eloqua.

 

Once again, I will be assuming that the code found Connecting to the Eloqua API - Generic Setupis being used to establish a connection to the Eloqua API.

 

As before, we will be using the EloquaService API.  For more information on which API to use for specific functions, see Eloqua SOAP API - Which one do I use?.

 

Now, the code...

 

class CreateRetrieveContact
    {
        static void Main()
        {
            bool success = false;
            int contactId = 0;
            var contactIDs = new int[1];

            try
            {
                #region Setup the Eloqua service

                var service = new EloquaInstance("instance", "userid", "password");

                #endregion

 

                #region Create a contact using a Dynamic Entity

                // Build a Contact Entity Type object
                EntityType entityType = new EntityType {ID = 0, Name = "Contact", Type = "Base"};

 

                // Create an Array of Dynamic Entities
                DynamicEntity[] dynamicEntities = new DynamicEntity[1];

 

                // Create a new Dynamic Entity and add it to the Array of Entities
                dynamicEntities[0] = new DynamicEntity();
                dynamicEntities[0].EntityType = entityType;

 

                // Create a Dynamic Entity's Field Value Collection
                dynamicEntities[0].FieldValueCollection = new DynamicEntityFields();

 

                // Add the Contact's Email Address field to the Dynamic Entity’s field collection
                dynamicEntities[0].FieldValueCollection.Add("C_EmailAddress", "cloud_support@eloqua.com");

 

                // Add the Contact's First Name field to the Dynamic Entity’s field collection
                dynamicEntities[0].FieldValueCollection.Add("C_FirstName", "Cloud");

 

                // Execute the request
                var result = service.ServiceProxy.Create(dynamicEntities);

 

                // Verify the status of each Contact Create request in the results
                foreach (CreateResult t in result)
                {
                    // Successfull requests return a positive integer value for ID
                    if (t.ID != -1)
                    {
                        contactId = t.ID;
                        success = true;
                    }
                        // Failed requests return a -1 integer value for ID
                    else
                    {
                        // Extract the Error Message and Error Code for each failed Create request
                        foreach (Error createError in t.Errors)
                        {
                            Console.WriteLine(String.Format("Code: {0}", createError.ErrorCode));
                            Console.WriteLine(String.Format("Message: {0}", createError.Message));
                        }
                    }
                }

                #endregion

               

                #region Retrieve the contact dynamically

                if (success)
                {
                    // Set the ID of the Contact Entity
                    contactIDs[0] = contactId;

                   

                    // Create a new list containing the fields you want populated
                    List<string> fieldList = new List<string>();

 

                    // Add the Contact’s Email Address to the field list
                    fieldList.Add("C_EmailAddress");

 

                    // Add the Contact’s First Name to the field list
                    fieldList.Add("C_FirstName");

 

                    // Build a Dynamic Entity array to store the results
                    DynamicEntity[] retrievedEntities;

 

                    // If the field list is empty - the request will return all Entity Fields
                    // Otherwise, only fields defined in the field list are returned
                    if (fieldList.Count == 0)
                    {
                        // Execute the request and return all of the Entity's fields
                        retrievedEntities = service.ServiceProxy.Retrieve(entityType, contactIDs, null);
                    }
                    else
                    {
                        // Execute the request and return only the selected Entity fields
                        retrievedEntities = service.ServiceProxy.Retrieve(entityType, contactIDs, fieldList.ToArray());
                    }

                    // If a result was found, extract the field values for each Dynamic Entity
                    if (retrievedEntities.Length > 0)
                    {
                        foreach (DynamicEntity dynamicEntity in retrievedEntities)
                        {
                            // Extract the Field Name and Value for each element in the collection
                            foreach (KeyValuePair<string, string> keyValPair in dynamicEntity.FieldValueCollection)
                            {

                                                        Console.WriteLine("New Contact Created Successfully!");
                                Console.WriteLine(String.Format("Field Name: {0}", keyValPair.Key));
                                Console.WriteLine(String.Format("Field Value: {0}", keyValPair.Value));
                            }
                        }
                    }
                }
                #endregion

 

                // Customize your own error handling
            }
            catch (System.ServiceModel.FaultException ex)
            {
                // Catch Service Model Fault Exceptions
                Console.WriteLine(String.Format("Reson: {0}", ex.Reason.ToString()));
                Console.WriteLine(String.Format("Fault Type: {0}", ex.GetType().ToString()));
                Console.WriteLine(String.Format("Fault Code: {0}", ex.Code.Name.ToString()));
            }
            catch (Exception ex)
            {
                // Catch System Exceptions
                Console.WriteLine(String.Format("Exception Message: {0}", ex.Message.ToString()));
            }

            // Wait for user input before stepping out.
            Console.WriteLine("Press any key to continue.");
            Console.ReadKey();

        }
    }

 

 

When the program is run, a console window will pop up showing the results as seen below.

 

Capture.PNG/servlet/JiveServlet/downloadImage/38-1160-1475/Capture.PNG

Filter Blog

By date: By tag: