Other than scheduling and sending push notification from our dashboard, you can also connect to our API to schedule push notifications for your users.
Submit request to the following URL together with the required details
https://centrecbiz.com/push_notification.php?rest_api_key=your-api-key
your-api-key: Get your unique API key in your account dashboard (My Account) after subscribing our Web to App package. You need to keep your subscription active in order to use the API key.
Required details in JSON format
- recipients: It’s an array containing multiple recipient details including device_uuid, device_token, user, category. You may refer to example at the bottom of the list.
- schedule: Date and time to send out the push notification. Timezone offset should be in UTC+0. Desired date and time format is Y-m-d H:i:s.
- title: Your push notification title.
- content: Your push notification content.
- url: The web app page you would like to redirect your users to when user clicks on the notification.
Below is an example using PHP cURL to perform the request
$ch = curl_init();
$curlConfig = array(
CURLOPT_URL => "https://centrecbiz.com/push_notification.php?rest_api_key=your-api-key",
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode(array(
'recipients' => array(
array( "user" => "123", "category" => "user", "device_uuid" => "aaa", "device_token" => "bbb" ),
array( "user" => "456", "category" => "user", "device_uuid" => "ccc", "device_token" => "ddd" ),
array( "user" => "789", "category" => "vendor", "device_uuid" => "eee", "device_token" => "fff" ),
),
'schedule' => '2023-06-23 08:00:00',
'title' => 'Test title',
'content' => 'Test content',
'url' => 'https://google.com',
))
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
Below is an example of recipients array in JSON format
[
{"user": "123", "category": "user", "device_uuid": "aaa", "device_token": "bbb"},
{"user": "456", "category": "user", "device_uuid": "ccc", "device_token": "ddd"},
{"user": "789", "category": "vendor", "device_uuid": "eee", "device_token": "fff"}
]
Sample Return Results
{"code":"1","msg":"Success!","not_subscribed":[{"device_uuid":"aaa","device_token":"bbb","user":"123","category":"user"},{"device_uuid":"ccc","device_token":"ddd","user":"456","category":"vendor"}]}
In the above returned results, it means that the push notification is successfully scheduled for the devices in the recipients array that has been subscribed to the system. For those devices in the recipients array that are not subscribed to the system will be listed in the response data and the push notification scheduled will not be sent to these devices. NOTE, if all devices in the recipients array are not subscribed to the system, the request will fail with code 0.
- code: 1 indicates request success while 0 indicates request failed.
- msg: Specify success or the reason of failure.
- not_subscribed: Return the devices list that are not subscribed to the system. You are not able to schedule push notifications for devices that are not subscribed to the system. Click Here to learn more about how to subscribe device to the system.