-
Notifications
You must be signed in to change notification settings - Fork 22
Description
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
onesignal-node-api/models/ObjectSerializer.ts
Lines 298 to 306 in f40b4bd
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6 | |
let subType: string = type.replace("Array<", ""); // Array<Type> => Type> | |
subType = subType.substring(0, subType.length - 1); // Type> => Type | |
let transformedData: any[] = []; | |
for (let index in data) { | |
let date = data[index]; | |
transformedData.push(ObjectSerializer.serialize(date, subType, format)); | |
} | |
return transformedData; |
filter
property would not only be Array<Filter>
(see onesignal-node-api/models/Notification.ts
Line 400 in f40b4bd
'filters'?: Array<Filter>; |
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
- I agree to follow this project's Code of Conduct