Use the FilterDefinition object to separate out information for a data source, such as a subscriber list or a data extension. Use the sample code below as a model for creating your own API call.
All date values for a simple filter part must go into the DateValue collection.
The FilterDefinition object contains these properties.
ObjectID
A unique identifier for the property.
CustomerKey
A client-supplied identifier for the filter. This must be unique across all FilterDefinitions owned by the client.
Name
A unique name for the filter. Don’t use the name for lookup purposes.
Description
A description of the filter.
DataSource
Specifies whether the filter is list-based or data-extension-based. If the filter is based on a data extension, supply a DataExtension object. Otherwise, leave this value null and the filter uses profile attributes.
DataFilter
This property specifies the rules associated with the filter. You can include measures here.
DataFilter Valid Values for Specific Data Types
Data Type
Valid Values
Boolean
True or False
Date
ShortDate (date with no time)
List
Not supported
Numeric
Bigint
DataFilter Valid SimpleOperator Types
Data Type
Valid Values
Boolean
Equals
Date
equals
notEquals
isAnniversary
isNotAnniversary
greaterThan
greaterThanAnniversary
lessThan
lessThanAnniversary
List
equals
notEquals
Numeric
equals
notEquals
greaterThan
greaterThanOrEqual
Text
equals
notEquals
greaterThan
greaterThanOrEqual
lessThan
lessThanOrEqual
existsInString
existsInStringAsAWord
notExistsInString
beginsWith
Sample .NET Code to Create a FilterDefinition Object
1DataExtension de = new DataExtension();2de.CustomerKey = "DE_UserSubscription"; // External key of data extension3FilterDefinition fd = new FilterDefinition();4fd.DataSource = de;5fd.Name = "A new Filter Definition";6fd.CustomerKey = "A_new_Filter_Definition";7fd.Description = "A new Filter Definition";8// Set up complex filter parts9ComplexFilterPart cfp = new ComplexFilterPart();10// set up simple filter parts11SimpleFilterPart sfpA = new SimpleFilterPart();12SimpleFilterPart sfpB = new SimpleFilterPart();13SimpleFilterPart sfpC = new SimpleFilterPart();14SimpleFilterPart sfpD = new SimpleFilterPart();15sfpA.Property = "opt_in"; // boolean16sfpA.SimpleOperator = SimpleOperators.equals;17sfpA.Value = new string[] { "true" };1819sfpB.Property = "pub_id"; // number20sfpB.SimpleOperator = SimpleOperators.equals;21sfpB.Value = new string[] { "1" };22sfpC.Property = "pub_type"; // text23sfpC.SimpleOperator = SimpleOperators.equals;24sfpC.Value = new string[] { "A" };25sfpD.Property = "subscribed"; // boolean26sfpD.SimpleOperator = SimpleOperators.equals;27sfpD.Value = new string[] { "true" };28// Joins the rules together29cfp.LeftOperand = sfpA;30cfp.LogicalOperator = LogicalOperators.AND;31cfp.RightOperand = sfpB;32cfp.AdditionalOperands = new FilterPart[2];33cfp.AdditionalOperands[0] = sfpC;34cfp.AdditionalOperands[1] = sfpD;3536// Associate the complex filter with the FilterDefinition37fd.DataFilter = cfp;38// Execute CreateRequest39CreateResult[] results = integrationFramework.Create(null, new APIObject[] { fd }, out requestID, out status);40// Output the Values41Console.WriteLine(status);42Console.WriteLine(requestID);43Console.WriteLine(results.Length);44foreach (CreateResult result in results)45{46 Console.WriteLine(result.ErrorCode);47 Console.WriteLine(result.StatusCode);48 Console.WriteLine(result.StatusMessage);49 Console.WriteLine(result.NewObjectID);50}
This code example creates a filter definition with a complex filter.
Using these criteria, the API performs the call on the test_subject_line data extension:
1// Create Filter2DataExtension fde = new DataExtension();3fde.CustomerKey = "test_subject_line"; // External key of data extension4FilterDefinition fd = new FilterDefinition();5fd.DataSource = fde;6fd.Name = "SUBJECT LINE";7fd.CustomerKey = "SUBJECT_LINE";8fd.Description = "description";9SimpleFilterPart sfpA = new SimpleFilterPart();10sfpA.Property = "test_cell"; // boolean11sfpA.SimpleOperator = SimpleOperators.equals;12sfpA.Value = new string[] {"CELL1"};13SimpleFilterPart sfpC = new SimpleFilterPart();14sfpC.Property = "division_permalink"; // boolean15sfpC.SimpleOperator = SimpleOperators.equals;16sfpC.Value = new string[] { "chicago" };17ComplexFilterPart cfp1 = new ComplexFilterPart();18cfp1.LeftOperand = sfpA;19cfp1.LogicalOperator = LogicalOperators.AND;20cfp1.RightOperand = sfpC;21// SFP for status = active or bounced22SimpleFilterPart sfpB1 = new SimpleFilterPart();23sfpB1.Property = "status"; // boolean24sfpB1.SimpleOperator = SimpleOperators.equals;25sfpB1.Value = new string[] { "active" };26SimpleFilterPart sfpB2 = new SimpleFilterPart();27sfpB2.Property = "status"; // boolean28sfpB2.SimpleOperator = SimpleOperators.equals;29sfpB2.Value = new string[] { "bounced" };30ComplexFilterPart cfp2 = new ComplexFilterPart();31cfp2.LeftOperand = sfpB1;32cfp2.LogicalOperator = LogicalOperators.OR;33cfp2.RightOperand = sfpB2;34ComplexFilterPart cfp3 = new ComplexFilterPart();35cfp3.LeftOperand = cfp1;36cfp3.LogicalOperator = LogicalOperators.AND;37cfp3.RightOperand = cfp2;38fd.DataFilter = cfp3;39// Execute CreateRequest40CreateResult[] results2 = client.Create(null, new APIObject[] { fd }, out requestID2, out status2);41if (status2.Equals("OK"))42{43lblMessage.Text = "Call is : " + status2;44}45else46{47lblMessage.Text = "Error Creating Data Extension: " + results2;48}
Sample .NET Code toUpdate a FilterDefinition Object
The update call supports both CustomerKey and ObjectID as identifiers to specify which FilterDefinition to update. The API requires both the DataExtension and DataFilter to update a FilterDefinition object.
1DataExtension de = new DataExtension();2de.CustomerKey = "DE_UserSubscription"; // External key of data extension3FilterDefinition fd = new FilterDefinition();4fd.DataSource = de;5fd.CustomerKey = "A_new_Filter_Definition"; // Update using customer key6// Simple7ComplexFilterPart cfp = new ComplexFilterPart();8SimpleFilterPart sfpA = new SimpleFilterPart();9SimpleFilterPart sfpB = new SimpleFilterPart();10SimpleFilterPart sfpC = new SimpleFilterPart();11SimpleFilterPart sfpD = new SimpleFilterPart();12sfpA.Property = "opt_in";13sfpA.SimpleOperator = SimpleOperators.equals;14sfpA.Value = new string[] { "true" };15sfpB.Property = "pub_id";16sfpB.SimpleOperator = SimpleOperators.equals;17sfpB.Value = new string[] { "1" };18sfpC.Property = "pub_type";19sfpC.SimpleOperator = SimpleOperators.equals;20sfpC.Value = new string[] { "A" };21sfpD.Property = "subscribed";22sfpD.SimpleOperator = SimpleOperators.equals;23sfpD.Value = new string[] { "true" };24cfp.LeftOperand = sfpA;25cfp.LogicalOperator = LogicalOperators.AND;26cfp.RightOperand = sfpB;27cfp.AdditionalOperands = new FilterPart[2];28cfp.AdditionalOperands[0] = sfpC;29cfp.AdditionalOperands[1] = sfpD;30fd.DataFilter = cfp;31// Execute UpdateRequest32UpdateResult[] results = integrationFramework.Update(null, new APIObject[] { fd }, out requestID, out status);33// Output the Values34Console.WriteLine(status);35Console.WriteLine(requestID);36Console.WriteLine(results.Length);37foreach (UpdateResult result in results)38{39 Console.WriteLine(result.ErrorCode);40}
Sample SOAP Envelope - Create a Filter Definition Using Profile Attributes