Пропустить навигацию
fsakr

REST API C# Client - Searching for Data

Опубликовано: fsakr 27.07.2012

In a previous post, we introduced a C# Library that simplifies requests to Eloqua's REST API. In today's post, we're going to talk about the data portion of the Library.

The library currently supports the following data objects :

  • Contact
  • Account
  • Custom Object

 

The library also supports the following operations :

  • Get (item or list of items)
  • Post
  • Put
  • Delete

 

Let's look at a simple example using Accounts. Let's start by creating a new account :

 

Account account = new Account
                         {
                              id = -1,
                              address1 = "111 Peter St.",
                              city = "New York",
                              country = "United State",
                              name = "sample company"
                         };

Account createdAccount = client.Data.Account.Post(account);

 

The client also supports searching, retrieving, updating and deleting records. We hope that you find this helpful.

 

Please note that the REST API is not yet public and the code samples available here are my own work. I'll be glad to help support and fix issues in the code, but please understand that Eloqua will not be able to support this - as it is my own.

 

Thanks,

Fred

fsakr

Eloqua REST API - How to Retrieve Contact Activities

Опубликовано: fsakr 27.07.2012

In a previous post, we showed you how to Create and Manage Emails using the REST API. In today's post, we're going to demonstrate how to search for a Contact's activities. Please note that the code shared here expects that you know the ID of a Contact. You'll find several posts in the resource guide that will help you find Contacts using the API.

 

The complete source code for the examples shared here is available here on Github.

The models are available here.

 

The API supports the following types of Activity :

  • Email Open
  • Email Send
  • Email Click Through
  • Email Subscribe
  • Email Unsubscribe
  • Form Submit
  • Web Visit
  • Email Bounceback
  • Campaign Membership

 

Please note that the Activity endpoint in the API is currently readonly.

 

Let's start with a function (available in the sample project) that will invoke a request to retrieve the activities for a known Contact.

 

publicList<Activity>GetActivities(intcontactId,DateTimestartDate,DateTimeendDate,stringtype,int?count)
        {
            RestRequest request = new RestRequest(Method.GET)
                                      {
                                          RequestFormat = DataFormat.Json,
                                          Resource = string.Format("/data/activities/contact/{0}?startDate={1}&endDate={2}&type={3}&count={4}",
                                                            contactId, ConvertToUnixEpoch(startDate), ConvertToUnixEpoch(endDate), type, count)
                                      };

            IRestResponse<List<Activity>> response = _client.Execute<List<Activity>>(request);
            return response.Data;
}





 

Next, we'll invoke a request to pull a list of Email Open activities for this Contact :

 

DateTime startDate = new DateTime(2012, 1, 1);
DateTime endDate = new DateTime(2012, 7, 1);
var activities= _activityHelper.GetActivities(320, startDate, endDate, Enum.GetName(typeof(ActivitySample.Models.ActivityType), 2), 10);




 

Please note that the REST API is not yet public and the code samples available here are my own work. I'll be glad to help support and fix issues in the code, but please understand that Eloqua will not be able to support this - as it is my own.

 

Thanks,
Fred

fsakr

Bulk API How To : Check the Status of your Import

Опубликовано: fsakr 27.07.2012

This is the 4th and final step in the series : Bulk API How To : Upload Contacts into a List. In the last step, we showed you how to import your data. In today's post, we'll show you how to check the status of your import.

 

After importing the data, the API returns a Sync object :

 

public class Sync
    {
        public string syncedInstanceUri { get; set; }
        public DateTime? syncStartedAt { get; set; }
        public DateTime? syncEndedAt { get; set; }
        public SyncStatusType? status { get; set; }
        public DateTime? createdAt { get; set; }
        public string createdBy { get; set; }
        public string uri { get; set; }
}



The Sync.Uri will be used to check the status/result of the sync. You'll probably want to use some polling here, as the status may be pending before complete.

Given the URI, you can use the following method to check the Sync results :


public RequestObjectList<SyncResult> CheckSyncResult(string syncUri)
        {
            RestRequest request = new RestRequest(Method.GET)
                                      {
                                          Resource = syncUri + "/results",
                                          RequestFormat = DataFormat.Json
                                      };

            IRestResponse<RequestObjectList<SyncResult>> response = _client.Execute<RequestObjectList<SyncResult>>(request);
            return response.Data;
}



Please note that the code samples referenced here are my own work and something that I've put together to try and help.

I'll do my best to support the code, but please understand that this code is not supported by Eloqua.

 

Thanks,

Fred


fsakr

Bulk API How To : Import Data

