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]: Cannot use Filter as field always throw null error #21

Open
1 task done
banhawchun opened this issue Dec 15, 2022 · 2 comments
Open
1 task done

[Bug]: Cannot use Filter as field always throw null error #21

banhawchun opened this issue Dec 15, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@banhawchun
Copy link

banhawchun commented Dec 15, 2022

What happened?

I want to send notification base on user tags filter but it seems like i cannot initialize Filter() without it throws null error:

ArgumentNullException: Value cannot be null.
Parameter name: field is a required property for Filter and cannot be null
OneSignalApi.Model.Filter..ctor(string field, string key, string value, RelationEnum relation) in Filter.cs, line 116

Steps to reproduce?

public static async Task<string> testSendAsync()
        {
            appConfig.BasePath = "https://onesignal.com/api/v1";
            appConfig.AccessToken = Authorization;
            var appInstance = new DefaultApi(appConfig);

            var notification = new Notification(appId: AppId)
            {
                Contents = new StringMap(en: "Hello World from .NET!"),
                Headings = new StringMap(en: "Hello"),
                IncludedSegments = new List<string> { "Sale Role" },
                Filters = new List<Filter>
                {
                    new Filter(){ Field = "tag", Key = "Role", Value = "4", Relation = Filter.RelationEnum.Equal}
                },
            };

            var response = await appInstance.CreateNotificationAsync(notification);

            return $"Alert success: {response.Recipients.ToString()}";
        }

What did you expect to happen?

It should not be null when we provide value to "field" already

Code of Conduct

  • I agree to follow this project's Code of Conduct
@banhawchun banhawchun added the bug Something isn't working label Dec 15, 2022
@bnoffer
Copy link

bnoffer commented Feb 13, 2023

Looks like the error is due to the constructor performing a null check. If you use the constructor instead of initializing manually it should work fine.

In addition you can not combine segments and Filters in one notification. You can check the API Reference on that: https://documentation.onesignal.com/reference/create-notification#send-to-users-based-on-filters

@oldmanhd7
Copy link

Hello bro, were you able to solve this? I am having the same problem and I have not been able to solve it, I have had to use IncludePlayerIds which is a function that is depreciated, thanks a lot

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