Filtering options for contacts

The contacts query supports an extensive selection of filters to help you identify high-value customers, find contacts due for re-engagement, generate compliance reports, export contact data to external platforms and more.

These filters use the ContactRule input type.

query FilterContacts($email: JSON!, $minScore: Float!) {
  contacts(filter: [
    { field: "Email Address", eq: $email }
    { field: "Score",         gt: $minScore }
  ]) {
    nodes {
      attributes(selectByName: ["Email Address", "Score"]) {
        name
        value
      }
    }
  }
}

For example, you can identify contacts who are between 46 and 54 years old and live in Ontario, Canada.

query {
  contacts(
    filter: [
      {
        and: [
          {
            field: "Birthday"
            between: {
              from: "1971-01-01T00:00:00.000Z"
              to: "1979-01-01T00:00:00.000Z"
            }
          }
          { field: "City", eq: "Ontario" }
        ]
      }
    ]
  ) {
    nodes {
      attributes(selectByName: ["First name", "Email", "Birthday"]) {
        name
        value
      }
    }
    totalCount
  }
}

Complete reference

Each filter object in the contacts query can contain:

  • field (required): String - The name of the contact attribute to filter by. If you don't have the names of all available contact attributes, see Query the audience.

Many operators support a negated form by prefixing with n (for example, neq negates eq). Several date operators are relative to today rather than a fixed value.

📘

The JSON scalar

The value field accepts any JSON value — string, number, boolean, array, or object. Declare variables as JSON!, not String!. This applies to the eq, neq, in, and nin operators only — other operators use their own specific types (see the Value type column below).

query FindContact($emailValue: JSON!) {
  contacts(filter: [{ field: "Email Address", eq: $emailValue }]) {
    nodes {
      attributes(selectByName: ["Email Address"]) {
        name
        value
      }
    }  
  }
}

Declaring String! causes the error: Variable "$emailValue" of type "String!" used in position expecting type "JSON". The value itself does not change — a JSON string is already valid JSON.

OperatorValue typeDescription
eqJSONFilter for exact matches
neqJSONFilter for values not equal to this value
in[JSON!]Is in the list of values
nin[JSON!]Is not in the list of values
containsStringFilter for values containing this text
ncontainsStringFilter for values not containing this text
startsWithStringFilter for values starting with this text
nstartsWithStringFilter for values not starting with this text
endsWithStringFilter for values ending with this text
nendsWithStringFilter for values not ending with this text
afterStringIs after a given date (RFC 3339 format)
beforeStringFilter for dates before this value (RFC 3339 format)
containsOneOf[String!]Filter for values containing any of these texts
ncontainsOneOf[String!]Filter for values not containing any of these texts
startsWithOneOf[String!]Filter for values starting with any of these texts
nstartsWithOneOf[String!]Filter for values not starting with any of these texts
endsWithOneOf[String!]Filter for values ending with any of these texts
nendsWithOneOf[String!]Filter for values not ending with any of these texts
eqOneOf[String!]Filter for values matching any of these options
neqOneOf[String!]Filter for values not matching any of these options
ltFloatIs less than
lteFloatIs less than or equal to
gtFloatIs greater than
gteFloatIs greater than or equal to
yearFloatIs in the given year
monthFloatIs in the given month (1-12)
dayFloatIs in the given day (1-31)
blankBooleanFilter for empty/non-empty values
isTodayBooleanFilter for dates matching today
isAfterTodayBooleanFilter for dates after today
isBeforeTodayBooleanFilter for dates before today
isAnniversaryTodayBooleanFilter for yearly anniversaries occurring today
arrayEmptyBooleanFilter for empty/non-empty array values
betweenValueRangeInputFilter for values within a range
anniversaryValueWithinInputFilter for anniversary exactly the provided number of days/weeks/months ago
exactlyValueWithinInputFilter for dates exactly the provided number of days/weeks/months ago/away
nexactlyValueWithinInputFilter for dates not exactly the provided number of days/weeks/months ago
withinLastValueWithinInputFilter for dates within the provided number of last days/weeks/months
nwithinLastValueWithinInputFilter for dates not within the provided number of last days/weeks/months
withinNextValueWithinInputFilter for dates within the provided number of next days/weeks/months
nwithinNextValueWithinInputFilter for dates not within the provided number of next days/weeks/months
withinLastRangeDateValueRangeInputFilter for dates within the provided range of last days/weeks/months
and[ContactRule!]Combine multiple conditions with AND logic
or[ContactRule!]Combine multiple conditions with OR logic
count[ContactRule!]Filter based on the count of matching sub-conditions
notContactRuleNegate a condition

Examples

Find corporate contacts using selected domains

filter: [
      {
        or: [
          { field: "Email", endsWith: "@company.com" }
          { field: "Email", endsWith: "@enterprise.com" }
          { field: "Email", endsWith: "@corp.net" }
        ]
      }
    ]

Find contacts without email addresses

filter: [
  { 
    field: "Email"
    blank: true 
  }
]

Find contacts who were born in January

filter: [
  { 
    field: "Birthday"
    month: 1 
  }
]

Related pages

Query contacts