Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Gabotronix's avatar

Error when sending firebase notification to topics with curl and api v1

in my laravel app I'm using curl to send a notification to all users suscribed to a topic, however when I send the notification I get this error:

"code": 400,
"message": "Invalid JSON payload received. Unknown name \"to\": Cannot find field."

This is how I send topic notif with curl:

public function sendTopic($topic,$title,$body, $data , $type, $image='')
    { 
        $client = new Client();
        
        $url = 'https://fcm.googleapis.com/v1/projects/wooloveapp-dda64/messages:send';
       
        $fields = 
        [
            'message' =>  
            [
                "to" => $topic,
                "notification" =>
                [
                    "title" => $title,
                    "body" => $body,
                ],
                "data" =>   [ "data" =>  json_encode($data) ],
                "android" =>
                [
                    "notification" => 
                    [
                        "sound" => "default",
                        "title" => $title,
                        "body" => $body,
                        'tag' => $topic,
                        "channel_id" => "500",
                        
                    ], 
                    "priority" => "high",
                    "ttl" => "86400s"
                    //"badge" => 1
                ],
                "apns" =>
                [
                    "payload" => 
                    [
                        "aps" => [ "sound" => "default" ]
                    ],
                    "headers" => [
                        "apns-priority" => "5",
                        "content_available" => "1"
                    ], 
                ],
                "webpush"=>[
                    "headers"=>[
                      "Urgency"=> "high",
                      //"image" => "https://wooloveapp.com/img/misc/logo-02.jpg"
                    ]
                    ],
            ]
        ];

        $headers = 
        [
            'Authorization: Bearer ' .$this->getGoogleAccessToken(),
            'Accept:application/json',
            'Content-Length:'.strlen(json_encode($fields)),
            'Content-Type:application/json',
        ];


        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

        $result = curl_exec($ch);

        $result =
        [
            'result' => $result,
            //'statusCode' => $statusCode
        ];

        return $result;
    }
0 likes
3 replies
Gabotronix's avatar

@Sinnbeck uhmm, I was but I changed to the new one... did they change the paylaod format again??

Please or to participate in this conversation.