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