Filter by respondent attributes
Filter responses by respondent attributes and return attributes with each response.
When listing responses, you can filter by the user attributes you passed to PollHero via identify(), and have these attributes returned.
Return attributes
With attributes[], you define which attributes come back in respondent.attributes, at most 50:
curl -G "https://app.poll-hero.com/api/v1/surveys/{survey_id}/responses" \
-H "Authorization: Bearer ph_xxxxxxxx" \
--data-urlencode "attributes[]=email" \
--data-urlencode "attributes[]=customer_type""respondent": {
"id": "b1f4c2d0-7a35-4c1e-8f7b-2f6f0e1f9a44",
"attributes": [
{ "name": "email", "value": "customer@example.com" },
{ "name": "customer_type", "value": "new" }
]
}- Values are always strings, for example
"true"or"1249.99". - Empty attributes are left out.
- Attributes you filter on are returned automatically.
Filters
A filter has the form filter[<attribute>][<operator>]=<value>:
| Example | Meaning |
|---|---|
filter[customer_type]=new | short form of [eq] |
filter[total_purchases][gte]=3 | at least 3 purchases |
filter[has_subscription][eq]=true | custom attribute |
filter[country][in]=DE,AT,CH | one of the values |
filter[email][exists]=false | without email address |
filter[plan->name]=pro | nested custom attribute |
- Several filters are combined with AND. At most 10 conditions per request.
filter[x][gte]=1&filter[x][lte]=5counts as two. - Negative operators (
ne,not_contains,exists=false) also match respondents that were never identified. filter[country]filters by thecountryattribute fromidentify(), not by the country of the response.
Attribute names
| Kind | Names |
|---|---|
| Fixed attributes | email, customer_id, customer_type, total_revenue, total_purchases, total_aov, country, language |
| Custom attributes | Keys of the data you pass to identify(). Separate nested keys with ->, e.g. plan->name. |
Operators
| Operator | Meaning |
|---|---|
eq | equal (default when no operator is given) |
ne | not equal |
contains | contains the text |
not_contains | does not contain the text |
in | one of the values, separated by commas |
gt, gte | greater than, greater than or equal |
lt, lte | less than, less than or equal |
exists | true: the attribute is set. false: the attribute is missing. |
For custom attributes, true and false are compared as boolean values and numbers as numbers. Fixed text attributes such as email or country are compared as text.
Pages with filters
With attribute filters, the API checks only a limited number of responses per request. A page can therefore hold fewer records than requested, or none at all, although there are more matches. Only links.next counts: keep paging as long as it is not null.