Eloqua’s SOAP API provides some great functionality, including operations for managing Contacts, Emails and Data Transfers. In this post, we’ll introduce the API's Campaign Service, that includes the following operations :

  • Campaign GetCampaign(int id)
  • Campaign[] ListCampaigns()
  • AddAssetToCampaign(CampaignAsset asset, int campaignId)

 

The first two operations involve listing and describing Marketing Campaigns. The last item in the list is AddAssetToCampaign, which allows you to associate assets such as Emails with Marketing Campaigns in your Eloqua install. In this document we'll use a sample written in c# to demonstrate how to associate Eloqua Email's to a Marketing Campaign. We'll also look at how to List and Describe Campaigns using the API.

 

Please note that you will need to add service references to your project for the Email and Campaign Service WSDL documents.

Email Service WSDL : https://secure.eloqua.com/API/1.2/EmailService.svc

Campaign Service WSDL : https://secure.eloqua.com/API/1.2/CampaignService.svc

 

Developers can use these web service to build applications that perform tasks such as displaying, composing and sending emails - as well as associating Emails with Marketing Campaigns.

 

Code Sample c# :

 

try
{
    // Instantiate a new instance of the Email Service with your Credentials
    var emailService = new EmailService.EmailServiceClient();
    emailService.ClientCredentials.UserName.UserName = @"Company\User.Name";
    emailService.ClientCredentials.UserName.Password = "______";

    // Instantiate a new instance of the Campagin Service with your Credentials
    var campaignService = new CampaignService.CampaignServiceClient();
    campaignService.ClientCredentials.UserName.UserName = @"Company\User.Name";
    campaignService.ClientCredentials.UserName.Password = "______";

    // List the campaigns in your Eloqua install
    CampaignService.Campaign[] campaigns = campaignService.ListCampaigns();
    foreach (CampaignService.Campaign campaign in campaigns)
    {
        Console.WriteLine("Id: " + campaign.Id);
        Console.WriteLine("Name: " + campaign.Name);
    }

    // Select a specific Campaign by id
    CampaignService.Campaign c = campaignService.GetCampaign(1);
    Console.WriteLine("Id :" + c.Id);
    Console.WriteLine("Name :" + c.Name);

    Console.WriteLine("Actual cost: " + c.ActualCost);
    Console.WriteLine("BudgetedCost :" + c.BudgetedCost);
    Console.WriteLine("Currency :" + c.Currency);
    Console.WriteLine("Description :" + c.Description);
    Console.WriteLine(" :" + c.EndDate);
    Console.WriteLine(" :" + c.ExternalCampaignID);
    Console.WriteLine(" :" + c.IncludeInROI);
    Console.WriteLine(" :" + c.StartDate);

    EmailService.Email emailDetails = emailService.GetEmailDetails(1);

    CampaignService.CampaignAsset asset = new CampaignAsset();
    asset.Type = CampaignAssetType.Email;
    asset.EntityId = emailDetails.Id;
    asset.Name = emailDetails.Name;

    // Associate the Email with the Campaign
    campaignService.AddAssetToCampaign(asset, c.Id);
} 
catch (Exception ex)
{
    // Display any error messages
    Console.WriteLine(ex.Message);
}