laravel-onesignal icon indicating copy to clipboard operation
laravel-onesignal copied to clipboard

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."]}

Open ijazbhatti007 opened this issue 6 years ago • 4 comments

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

ijazbhatti007 avatar Oct 08 '18 07:10 ijazbhatti007

@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.

samundra avatar Oct 08 '18 18:10 samundra

@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

rebirthtobi avatar Nov 21 '18 11:11 rebirthtobi

@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.

samundra avatar Nov 21 '18 14:11 samundra

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
   );

gelinger777 avatar Sep 06 '19 21:09 gelinger777