Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting 400 bad request - using fromRaw() method #7

Open
MicahDavid opened this issue May 23, 2024 · 1 comment
Open

getting 400 bad request - using fromRaw() method #7

MicahDavid opened this issue May 23, 2024 · 1 comment

Comments

@MicahDavid
Copy link

I'm having a problem using the fromRaw method, and receiving a 400 bad request response. If I use the standard helper methods, then I get a success response.

I'm assuming my syntax is not correct. Here it is:

            $firebaseMessage = (new FirebaseMessage)
                ->fromRaw([
                            "data" => [],
                            "notification" => [
                                "title" => $this->title,
                                'body' => $this->body,
                            ],
                            "android" => [
                                "ttl" => "86400",
                                'notification' => [
                                    'sound' => 'surf_alert_sound.wav',
                                    'channel_id' => 'surf-alert-channel'
                                ]
                            ],
                            "apns" => [
                                "payload" => [
                                    'aps' => [
                                        'sound' => 'surf-alert_sound.wav',
                                        'badge' => 1
                                    ]
                                ]
                            ],
                            "token" => $this->token,
                        ]
                )->asNotification();

Any suggestions on my syntax issues are appreciated.

@MicahDavid
Copy link
Author

I was able to figure this out. There were 3 issues:

  1. I need to wrap my existing data inside a "message" array. I think this is missing from the Readme example.
  2. I couldn't include an empty "data" array.
  3. the ttl needed an "s" for seconds.

Here's the corrected code:

            $firebaseMessage = (new FirebaseMessage)
                ->fromRaw([
                    'message' => [
                        //"data" => [],
                        "notification" => [
                            "title" => $this->title,
                            'body' => $this->body,
                        ],
                        "android" => [
                            "ttl" => "86400s",
                            'notification' => [
                                'sound' => 'surf_alert_sound.wav',
                                'channel_id' => 'surf-alert-channel'
                            ]
                        ],
                        "apns" => [
                            "payload" => [
                                'aps' => [
                                    'sound' => 'surf-alert_sound.wav',
                                    'badge' => 1
                                ]
                            ]
                        ],
                        "token" => $this->token,
                    ]
                        ]
                )->asNotification();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant