Search code examples
phphttponesignal

Onesignal : included_segments must be an array of strings


I want to send push notification via API on PHP project.

This is the basic code that I use

$client = new GuzzleHttp\Client([
            'base_uri' => 'https://onesignal.com/api/v1/',
            'headers' => [
                'Authorization'=> 'Basic '. config('onesignal.rest_api_key'),
                'Content-Type' => 'application/json'
             ]]);

$response = $client->post('notifications', [
                    'form_params'=>[
                        'app_id' => config('onesignal.app_id'),
                        'included_segments' => ['All'],
                        'contents' => ["en"=> "Un nouveau cas de suspect vient d'être confirmé à Kinshasa"]
                    ]]) ;

When I execute it, $response->getBody()->getContents() return this

{"errors":["included_segments must be an array of strings"]}

I don't know What is mean by Array of string


Solution

  • So stupid that this can be, the problem was resolved by using an other HTTP client library than Guzzle.

    I don't know why but I've used https://github.com/php-curl-class/php-curl-class and with the same logique, I resolved my problem !

    Hope that it'll help someone !