In this post, we'll show you how to retrieve Activity data using the SOAP API. We'll assume that you're already familiar with how to connect to the API, but please see the following post (Connecting to the API) for more information.

 

The API exposes activities for the following assets :

  • Email
    • Email Open
    • Email Send
    • Email Subscribe
    • Email Unsubscribe
    • Email Click Through
  • Form
  • Web

 

The response for each activity will include a dictionary of details, related to the activity type.

 

For example, the Email Send activity will contain the following details :

  • Email Web Link
  • Email Name
  • Email Recipient ID
  • Subject Line

 

Let's look at a quick sample for retrieving some Email Send Activities :

 

We'll start by creating a new instance of the Eloqua Service :

 

            // Create a new instance of the service proxy
            var service = new EloquaService.EloquaServiceClient();
            service.ClientCredentials.UserName.UserName = "site\\user";
            service.ClientCredentials.UserName.Password = "password";

 

Next, we'll execute a request to list all of the Activity Types available :

 

            var types = service.ListActivityTypes();
            foreach (var type in types.ActivityTypes)
            {
                Console.WriteLine(type);
            }

 

Note that you will need to have a known Contact in order to retrieve activity data. Let's look at a simple request to retrieve a Contact by their email address :

 

            // Search for and identify a known Contact
            var entityType = new EntityType() { Type = "Base", Name = "Contact" };
            var queryResult = service.Query(entityType, "C_EmailAddress=fred.sakr@eloqua.com", null, 1, 1);
            var entity = queryResult.Entities[0];

 

Next, we'll build a list of Activity Types that we want to retrieve for this contact. In our example, we'll request Email Send activities :

 

            // Define the list of Activity Types to query for
            var activityTypes = new List<ActivityType>();
            activityTypes.Add(ActivityType.EmailSend);

 

We'll also provide the start and end date for the Activity data :

 

            // Define start and end dates for Activities
            var startDate = DateTime.Now.AddMonths(-3);
            var endDate = DateTime.Now;

 

Finally, we'll invoke a request to retrieve the activity data for this Contact :

 

            // Execute a request to retrieve a list of Activities
            var activityResult = service.GetActivities(entity, activityTypes.ToArray(), startDate, endDate);

 

And we'll loop through and write the data to the console :

 

            foreach (var item in activityResult)
            {
                Console.WriteLine("Activity Type: " + item.ActivityType);

                // Activity Details
                foreach (var detail in item.FieldValueCollection)
                {
                    Console.WriteLine(detail.Key + " : " + detail.Value);
                }
            }


 

We hope that you find this helpful.

 

Thanks,

Fred