onesignal-node-api
onesignal-node-api copied to clipboard
[Bug]: Operators not supported in notification filters
What happened?
When trying to add filters to a notification but not only with Filter
instances but also with Operator
instances, the serialization process first turns all values of the Operator
into undefined
and the resulting payload will then carry an emtpy object {}
.
[
{
"field": "tag",
"key": "value",
"relation": "=",
"value": "value"
},
{
"field": undefined,
"key": undefined,
"relation": undefined,
"value": undefined
},
{
"field": "tag",
"key": "value",
"relation": "=",
"value": "value"
}
]
The issues seems to be that internally the filter property of a Notification
is set to be of type Array<Filter>
. The ObjectSerializer therefore ignores the operator: "OR"
as it's not a field of Filter
. As a result, the request fails because of a BadRequest
error with Body: {"errors":["Segment is not a valid filter field."]}
.
The serialization happens here https://github.com/OneSignal/onesignal-node-api/blob/f40b4bdac714efb3d7139ee3ba9d8b17cfc14987/models/ObjectSerializer.ts#L298-L306 . Either the filter
property would not only be Array<Filter>
(see https://github.com/OneSignal/onesignal-node-api/blob/f40b4bdac714efb3d7139ee3ba9d8b17cfc14987/models/Notification.ts#L400) but instead Array<Filter|Operator>
and that would properly be parsed. Or you just allow objects to be passed without serializing them through the ObjectSerializer.
In the Go SDK, this case seems to be handled as expected: https://github.com/OneSignal/onesignal-go-api/blob/a573325af1d37a1c7dc8bad8d78fdd33fbfcaf38/model_filter_expressions.go#L27-L54
Also the NodeJS SDK docs state that it should be possible to pass { operator: "OR"}
.
Steps to reproduce?
1. create a new notification
2. set `filter` to an array of [Filter, Operator, Filter] instances
3. send the notification
What did you expect to happen?
The notification should be sent and the filter fields in the OneSignal dashboard should show that the notification was sent with three filters, the second being the "OR" operator.
Relevant log output
No response
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
I run into the same issue
Hi @bastiankistner and @Elyytscha thanks for reporting and for your patience.
We recently released an alpha version of our latest user model API: Release 5.0.0-alpha-01 that addresses this and other issues.
Please read the release description for how to get started, and we appreciate any early feedback on this release.