How to send notifications from API?

You can send notifications from your applications using the Campaigns API.

Campaigns API

  • Usage: Campaigns API enables you to programmatically send notifications to users. You can send either to a specific user or to every subscriber from the API.
  • URL : https://api.engagespot.co/2/campaigns
  • Method : POST
  • Inputs :
      • Headers :
        • Api-Key - your api key (found in website settings page)
        • Content-Type - value set to 'application/json'
      • Body :
            • campaign_name - your campaign name
            • notification object - JSON object holding notification message

 

eg:

"notification" : { "title":"My sample notification, "message" : "The notification message goes here.", "icon":"http://my_url.com/icon.jpg", "url":"http://target_url.com" }

 
            • send_to: specify target users
                    • identifiers - for sending to specific users
                    • everyone - for sending to all subscribers
            • identifiers : (optional ) specify the identifier of the user.

 

      • Output: status and message.

 

1. Sending notifications to specific users (by identifier) :

You can send a notification to specific users by specifying the identifiers.

Eg: here is the sample PHP curl code,

 

<?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"https://api.engagespot.co/2/campaigns"); curl_setopt($ch, CURLOPT_POST, 1); $vars = '{"campaign_name":"Test APi Campaign","notification":{"title":"test case","message":"Hello message","icon":"http://engagespot.co/blog/wp-content/uploads/2017/02/wpengage.jpg","url":"http://google.com"},"send_to":"identifiers","identifiers":["identifier_1","identifier_2"]}'; curl_setopt($ch, CURLOPT_POSTFIELDS,$vars); //Post Fields curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $headers = [ 'Api-Key: xxxxxxxxxxxxxxxxxxxx', 'Content-Type: application/json' ]; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $server_output = curl_exec ($ch); curl_close ($ch); print $server_output ; ?>

2. Sending notifications to specific users (by user hash)

You can send a notification to specific users by specifying the user hashes.

Eg: here is the sample PHP curl code,

 

<?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"https://api.engagespot.co/2/campaigns"); curl_setopt($ch, CURLOPT_POST, 1); $vars = '{"campaign_name":"Test APi Campaign","notification":{"title":"test case","message":"Hello message","icon":"http://engagespot.co/blog/wp-content/uploads/2017/02/wpengage.jpg","url":"http://google.com"},"send_to":"new_segment","user_hashes":["xxxxxxxxxxx","xxxxxxxxxxx"]}'; curl_setopt($ch, CURLOPT_POSTFIELDS,$vars); //Post Fields curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $headers = [ 'Api-Key: xxxxxxxxxxxxxxxxxxxx', 'Content-Type: application/json' ]; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $server_output = curl_exec ($ch); curl_close ($ch); print $server_output ; ?>
 
You can access the user hashes from the cookie with the key '_webPushUserHash'.
3. Sending notifications to all subscribers (and online users)
You can send notifications programmatically to everyone.
Eg: here is the sample PHP curl code,
 
<?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"https://api.engagespot.co/2/campaigns"); curl_setopt($ch, CURLOPT_POST, 1); $vars = '{"campaign_name":"Sample Campaign","notification":{"title":"My Notification","message":"Notification Body","icon":"http://engagespot.co/blog/wp-content/uploads/2017/02/wpengage.jpg","url":"http://sample_url.com"},"send_to":"everyone"}'; curl_setopt($ch, CURLOPT_POSTFIELDS,$vars); //Post Fields curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $headers = [ 'Api-Key: xxxxxxxxxxxxxxxxxxxx', 'Content-Type: application/json' ]; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $server_output = curl_exec ($ch); curl_close ($ch); print $server_output ; ?>
 
 
 
 
 

 

 

 


Did this help answer your question?

thumbs up
thumbs down

Thanks for the feedback! 🙏🏽


Help by drift