Опубликовано: fsakr 27.07.2012

This is the 3rd step in the series : Bulk API How To : Upload Contacts into a List. In the last step, we showed you how to create the definition of your Import.

You'll remember that we supplied a list of Contact fields (to identify the metadata that we'll be working with).

 

The fields that we've chosen in this sample are :

  • C_EmailAddress
  • C_FirstName

 

As such, we'll create a dictionary of field name/value pairs to represent the contacts that will be created :

 

Dictionary<string,string> data = new Dictionary<string,string>
                           {
                               {"C_EmailAddress", "test123@test.com"},
                               {"C_FirstName", "Test123"}
                           };
            Dictionary<string, string> data2 = new Dictionary<string, string>
                           {
                               {"C_EmailAddress", "test456@test.com"},
                               {"C_FirstName", "Test456"}
                           };

            List<Dictionary<string, string>> list = new List<Dictionary<string, string>>
                           {
                               data,
                               data2
                         };


Next, we'll provide a function, which given the Uri for the import (defined in Step 2) and the field data above, will push the data to the server :



        public Sync ImportData(string importUri, List<Dictionary<string, string>> data)
        {
            RestRequest request = new RestRequest(Method.POST)
                                      {
                                          Resource = importUri + "/data",
                                          RequestFormat = DataFormat.Json
                                      };
            request.AddBody(data);

            IRestResponse<Sync> response = _client.Execute<Sync>(request);
            Sync sync = response.Data;

            return sync;
}


Please see the following post if you're interesting in Uploading Data using a CSV.


Please note that the code samples referenced here are my own work and something that I've put together to try and help.

I'll do my best to support the code, but please understand that this code is not supported by Eloqua.

 

Thanks,

Fred

This is the 2nd step in the series : Bulk API How To : Upload Contacts into a List. In the last step, we showed you how to setup your import by identifying :

  • contact fields : where the data is going
  • contact lists : where the contacts are going

 

The complete sample for this code is available on Github.

 

We'll now create the definition of the Import.

 

Import import= new Import
                                {
                name = "sample import",
                fields = fields,
                updateRule = RuleType.always,
                identifierFieldName = "C_EmailAddress",
                secondsToRetainData = 3600,
                isSyncTriggeredOnImport = true,
                syncActions = new List<SyncAction>()
                                                   {
                                                       new SyncAction()
                                                           {
                                                               action = SyncActionType.add,
                                                               destinationUri = "/contact/list/1"
                                                           }
                                                   }
            };

            RestRequest request = new RestRequest(Method.POST)
                                      {
                                          Resource = "/contact/import",
                                          RequestFormat = DataFormat.Json,
                                          RootElement = "import"
                                      };
            request.AddBody(import);

            IRestResponse<Import> response = _client.Execute<Import>(request);
            Import returnedImport = response.Data;
return returnedImport.uri;


Notice that we've supplied the following arguments (obtained in step 1 : How to Setup your Import) :

  • fields : a dictionary of the contact fields that will be included
  • destinationUri : the URI of the Contact List -> where the contacts will be uploaded


