berkayk / laravel-onesignal

OneSignal Push Notifications for Laravel
506 stars 176 forks source link

Client error: `POST https://onesignal.com/api/v1/notifications` resulted in a `400 Bad Request` response: {"errors":["Segment user_id is not a valid filter field.","Segment device_id is not a valid filter field."]} #90

Open ijazbhatti007 opened 6 years ago

ijazbhatti007 commented 6 years ago

Client error: POST https://onesignal.com/api/v1/notifications resulted in a 400 Bad Request response: {"errors":["Segment user_id is not a valid filter field.","Segment device_id is not a valid filter field."]} I am trying to send using tags

samundra commented 6 years ago

@ijazbhatti007

When you are making calls to send notification using the tags what library does is it translates your tags calls to filter calls which onesignal expects for tags.

The error you have likely could have been due to the incorrect payload and not because of the library itself. To have more information on the filters see onesignal's REST API documentation https://documentation.onesignal.com/reference#section-filter-usage

Also, Can you provide us the sample code block that you are using to send using tags?

That way we'll be able to help you more and guide further.

rebirthtobi commented 6 years ago

@ijazbhatti007 your array should be

array ( {"field": "tag", "key": "is_vip", "relation": "!=", "value": "true"} )

@samundra when sendNotificationUsingTags i think we don't need to specify the filed: tag again

samundra commented 6 years ago

@ijazbhatti007 We have to be very specific and have to specify the field: tag ourselves.

If you look at https://github.com/berkayk/laravel-onesignal/blob/master/src/OneSignalClient.php#L182-L186 it simply adds anything that comes as $filters to filters key.

gelinger777 commented 5 years ago

So right answer is

 OneSignal::sendNotificationUsingTags(
            "Hi There, please check our new website update.",
            array(
                ["field"=>"tag","key" => "yourTagHere", "relation" => "=", "value" => "yourValueHere"]

               ),
            $url = 'https://google.com',
           $data = null,
           $buttons = null,
             $schedule = null
    );