In a previous post, we discussed how to Create and Manage Emails using the REST API. In today's post, we'll discuss Custom Objects.

We'll cover the following operations :

  • Retrive a Custom Object by ID
  • Search for Custom Objects
  • Create and Update Custom Objects
  • Delete Custom Objects

 

The sample code is available on Github : eloqua-samples/customObject-helper at master · fredsakr/eloqua-samples · GitHub

 

Searching for Custom Objects

The search operation has 3 arguments :

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

 

The following request will search for and retrieve a list of Custom Objects

 

public SearchResponse<CustomObject> SearchCustomObjects(string searchTerm, int page, int pageSize)
        {
            var request = new RestRequest(Method.GET)
                              {
                                  RequestFormat = DataFormat.Json,
                                  Resource =
                                      string.Format(
                                          "/assets/customObjects?depth=complete&search={0}&page={1}&count={2}",
                                          searchTerm, page, pageSize)
                              };

            var response = _client.Execute<SearchResponse<CustomObject>>(request);

            return response.Data;
}
        

 

Creating Custom Objects

The following properties are available on the Custom Object model :

  • displayNameFIeldId : the id of the field containing the display name
  • fields : List<CustomObjectField> // see sample code for model definition
  • id : <int>
  • name : <string>
  • uniqueCodeFieldId : the id of the unique code field

 

Let's start by defining a new object :

 

var customObject = new CustomObject
                                   {
                                       id = -10001,
                                       name = "sample",
                                       fields = new List<CustomObjectField>
                                                    {
                                                        new CustomObjectField
                                                            {
                                                                name = "sample text field",
                                                                dataType = Enum.GetName(typeof(DataType), DataType.text),
                                                                type = "CustomObjectField"
                                                            },
                                                        new CustomObjectField
                                                            {
                                                                name = "sample numeric field",
                                                                dataType = Enum.GetName(typeof(DataType), DataType.numeric),
                                                                type = "CustomObjectField"
                                                            },
                                                        new CustomObjectField
                                                            {
                                                                name = "sample date field",
                                                                dataType = Enum.GetName(typeof(DataType), DataType.date),
                                                                type = "CustomObjectField"
                                                            }
                                                    }
                                   };
        

 

The following method invokes an HTTP Post request to create the record :

 

public CustomObject CreateCustomObject(CustomObjectcustomObject)
        {
            var request = new RestRequest(Method.POST)
                              {
                                  RequestFormat = DataFormat.Json,
                                  Resource = "/assets/customObject"
                              };
            request.AddBody(customObject);

            var response = _client.Execute<CustomObject>(request);

            return response.Data;
        }
        

 

 

Samples for the update and delete API operations are available in the project on Github.

 

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