We've also identified :

  • updateRule : {"always", "ifNewIsNotNull", "ifExistingIfNull", "useFieldRule"}
  • identifierFieldName : the unique identifier for the Contact records (determines whether to Create or Update)
  • syncActions : {"add", "remove", "subscribe", "unsubscribe", "markActive", "markComplete"


Please note that I've written the code to try and help and I'll do my best to support it, but it is not supported by Eloqua.

 

Thanks,
Fred

fsakr

Eloqua REST API C# Client - Microsites

Опубликовано: fsakr 27.07.2012

We recently added support for Microsites in the c# library. If you're not familiar with this library, you can learn more about it here.

In today's post, we'll show you how to use the client to work with Microsites.

 

Let's start by instantiating the client and searching for Microsites :

 

Client client = new Eloqua.Api.Rest.Client("site", "user", "password");
List<Microsites> microsites = client.Assets.Microsite.Get("*", 1, 10);

 

The goal of the client is to make things as simple as possible, using strongly typed classes to represents the objects in the API.

Let's create a new Microsite :

 

Microsite microsite = new Microsite
                              {
                                   id = -1,
                                   name = "sample",
                                   domains = new List<string>{"sample.com"},
                                   isSecure = false
                              };
var createdMicrosite = client.Assets.Microsite.Post(microsite);

 

Note that you can attach more than one domain to the site.

 

We hope that you find this helpful.

Please note that the REST API is not yet public and the code samples available here are my own work. I'll be glad to help support and fix issues in the code, but please understand that Eloqua will not be able to support this - as it is my own.

 

Thanks,
Fred

fsakr

Bulk API How To : Upload Contacts using .csv

Опубликовано: fsakr 26.07.2012

In a previous post, we demonstrated how to Upload Contacts using the Bulk API. We've recently updated the sample project (available here on Github) to include support for .csv files.

The following code is available in the sample project, but we're calling it out here as we've had several requests for this recently.

 

using(FileStreamrdr=newFileStream(fileToUpload,FileMode.Open))
            {
                var req = (HttpWebRequest) WebRequest.Create(_baseUrl + importUri + "/data");
                req.Method = "POST";
                req.ContentLength = rdr.Length;
                req.ContentType = "text/csv";
                req.AllowWriteStreamBuffering = true;
                req.Headers.Add("Authorization", BuildAuthHeader(username, password));

                using (Stream reqStream = req.GetRequestStream())
                {
                    byte[] inData = new byte[rdr.Length];

                    reqStream.Write(inData, 0, (int) rdr.Length);

                    rdr.Close();
                    req.GetResponse();
                }
            }

 

Please note that the code samples referenced here are my own work and something that I've put together to try and help.

I'll do my best to support the code, but please understand that this code is not supported by Eloqua.

 

Thanks,

Fred

fsakr

Eloqua REST API C# Client - Contacts Lists

Опубликовано: fsakr 26.07.2012

In a previous post we introduced a c# library that simplifies interactions with Eloqua's REST API. In today's post, we'll demonstrate how to use this library to create and manage your Contact Lists.

We'll assume that you've already imported the dll and constructed the client, see the following post for details.

 

We'll start by creating a new Contact List.

(Notice that we're including some members, represented by their Contact IDs : 1, 2)

 

ContactList list = new ContactList
                              {
                                   id = -1,
                                   name = "sample",
                                   membershipAdditions = new List<string> {"1", "2")
                              };

 

Next, we'll invoke a simple request to create the list :

 

ContactList createdList = client.Assets.ContactList.Post(list);
var listId = createdList.id;

 

You've just created your list!

 

The next step is to add/remove members from the list. You can do this by manipulating the following properties :

  • membershipAdditions
  • membershipDeletions

 

// remove a member from the list
createdList.membershipDeletions = new List<string>{"1"}
client.Assets.ContactList.Put(createdList);

 

We hope that you find this helpful.

 

Please note that the REST API is not yet public and the code samples available here are my own work. I'll be glad to help support and fix issues in the code, but please understand that Eloqua will not be able to support this - as it is my own.

 

Thanks,

Fred

fsakr

Eloqua REST API - C# Client

Опубликовано: fsakr 24.07.2012

In today's post, we're going to share a C# library that simplifies interactions with Eloqua's REST API.

The client is open source under the Apache License and currently supports the following objects :

  • Email
  • Sending Email
  • Account
  • Contact
  • Custom Object
  • Contact List
  • Landing Page
  • Microsite
  • Contact Activity
  • Content Section
  • Dynamic Content

 

We're sharing this with the community in the hope that you'll help drive its development. We've started with a few basic types and welcome suggestions from the community for more.

This is an open project, so please feel free to submit any requests or changes.

 

Getting Started

The project is available here on Github. To get started, build the project and reference the following dll in your application : Eloqua.Api.Rest.dll

 

Usage

Create Client

var client = new Eloqua.Rest.Api.ClientLibrary.Client("site", "user", "pass");







 

GET (item)

int emailId = 1;
Email email = client.Assets.Email.Get(emailId);







 

GET (list)

List<Email> emails = client.Assets.Email.Get("searchTerm", pageNumber, pageSize);







 

POST

Email email = new Email() { ... };
email = client.Assets.Email.Post(Email);







 

PUT

Email email = new Email() { ... };
email = client.Assets.Email.Put(Email);







 

DELETE

int emailId = 1;
client.Assets.Email.Delete(emailId);







 

License

The project is intended for both open source and commercial environments.

 

Please note that the REST API is not yet public and the code samples available here are my own work. I'll be glad to help support and fix issues in the code, but please understand that Eloqua will not be able to support this - as it is my own.

 

Thanks,
Fred


fsakr

Eloqua REST API - How To Create a Contact Segment

Опубликовано: fsakr 24.07.2012

In today's post, we'll show you how to create the following Contact Segment :

 

 

A complete working sample of the code is available here on Github.

The code assumes that you've initialized the REST client. Please see the following post on making Eloqua REST API - C# requests.

The models are available here.

 

We'll start by defining the Filter Critiera : "Sent any Email". This object contains two important properties :

  • activityRestriction : at least once
  • timeRestriction : within the last week

 

            // Activity Restriction (number of sends)
            var activityRestriction = new NumericValueCondition
                                          {
                                              id = -500020,
                                              @operator = "withinLast",
                                              type = "NumericValueCondition",
                                              value = 1
                                          };

            // Time Restriction (sent within the last)
            var timeRestriction = new DateValueCondition
                                      {
                                          id = -21,
                                          @operator = "withinLast",
                                          type = "DateValueCondition",
                                          value = new RelativeDate
                                                      {
                                                          id = "-500021",
                                                          offset = 1,
                                                          timePeriod = "week",
                                                          type = "RelativeDate"
                                                      }
};
    

 

Next, we'll create a container for our Filter Criteria :

 

          // The endpoint expects a list, but we'll only include 1 criteria
            List<ContactSegmentSample.Models.Criteria.Criterion> criteria = new List<ContactSegmentSample.Models.Criteria.Criterion>();
            criteria.Add(emailSentCriterion);
    

 

Contact Segments can contain one or many Contact Filters. In our example, we're only using 1 Filter, but the API expects this as a list.

We're going to create another list, but please note that we're only adding a single Filter.

 

            // Next we'll create a Contact Filter
            ContactFilter filter = new ContactFilter
                                       {
                                           criteria = criteria,
                                           id = -500012,
                                           name = "Filter Sample",
                                           scope = "local",
                                           statement = "-500014",
                                           type = "ContactFilter"
                                       };

            ContactFilterSegmentElement filterElement = new ContactFilterSegmentElement()
                                                            {
                                                                filter = filter,
                                                                id = -500013,
                                                                isIncluded = true,
                                                                type = "ContactFilterSegmentElement"
                                                            };

            // The Segment expects one or more Filters, we'll include 1
            List<SegmentElement> filterElements = new List<SegmentElement>();
filterElements.Add(filterElement);
    

 

The ContactSegment model is the main container that we'll be sending to the API. It contains all of the elements that we're created above :

 

                   ContactSegment segment = new ContactSegment
                                         {
                                             detph = "complete",
                                             id = -500002,
                                             elements = filterElements,
                                             name = "sample segment",
                                             type = "ContactSegment"
};
    

 

Finally, we'll provide a function that accepts this ContactSegment as an argument and invokes an HTTP POST request to create the record :

 

        publicContactSegment CreateSegment(ContactSegment segment)
        {
            RestRequest request = new RestRequest(Method.POST)
                                      {
                                          RequestFormat = DataFormat.Json,
                                          Resource = "/assets/contact/segment"
                                      };
            request.AddBody(segment);

            IRestResponse<ContactSegment> response = _client.Execute<ContactSegment>(request);
            return response.Data;
}
   

 

We've started with a simple Contact Segment, but please let us know if you're interested in working with other Filters or Criteria and we'll be glad to add them to the project.

 

Please note that the REST API is not yet public and the code samples available here are my own work. I'll be glad to help support and fix issues in the code, but please understand that Eloqua will not be able to support this - as it is my own.

 

Thanks,
Fred

 

 

fsakr

Eloqua REST API - Create and Manage Segments

Опубликовано: fsakr 24.07.2012

In a previous post, we showed you how to Create and Manage Emails using the REST API. In today's post we're going to show you how to Create and Manage Segments.

Note that Segments are complex types and can contain dozens of different models representing Filters, Criteria and Conditions.

 

Our sample will use a basic Segment containing a single Filter : (see picture below)

  • Contact Filter : Contacts who have been Sent Any Email at least 1 time in the last week

 

 

We're going to cover the following operations :

  • Search and Retrieve a Segment

 

And we'll provide separate posts to show you how to :

 

And the code samples on Github contain examples on :

  • Updating and Deleting a Segment

 

A complete working sample of the code is available here on Github.

The code assumes that you've initialized the REST client. Please see the following post on making Eloqua REST API - C# requests.

The models are available here.

 

Retrieve a Contact Segment

Let's start by retrieving a Contact Segment from your Eloqua install. Given the ID of a known Contact Segment, the following method will invoke an HTTP GET request to retrieve the Segment :

 

public ContactSegment GetSegment(int id)
        {
            RestRequest request = new RestRequest(Method.GET)
                                      {
                                          RequestFormat = DataFormat.Json,
                                          Resource = "/assets/contact/segment/" + id
                                      };

            IRestResponse<ContactSegment> response = _client.Execute<ContactSegment>(request);

            return response.Data;
}
    

 

Searching for a Contact Segment

The following method can be used to search for Contact Segments :

 

        public RequestObjectList<ContactSegment> SearchSegments(string searchTerm, int page, int pageSize)
        {
            RestRequest request = new RestRequest(Method.GET)
                                      {
                                          RequestFormat = DataFormat.Json,
                                          Resource =
                                              string.Format("/assets/contact/segments?search={0}&page={1}&count={2}",
                                                            searchTerm, page, pageSize)
                                      };

            IRestResponse<RequestObjectList<ContactSegment>> response = _client.Execute<RequestObjectList<ContactSegment>>(request);

            Console.WriteLine("Total: " + response.Data.total);

            return response.Data;
}
    

 

Stay tuned as we'll be adding posts on Creating, Updating and Deleting Contact Segments.

 

Please note that the REST API is not yet public and the code samples available here are my own work. I'll be glad to help support and fix issues in the code, but please understand that Eloqua will not be able to support this - as it is my own.

 

Thanks,
Fred

fsakr

Eloqua REST API - Create and Manage Landing Pages

Опубликовано: fsakr 18.07.2012

In a previous post, we showed you how to Create and Manage Emails using the REST API.

In today's post we'll show you how to Create and Manage Landing Pages.

 

We'll be using the following operations :

  • Retrieve a Landing Page
  • Search for Landing Pages
  • Create a Page
  • Update a Page
  • Delete a Page

 

The code assumes that you've initialized the REST client. Please see the following post on making Eloqua REST API - C# requests.

The complete source code for the examples shared here is available here on Github.

The models are available here.

 

Retrieve a Landing Page

Let's start by retrieving a Landing Page from your install.

Note that this method assumes that you know the ID of a Landing Page in your install. If you're not sure of this, skip to Searching for Landing Pages.

 

public LandingPage GetLandingPage (int id)
        {
            RestRequest request = new RestRequest(Method.GET)
                                      {
                                          RequestFormat = DataFormat.Json,
                                          Resource = "/assets/landingPage/" + id
                                      };

            IRestResponse<LandingPage> response = _client.Execute<LandingPage>(request);
            return response.Data;
}
  

 

Searching for Landing Pages

The Search operation takes 3 arguments :

  • searchTerm : specifies the search criteria to use to filter the Landing Pages
  • page : the page of entities to return
  • pageSize : the number of entities to return

 

publicList<LandingPage> GetLandingPages (string searchTerm, int page, int pageSize)
        {
            RestRequest request = new RestRequest(Method.GET)
                                      {
                                          RequestFormat = DataFormat.Json,
                                          Resource =
                                              string.Format("/assets/landingPages?search={0}&page={1}&count={2}",
                                                            searchTerm, page, pageSize)
                                      };

            IRestResponse<RequestObjectList<LandingPage>> response =
                _client.Execute<RequestObjectList<LandingPage>>(request);

            Console.WriteLine("Total : " + response.Data.elements.Count);

            return response.Data.elements;
}
 

 

Creating a Landing Page

Now let's create a new Landing Page. We'll start by creating the definition for a new Landing Page object :

 

LandingPagelandingPage = newLandingPage
                                          {
                                              name = "sample landing page",
                                              htmlContent = new RawHtmlContent
                                                                {
                                                                    type = "RawHtmlContent",
                                                                    html =
                                                                        "<html><head></head><body>Sample Landing Page</body></html>"
                                                                }
                                          };
            LandingPage returnedLandingPage = _landingPageHelper.CreateLandingPage(landingPage);
Assert.AreEqual(landingPage.name,returnedLandingPage.name);
 

 

Next, we'll provide a function that invokes an HTTP POST request to create the page :

 

public LandingPage CreateLandingPage(LandingPage landingPage)
        {
            RestRequest request = new RestRequest(Method.POST)
                                      {
                                          Resource = "/assets/landingPage",
                                          RequestFormat = DataFormat.Json
                                      };
            request.AddBody(landingPage);

            IRestResponse<LandingPage> response = _client.Execute<LandingPage>(request);

            return response.Data;
}

 

The code samples on Github contain methods and examples for :

  • Updating your Page
  • Deleting your Page

 

Please note that the REST API is not yet public and the code samples available here are my own work. I'll be glad to help support and fix issues in the code, but please understand that Eloqua will not be able to support this - as it is my own.

 

Thanks,
Fred

 

 

fsakr

Building Cloud Connectors : Testing

Опубликовано: fsakr 13.07.2012

Now that you've built your Cloud Connector, its time to start testing.

 

To start, log into your Eloqua install and go to the Setup area and select "Cloud Connectors" under the database section.

 

 

From here, you can add your new Cloud Connector manually to your install :

 

 

From there, you can see the new Cloud Connector on your Campaign Canvas (or in Program Builder) :

 

 

You're now ready to start testing.

 

Thanks,

Fred

fsakr

Eloqua REST API - Searching for Contacts

Опубликовано: fsakr 06.07.2012

In this post, we'll demonstrate how to search for contacts in the REST API using c#.

If you're new to c# and RESTful APIs, please see the following post on making API requests using c#.

 

Let's start by defining a model for the Contact record :

 

public class Contact
    {
        public string accountName { get; set; }
        public string address1 { get; set; }
        public string address2 { get; set; }
        public string address3 { get; set; }
        public string businessPhone { get; set; }
        public string city { get; set; }
        public string country { get; set; }
        public string emailAddress { get; set; }
        public string firstName { get; set; }
        public int? id { get; set; }
        public string lastName { get; set; }
        public bool? isSubscribed { get; set; }
        public bool? isBounceBack { get; set; }
        public string salesPerson { get; set; }
        public string title { get; set; }
        public List<FieldValue> fieldValues { get; set; }
}

 

Next, we'll provide you with a function that will invoke an HTTP GET request to search for Contacts using the API.

Please note that a complete working sample of this code is available here on Github.

 

public List<Contact>SearchContacts(string searchTerm ,int page ,int pageSize)
        {
            RestRequest request = new RestRequest(Method.GET)
                                      {
                                          RequestFormat = DataFormat.Json,
                                          Resource = string.Format("/data/contacts?search={0}&page={1}&count={2}&depth=complete", searchTerm,
                                                            page, pageSize)
                                      };

            IRestResponse<RequestObjectList<Contact>> response = _client.Execute<RequestObjectList<Contact>>(request);

            List<Contact> contacts = response.Data.elements;

            return contacts;
}

 

Finally, we'll execute a search for all contacts whose email address ends with "@domain.com" :

 

List<Contact>contacts =_contactHelper.SearchContacts("*@domain.com",1,100);

 

We hope that you find this useful.

 

Please note that the REST API is not yet public and the code samples available here are my own work.

I'll be glad to help support and fix issues in the code, but please understand that Eloqua will not be able to support this - as it is my own.

 

Thanks,
Fred

 

 

fsakr

Eloqua REST API - Activate a Campaign

Опубликовано: fsakr 06.07.2012

In this post, we'll show you how to activate a Campaign using the REST API. This is the 3rd step in the series Sending Email to a Segment or List of Contacts.

In the last step, we created the following Campaign :

 

https://lh6.googleusercontent.com/n9dFpMJMXgkAEevEjYXr45wHaUmURmvkeCPjiJHWTEgZRvCRnNdpz3L5XkhTasAkfEObFtHuy_lOdwkeabK8yzBY76HoP9kHUXQol95Y5kAWcOn-uS8

 

Assuming the ID of the new Campaign is 1, we'll create a function that will be responsible for activating the Campaign :

 

public Campaign ActivateCampaign (int campaignId)
        {
            RestRequest request = new RestRequest(Method.POST)
                                      {
                                          Resource = "/assets/campaign/activate/" + campaignId,
                                          RequestFormat = DataFormat.Json
                                      };

            IRestResponse<Campaign> response = _client.Execute<Campaign>(request);

            return response.Data;
        }


Note that a complete sample of the code is available here on Github.

The code call this function :

 

int campaignId=1;
Campaign campaign = _campaignHelper.ActivateCampaign(campaignId);


That's all there is to it. After the call completes, your Campaign will be active.

See picture below :

 

https://lh5.googleusercontent.com/atm3sONeioTzaCS8yUaN7OiSpOkXeFulYFcZc-qvl1L5d2zsAZwGWT_JkGBAWo8bnaWXXtRP86xnoO04JDFKebTEqTzn5MZgsk7IFmo-ESia2zdoyUY

 

Please note that the code samples referenced here are my own work and something that I've put together to try and help. I'll do my best to support it, but please understand that this code is not supported by Eloqua.

 

Thanks,

Fred

In today's post, we'll describe how to create a Campaign using the REST API. This is the 2nd step in the series

REST API : Sending Email to a Segment or List of Contacts.

 

The Campaign that we're going to build consists of 2 elements : (see picture below)

  • Segment
  • Email

 

https://lh6.googleusercontent.com/n9dFpMJMXgkAEevEjYXr45wHaUmURmvkeCPjiJHWTEgZRvCRnNdpz3L5XkhTasAkfEObFtHuy_lOdwkeabK8yzBY76HoP9kHUXQol95Y5kAWcOn-uS8

 

Let's start by creating the Campaign Segment named "Segment Sample".

Note that the models for the objects used in these samples are available here on Github and a complete working sample is available here.

 

Campaign Email

The following helper method (provided in the sample code) is responsible for creating the Email campaign element :

 

public CampaignEmail GetCampaignEmail(int emailId,int referenceId)
        {
            return new CampaignEmail
                       {
                           id = referenceId,
                           type = "CampaignEmail",
                           emailId = emailId,
                           sendTimePeriod = "sendAllEmailAtOnce",
                           position = new Position
                                          {
                                              x = 100,
                                              y = 100
                                          }
                       };
}

 

Notice that the method takes two arguments :

  • int emailId : the ID of the Email that will be sent
  • int referenceId : a negative number (unique) that identifies this element

The reference ID will be used in the next step, to connect the elements together.

 

Campaign Segment

The following helper method (provided in the sample code) is responsible for creating the Segment campaign element :

 

public CampaignSegment GetCampaignSegment(int segmentId, int referenceId, int outputElementId)
        {
            return new CampaignSegment
                       {
                           id = referenceId,
                           type = "CampaignSegment",
                           segmentId = segmentId,
                           isRecurring = false,
                           position = new Position
                                          {
                                              x = 10,
                                              y = 10
                                          },
                           outputTerminals = new List<CampaignOutputTerminal>
                                                 {
                                                     new CampaignOutputTerminal
                                                         {
                                                             connectedId = outputElementId,
                                                             connectedType = "CampaignEmail",
                                                             terminalType = "out"
                                                         }
                                                 }

                       };
}

 

Notice the method takes 3 arguments :

  • int segmentId : the ID of the Segment that will receive the Email
  • int referenceId : a negative number (unique) that identifies this element
  • int outputElementId : the referenceId of the element that this will output to (connected element)

 

Create the Campaign

The last step is to create the Campaign.

 

public Campaign CreateCampaign(int emailId, int segmentId)
        {
            CampaignEmail campaignEmail = _elementHelper.GetCampaignEmail(emailId, -101);
            CampaignSegment campaignSegment = _elementHelper.GetCampaignSegment(segmentId, -100, -101);

            Campaign campaign = new Campaign
                                    {
                                        name = "sample campaign",
                                        campaignType = "sample",
                                        startAt = ConvertToUnixEpoch(DateTime.Now),
                                        endAt = ConvertToUnixEpoch(DateTime.Today.AddDays(1)),
                                        elements = new List<CampaignElement>
                                                       {
                                                           campaignSegment,
                                                           campaignEmail
                                                       }
                                    };

            RestRequest request = new RestRequest(Method.POST)
                                      {
                                          Resource = "/assets/campaign",
                                          RequestFormat = DataFormat.Json
                                      };
            request.AddBody(campaign);

            IRestResponse<Campaign> response = _client.Execute<Campaign>(request);

            return response.Data;
        }

 

This method invokes a POST request to create a new Campaign, containing your Segment and Email.

 

Please note that the code samples referenced here are my own work and something that I've put together to try and help. I'll do my best to support it, but please understand that this code it not supported by Eloqua.

 

Thanks,

Fred

In this post, we'll describe some of the operations you'll need in order to setup your Campaign using the REST API.

This is the first step in the series : REST API : Sending Email to a Segment or List of Contacts.

 

In our example, we're working with a Segment and an Email. In order to create our Campaign, we'll need to first identify the Segment and Email that will be used.

See picture below for details :

 

https://lh6.googleusercontent.com/n9dFpMJMXgkAEevEjYXr45wHaUmURmvkeCPjiJHWTEgZRvCRnNdpz3L5XkhTasAkfEObFtHuy_lOdwkeabK8yzBY76HoP9kHUXQol95Y5kAWcOn-uS8

 

Please note that a complete working sample of the code is available here on Github.

 

Searching for Segments

Let's look at a simple example to search for and retrieve a list of Segments using the REST API.

We'll provide a function, which given a search term, page and pageSize, will return a list of matching Segments.

 

publicList<Segment> SearchSegments(string searchTerm,int page,int pageSize)
        {
            RestRequest request = new RestRequest(Method.GET)
                                      {
                                          RequestFormat = DataFormat.Json,
                                          Resource = string.Format("/assets/contact/segments?search={0}&page={1}&count={2}",
                                                            searchTerm, page, pageSize)
                                      };

            IRestResponse<RequestObjectList<Segment>> response = _client.Execute<RequestObjectList<Segment>>(request);
            List<Segment> segments = response.Data.elements;

            return segments;
}

 

The model for the Segment object used in this sample is available here on Github.

The complete working sample is available here on Gitbhub.

 

Searching for Emails

We already have a post discussing how to Create and Manage Email using the REST API.

 

Please note that the code samples referenced here are my own work and something that I've put together to try and help. I'll do my best to support it, but please understand that this code is not supported by Eloqua.

 

Thanks,

Fred

In a previous post, we discussed how to use the REST API to Send Email to a Contact. In today's post, we'll demonstrate how to send an email to a segment or list of contacts.

We're going to assume that the user is already familiar with Eloqua's Campaign Canvas.

 

There are 4 main steps to setup and deploy an Email to a Segment :

  1. Setup your Campaign
  2. Create your Campaign
  3. Activate your Campaign
  4. Check the Status and Cleanup

 

We'll add related posts for each step and for your convenience a complete working sample of the code is available here on Github.

 

In our example, we're essentially building a campaign that includes a segment and email, see picture below :

 

https://lh4.googleusercontent.com/SM9JdM6h-BU3xmVajA9MbAlmoItLyfcNkOx4_ABux_AVH6Dr5-dEyY6RldSXE7n2vXPefT2IWS7_f_Bvy72vr-cBi_mifz7RBqLW507BpouvGHFOYsQ

 

 

Remember that a Segment can include any combination of the following items :

  • Shared Lists
  • Shared Filters
  • Filter Criteria (including both Activity and Profile data)
  • Individual Contacts

 

If you're interested in working with Emails using the API, see the following post on Creating and Managing Emails using the REST API.

 

Please note that the samples referenced here are my own work and something that I've put together to try and help. I'll do my best to support it, but please understand that this code is not supported by Eloqua.

 

Thanks,

Fred

fsakr

Eloqua REST API - Sending Email to a Contact

Опубликовано: fsakr 03.07.2012

Eloqua will soon be exposing our web services in the form of REST Resources. The new API will give users access to create and send emails. It also provides access to manage your emails, edit content and configure details such as the sender, subject and much more.

 

In this post, we'll demonstrate a very basic use-case that uses the REST API to create an Email and send it to a known Contact. While code samples are provided below, the complete project is available here on Github.

This project is meant to help you get started with Emails in the REST API.

 

It includes helper methods to :

  • Create an Email
  • Update an Email
  • Get an Email
  • Search for Emails
  • Delete Email
  • Send Email

 

Let's start by creating a new Email using the REST API.

(Models for the objects used in this sample are available here.)

 

Email email = new Email()  
            {  
                name = "sample email",  
                emailFooterId = 1,  
                emailHeaderId = 1,  
                encodingId = 1,  
                emailGroupId = 1,  
                subject = "sample",  
                htmlContent = new RawHtmlContent()  
                                  {  
                                      type = "RawHtmlContent",  
                                      html = "<html><head></head><body>test</body></html>"  
                                  }  
            };  

 

Now that we've defined our Email, we'll create a function that invokes an HTTP Post request to create the Email in your Eloqua install.

 

public Email CreateEmail(Email email)
        {
            RestRequest request = new RestRequest(Method.POST)
                                      {
                                          Resource = "/assets/email",
                                          RequestFormat = DataFormat.Json
                                      };
            request.AddBody(email);

            IRestResponse<Email> response = _client.Execute<Email>(request);

            return response.Data;
        }

 

Finally, we'll provide a function to send the Email. Note that the arguments require that you know :

  • the ID of the contact
  • the Email that will be delivered

 

public Deployment SendEmailToContact(int contactId, Email email)
        {
            Deployment deployment = new Deployment
                                        {
                                            contactId = contactId,
                                            email = email,
                                            name = "sample deployment",
                                            type = "EmailTestDeployment"
                                        };

            RestRequest request = new RestRequest(Method.POST)
                                      {
                                          Resource = "/assets/email/deployment",
                                          RequestFormat = DataFormat.Json
                                      };
            request.AddBody(deployment);

            IRestResponse<Deployment> response = _client.Execute<Deployment>(request);

            return response.Data;
        }

 

Please note that the code samples referenced here are my own work and something that I've put together to try and help. I'll do my best to support the code, but please understand that this code is not supported by Eloqua.

 

Thanks,

Fred

Фильтр по блогу

По дате: По метке: