Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Operators not supported in notification filters #62

Open
1 task done
bastiankistner opened this issue Jul 5, 2023 · 2 comments
Open
1 task done

[Bug]: Operators not supported in notification filters #62

bastiankistner opened this issue Jul 5, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@bastiankistner
Copy link

bastiankistner commented Jul 5, 2023

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

} 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;
. Either the filter property would not only be Array<Filter> (see
'filters'?: Array<Filter>;
) 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

  • I agree to follow this project's Code of Conduct
@bastiankistner bastiankistner added the bug Something isn't working label Jul 5, 2023
@Elyytscha
Copy link

I run into the same issue

@nan-li
Copy link
Contributor

nan-li commented May 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants