In a previous post, we briefly discussed the The specified item was not found..


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='*'";




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




                    // 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.");