Mateus Carvalho
Mateus Carvalho

Reputation: 336

Send API notification OneSignal for multiple users

I'm try send a API Notification by OneSignal to API REST, when I send for a unique user it's work right, but when have to more than one user in Json, the notification is sent for unique user yet.

My JSON (listOnesignal):[{"key":"user","relation":"=","value":"YAlBcuwiOJ"},{"key":"user","relation":"=","value":"MSoVMRxzbh"}]    

var jsonBody = { 
                  app_id: "appid", 
                  android_background_data: true,
                  tags: listOneSignal,
                  data: {anything}
    };

Upvotes: 2

Views: 6232

Answers (2)

jkasten
jkasten

Reputation: 3948

You need to add an OR operator between each entry as AND is used by default.

[{"key":"user","relation":"=","value":"YAlBcuwiOJ"},
 {"operator": "OR"},
 {"key":"user","relation":"=","value":"MSoVMRxzbh"}]

Note that there is a limit of 200 entries (including OR's) on the tags field per REST API call. You can use include_player_ids instead if you need to target more devices at a time as you can send up to 2,000.

See the OneSignal create notification REST API documentation page for more details.

Upvotes: 4

Andrew
Andrew

Reputation: 7880

In case someone is using the OneSignal CSharp SDK, this is how you can do the same thing (although this example uses tags instead of player ids):

IList<INotificationFilter> filters = new List<INotificationFilter>();

foreach (var tag in tagList)
{
    var filter = new NotificationFilterField
    {
        Field = NotificationFilterFieldTypeEnum.Tag,
        Key = "tag_id",
        Value = tag,
        Relation = "="
    };

    if (filters.Count > 0)
        filters.Add(new NotificationFilterOperator { Operator = "OR" });

    filters.Add(filter);
}

var client = new OneSignalClient("...");

var options = new NotificationCreateOptions
{
    AppId = new Guid("..."),
    Filters = filters
};

options.Contents.Add(...);
client.Notifications.Create(options);

Upvotes: 2

Related Questions