More then two filters in OneSignal create Notification

Viewed 64

I'm using filters in create notifications with onesignal. I want to use 3 or more filters at a time but one filter must match and others can be optional. Read the docs but can't find option like this.

What I want?

Let say I have following 3 filters

  • country
  • language
  • tag ( having key type and value 'premium' )

I want to send notification to users only from US, either having language english or type premium.

What I tried?

[
 {field: "country", relation: "=", value: "US"},
 {operator: "AND"}, 
 {field: "language", relation: "=", value: "en"},
 {operator: "OR"}, 
 {field: "tag", key: "type", relation: "=", value: "premium"}
]

this is not working as expected.

1 Answers

After talking to support, I found we need to AND required filter with every other filter that is optional. Using above example from question which is:

Let say I have following 3 filters:

  • Country
  • Language
  • Tag ( having key type and value 'premium' )

If I want to send notification to users only from US, either having language english or type premium. I have to AND country with Language and Tag filter.

So my filter's array will look like this:

[
 {field: "language", relation: "=", value: "en"},
 {operator: "AND"}, 
 {field: "country", relation: "=", value: "US"},
 {operator: "OR"}, 
 {field: "tag", key: "type", relation: "=", value: "premium"}
 {operator: "AND"}, 
 {field: "country", relation: "=", value: "US"},
]

Note: According to docs, only 200 filters are allowed including operators

Related