Use Complex Filter Parts

ComplexFilterParts and SimpleFilterParts can be nested together to produce sophisticated filtering scenarios.

Sample .NET Code 

The sample code below shows how to create this nesting scenario.

This code represents the following business logic:

  • Retrieve all subscribers

    • (Where the Subscriber’s SubscriberKey property is IN (or one of) the string values “1”, “2”, or “8” OR
    • Where the Subscriber’s SubscriberKey property is IN (or one of) the string values “3”, “6”, or “12”) AND
    • Where the Subscriber’s Status property equals Active

The object structure of this business logic is:

  • ComplexFilterPart

  • ((SubscriberKey in”1”, “2”, or “8” OR SubscriberKey in”3”, “6”, or “12”) AND (Status = Active))

  • ComplexFilterPart ((SubscriberKey in “1”, “2”, or “8”) or(SubscriberKey in”3”, “6”, or “12”))

    • SimpleFilterPart (SubscriberKey in”1”, “2”, or “8”)
    • OR
    • SimpleFilterPart (SubscriberKey in”3”, “6”, or “12”)
  • AND

  • SimpleFilterPart (Status = Active)

1SimpleFilterPart sfp1 = new SimpleFilterPart();
2            sfp1.Property = "SubscriberKey";
3            sfp1.SimpleOperator = SimpleOperators.IN;
4            sfp1.Value = new String[] { "1", "2", "8" };
5            SimpleFilterPart sfp2 = new SimpleFilterPart();
6            sfp2.Property = "SubscriberKey";
7            sfp2.SimpleOperator = SimpleOperators.IN;
8            sfp2.Value = new String[] { "3", "6", "12" };
9            ComplexFilterPart cfp1 = new ComplexFilterPart();
10            cfp1.LeftOperand = sfp1; // Simple Filter
11            cfp1.LogicalOperator = LogicalOperators.OR;
12            cfp1.RightOperand = sfp2; // Simple Filter
13            SimpleFilterPart sfp3 = new SimpleFilterPart();
14            sfp3.Property = "Status";
15            sfp3.SimpleOperator = SimpleOperators.equals;
16            sfp3.Value = new string[] { SubscriberStatus.Active };
17            ComplexFilterPart cfp2 = new ComplexFilterPart();
18            cfp2.LeftOperand = cfp1; // Complex Filter
19            cfp2.LogicalOperator = LogicalOperators.AND;
20            cfp2.RightOperand = sfp3; // Simple Filter

Sample SOAP Envelope 

The sample code below retrieves all active subscribers created after the specified date:

1<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2   <soapenv:Header>
3      <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
4         <wsse:UsernameToken wsu:Id="UsernameToken-32259181" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
5            <wsse:Username>XXXXX</wsse:Username>
6            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">XXXXX</wsse:Password>
7         </wsse:UsernameToken>
8      </wsse:Security>
9   </soapenv:Header>
10   <soapenv:Body>
11      <RetrieveRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
12         <RetrieveRequest>
13            <ObjectType>Subscriber</ObjectType>
14            <Properties>ID</Properties>
15            <Properties>CreatedDate</Properties>
16            <Properties>Client.ID</Properties>
17            <Properties>EmailAddress</Properties>
18            <Properties>SubscriberKey</Properties>
19            <Properties>Status</Properties>
20            <Properties>UnsubscribedDate</Properties>
21            <Properties>EmailTypePreference</Properties>
22            <Filter xsi:type="par:ComplexFilterPart" xmlns:par="http://exacttarget.com/wsdl/partnerAPI">
23               <LeftOperand xsi:type="par:SimpleFilterPart">
24                  <Property>Status</Property>
25                  <SimpleOperator>equals</SimpleOperator>
26                  <Value>Active</Value>
27               </LeftOperand>
28               <LogicalOperator>AND</LogicalOperator>
29               <RightOperand xsi:type="par:SimpleFilterPart">
30                  <Property>CreatedDate</Property>
31                  <SimpleOperator>greaterThan</SimpleOperator>
32                  <DateValue>2010-11-15T11:25:54.617-07:00</DateValue>
33               </RightOperand>
34            </Filter>
35         </RetrieveRequest>
36      </RetrieveRequestMsg>
37   </soapenv:Body>
38</soapenv:Envelope>