How to Create Public Notifications Using Notific.io’s PHP SDK
The Notific.io PHP SDK facilitates interaction with the service’s API. Here’s a look at how you can go about setting up the SDK to make the most of our push and email notifications for your app or website.
Integrating Notific.io Notifications With Your Website
Let’s first get a quick refresher on how to get Notific.io working on your website. All you need to do is paste the following piece of code in the body of each HTML page:
Adding that line loads Notific.io with its default user interface and the ability to deliver notifications in real-time.
Installing The Notific.io PHP SDK
The PHP SDK makes it extremely simple to interact with the Notific.io API. To get started using the PHP SDK, install Notific’s composer package.
$ composer require notific/notific-php-sdk
The next thing you need to do is create an instance of the SDK using the following line of code.
$notific = new Notific\PhpSdk\Notific(APP_ID, API_TOKEN);
The APP_ID parameter refers to the unique app ID you are assigned once you sign up here.
Creating Public Notifications with Notific.io
So now you have the PHP SDK set up and you’re ready to start playing around with the Notific API. The first thing you will likely want to do is create a public notification, which is one that is sent out to all your users. The most basic parameters you will pass as part of creating any notification are its body and title. The following code creates a notification alerting users about a seasonal discount on your product.
$notific->createPublicNotification([ 'title' => 'Christmas Is Here!' 'body' => 'And we're feeling generous. Premium subscriptions are 10% off all December. Enjoy!' ]);
As you can see, it’s really easy to create a notification that goes out to all users. You can get more detailed with the messaging by adding more parameters to the function that creates the notification. Going back to the example we mentioned, you might want to lead users to a page on which they can redeem the discount. You can use the URL parameter for that.
$notific->createPublicNotification([ 'title' => 'Christmas Is Here!' 'body' => 'And we're feeling generous. Premium subscriptions are 10% off all December. Enjoy!' 'url' => 'mywebsite.com/christmas-discount' ]);
And there you go. You just created a notification that will get out to all your customers, getting your promotional offer the attention it needs.
You can use various other parameters to get more sophisticated about the content and behavior of notifications. Sticking with the Christmas discounts example, you can add a parameter that automatically deactivates the notification once the season has passed.
$notific->createPublicNotification([ 'title' => 'Christmas Is Here!' ‘body’ => ‘And we're feeling generous. Premium subscriptions are 10% off all December. Enjoy!’ ‘active_till’ => ‘2019-01-01’ ]);