Skip navigation

A while back I did a post Consuming the EloquaService WSDL with PHP that later turned out didn't really work too well!

 

Many developers are running into issues consuming the EloquaService WSDL, which is preventing them from building on the Eloqua Platform.

 

Well, there is now good news...Eloqua has developed an Eloqua PHP Client, and it is now in Alpha testing.

 

If you are a developer working with PHP, and are having trouble using the Eloqua API, please go to the link above and check out the great work that Syed has done!

Syed Naqvi

Eloqua PHP Client

Posted by Syed Naqvi Dec 16, 2011

Good news for folks wanting to use PHP to invoke Eloqua Service. We have been investigating the issues related to invoking Webservice calls through Native PHP Soap client using the EloquaService WSDL and have built a client that can solve your problem.

 

The client provides services to invoke SOAP call for all the methods enumerated in the Eloqua API 1.2 which provides functionality for managing assets, entities, activities, group memberships as well as basic email sending. The client also consist of a list of samples which include examples for most Eloqua API service calls. We encourage folks to join in the fun and suggest any other sample they would like to see.

 

 

Note: This client is currently in ALPHA and looking forward to the brave ones to try it. We will move it to Beta and forward after adding more functionality based on customer requirements & interest.

 

 

What do you need to have ?

There are some pre-req to using the client : 

  1. PHP 5.x installed
  2. PHP Soap Extension must be enabled
  3. PHP OpenSSL Extension must be enabled
  4. Have Git installed and configured if you want to fetch the project repository using Git.(Optional)

 

 

How can you get it ? 

  1. Create a free account on GitHub.com.
  2. Please send an email with your GitHub.com username to syed.naqvi@eloqua.com for getting access to the GitHub.com repository containing the PHP Client.
  3. Please read the README on steps for how to use it.

In a previous post, we briefly discussed the The Processed Activity Queue (PAQ).

 

Now that the PAQ has been enabled for your install, how do you use the Eloqua API to retrieve this data?


In this post, we will look at how to retrieve  the marketing activity data stored in an Eloqua instance.


To retrieve activity data via the API, without using the PAQ, see Eloqua API - How to Retrieve Activity Data


Once again, we will assume that the code found here is being used to establish a connection to the Eloqua API, and we will be using the EloquaService API (see Eloqua SOAP API - Which one do I use?). 

 

The code  is the same as that used for Eloqua API How To: Query a Contact by Email Address, with the exception of entityType.Name being "ProcessedActivity" instead of "Contact", and the use of a different search term.

 

In this snippet, we will assume that we have a field in our activity data called "Date".  We will use the search term Date='*' to bring back all of the data available.  You may choose to query using other fields, in this case, please see Eloqua API How To: Describe an Entity and Eloqua API How To: Query a Contact by Multiple Fields for more information on how to do this.


Now, to the code...

 

    class RetrieveActivityData

    {

        static void Main()

        {

           const string searchQuery = "Date='*'";

 

            try

            {

               //Create the service instance using your credentials

 

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

 

                // Instantiate a ProcessedActivity,Entity Type

                EntityType activityEntityType = new EntityType

                               {

ID = 0,

Name = "ProcessedActivity",

Type = "Base"

                               };

 

                // Create a new list containing the fields you want populated

                // We will leave this empty for now, which will cause the code to return all fields

                List<string> fieldList = new List<string>();

 

 

                // Define a container for the Query results

                DynamicEntityQueryResults queryResult;

 

                // Set the page number and size for the results

                const int currentPage = 1;

                const int pageSize = 20;

 

 

                // If the field list is empty - the request will return all Entity Fields

                if (fieldList.Count == 0)

                {

                    // Execute the request and return all of the Entity's fields

                    queryResult = service.ServiceProxy.Query(activityEntityType , searchQuery, null, currentPage, pageSize);

                }

                else

                {

                    // Execute the request and return only the selected fields

                    queryResult = service.ServiceProxy.Query(activityEntityType , searchQuery, fieldList.ToArray(), currentPage, pageSize);

                }

 

                if (queryResult.Entities.Length > 0)

                {

                    //Extract the total number of pages and records

Console.WriteLine(String.Format("Total number of pages: {0}", queryResult.TotalPages));

Console.WriteLine(String.Format("Total number of records: {0}", queryResult.TotalRecords));

 

                    // Extract each Dynamic Entity in the result

                    foreach (DynamicEntity dynamicEntity in queryResult.Entities)

                    {

                        // Extract the field name and value of each field in the collection

                        foreach (KeyValuePair<string, string> field in dynamicEntity.FieldValueCollection)

                        {

                            Console.WriteLine(String.Format("Field Name: {0}: {1}", field.Key, field.Value));

                        }

                    }

                }

            }

 

            // 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();

        }

    }

To expand on my previous post Building Cloud Connectors:  What is a Feeder? let's briefly discuss the general use case for each.

 

Step-based connectors are generally used to update or add data to records that already exist in Eloqua.  The true power of a step-based connector is the  use of Program Builder to perform operations (such as Lead Scoring) on contacts before they are sent to your connector step.  This gives the marketer a robust system to target and process data, and get the most out of  the use of your service. 

 

If your goal is to build an integration with a system that contains contact data that is not already in Eloqua, then a Feeder is the way to go.  A Feeder will allow marketers to reach out to your system and pull new leads (as contact records and custom data objects) into a contact group in Eloqua.  Once the new contacts are in Eloqua, their group can be used to "feed" a Program Builder program.

 

In order to offer the most flexibility, and drive adoption of your service, offering both types of connectors may be the best strategy. 

 

As far as coding effort, both types are developed using the same basic principles.

 

For more information, see Building On The Eloqua Platform - A Resource Guide