John Davidson

php - Push notification with pusher beam, unable to send data/payload


I am using following php sdk for generating pusher beam push notification. but there is not information provided in the sdk docs on how to send data/payload along with it. the notification is bean sent correctly but I am unable to send data: please guide me how we can send the data: it is showing hasData as false in beam console, please check:

php sdk i am using :

my code look like this:

$pushNotification = new PushNotifications([
'instanceId' => env('BEAM_INSTANCE_ID'),
'secretKey' => env('BEAM_PRIMARY_KEY')
"apns" => [
"aps" => [
"alert" => "Message Received",
"fcm" => [
"notification" => [
'title' => 'some title',
'body' => 'some body',
'data' => 'some data', //passing data here but not working

My Answer:
> You can send data/payload along with the push notification by including it in the `publish` method of the PushNotifications SDK. Here is an example of how you can send data along with the notification:

$pushNotification = new PushNotifications([
'instanceId' => 'YOUR_INSTANCE_ID',
'secretKey' => 'YOUR_SECRET_KEY',

$data = [
'message' => 'Hello, this is a push notification with data',
'custom_data' => 'Custom data here',

$publishResponse = $pushNotification->publish(
['interests' => ['hello']],
['fcm' => ['notification' => ['title' => 'Hello', 'body' => 'This is a push notification'], 'data' => $data]]


In the above code, the `$data` array contains the data that you want to send along with the notification. You can include any custom data that you want to send. The `publish` method takes two parameters: the interests to which the notification should be sent and the notification data. In the notification data, you can include the title, body, and the data array.

Make sure to replace `'YOUR_INSTANCE_ID'` and `'YOUR_SECRET_KEY'` with your actual Pusher Beam instance ID and secret key.

After sending the notification, you should see the data in the Pusher Beam console under the notification details.

Rate this post

3 of 5 based on 2214 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us