Draft Push#

Getting Started#

Introduction

This endpoint is used to create new notifications and can be saved as draft in PushEngage. The request method of this call needs to be a "POST". The title, message, URL and other option of the notification have to be drafted as POST parameters to the API endpoint.

Request URL

https://api.pushengage.com/apiv1/notifications

Method

POST

Request Parameters

Required Parameters

Parameter Name Parameter Type Description
notification_title String Title of the push notification.
notification_message String The message to be displayed in the push notification.
notification_url String URL to open upon clicking on the push notification.

Optional Parameters

Parameter Name Parameter Type Description
image_url String Image to be displayed in the Push Notification.
profile_id Array of String A profile id is unique for a customer in your database. Notifications will be sent to only those devices have this profile id.
include_segments Array of String Include_segments accepts value of array of segment_id. Notifications will be sent to only those subscribers which are subscribed in this segment.
include_countries Array of String include_countries accepts value as array of country. Notifications will be sent to only those subscribers, which are subscribed from these countries.
include_states Array of String include_states accepts value as array of state. Notifications will be sent to only those subscribers, which are subscribed from these states.
include_cities Array of String include_cities accepts value as array of city. Notifications will be sent to only those subscribers, which are subscribed from these cities.
include_device_types Array of String include_device_types accepts value as array of device. Notifications will be sent to only those subscribers, which are subscribed from these devices.
include_browsers Array of String include_browsers accepts value as array of browser. Notifications will be sent to only those subscribers, which are subscribed from these browsers.
require_interaction Number This defines the notification duration on browsers.
notification_expiry Number This is the expiry time for a notification. The maximum value is 28 days.
subscriber_hash String A subscriber hash is unique for a subscriber in our database. Notifications will be sent to only the device having this subscriber hash.
notification_type String This defines the notification status, such as now, later or, draft. In this case, notification_type has always been "draft".

Response Objects

Required Object

Property Name Property Type Description
success Boolean To denote whether push request succeeded or not. Values can be 'true' or 'false'.
Notification_id Number To denote unique id of notification.

Optional Object

Property Name Property Type Description
message String Present in case of failure. Used to denote reason of failure.

Draft Sample Push#

This push notification requires these parameters; notification_title, notification_message, notification_url and notification_type. The title should not exceed 45 characters, message should not exceed 73 characters, URLs should be W3C formatted and notification_type value should be "draft".

Example#

Request

  • cURL
  • PHP
curl -X POST
-H "api_key: <your_pushengage_api_key>"
-H "Content-Type: application/x-www-form-urlencoded"
-d 'notification_title=this is title of notification&notification_message=this is message of notification&notification_url=http://www.example.com&notification_type=draft'
"https://api.pushengage.com/apiv1/notifications"
<?php

    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://api.pushengage.com/apiv1/notifications",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => "notification_title=this is title of notification&notification_message=this is message of notification&notification_url=http://www.example.com&notification_type=draft",
      CURLOPT_HTTPHEADER => array(
        "api_key: <your_pushengage_api_key>",
        "cache-control: no-cache",
        "content-type: application/x-www-form-urlencoded"
      ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }
?>

Response

  • 200 OK
  • 401 Unauthorized
  • 400 Bad Request
  • 400 Bad Request
  • 400 Bad Request
  • 500 Internal Server Error
{
  "success": true,
  "notification_id": 1234567
}
{
  "success": false,
  "message": "API KEY Invalid"
}
{
  "message": "The Title field is required.",
  "success": false
}
{
  "message": "The Message field is required.",
  "success": false
}
{
  "message": "The URL field is required.",
  "success": false
}
{
  "success": false,
  "message": "sending notification failed"
}

Draft Push with Image#

Push with a custom notification image. This image replaces your site logo in the notifications. For this push notification the required parameters are; notification_title, notification_message, notification_url, notification_type and image_url.

Example#

Request

  • cURL
  • PHP
curl -X POST
-H "api_key: <your_pushengage_api_key>"
-H "Content-Type: application/x-www-form-urlencoded"
-d 'notification_title=this is title of notification&notification_message=this is message of notification&notification_url=http://www.example.com&notification_type=draft&image_url=your_image_path/image.png'
"https://api.pushengage.com/apiv1/notifications"
<?php

    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://api.pushengage.com/apiv1/notifications",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => "notification_title=this is title of notification&notification_message=this is message of notification&notification_url=http://www.example.com&notification_type=draft&image_url=your_image_path/image.png",
      CURLOPT_HTTPHEADER => array(
        "api_key: <your_pushengage_api_key>",
        "cache-control: no-cache",
        "content-type: application/x-www-form-urlencoded"
      ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }
?>

Response

  • 200 OK
  • 401 Unauthorized
  • 400 Bad Request
  • 400 Bad Request
  • 400 Bad Request
  • 500 Internal Server Error
{
  "success": true,
  "notification_id": 12345670
}
{
  "success": false,
  "message": "API KEY Invalid"
}
{
  "message": "The Title field is required.",
  "success": false
}
{
  "message": "The Message field is required.",
  "success": false
}
{
  "message": "The URL field is required.",
  "success": false
}
{
  "success": false,
  "message": "sending notification failed"
}

Draft Push with Profile Id#

Notifications will be sent to only those devices which has this profile id. For this push notification the required parameters are; notification_title, notification_message, notification_url, notification_type and profile_id.

Example#

Request

  • cURL
  • PHP
curl -X POST
-H "api_key: <your_pushengage_api_key>"
-H "Content-Type: application/x-www-form-urlencoded"
-d 'notification_title=this is title of notification&notification_message=this is message of notification&notification_url=http://www.example.com&notification_type=draft&profile_id[0]=<profile_id>&profile_id[1]=<profile_id>'
"https://api.pushengage.com/apiv1/notifications"
<?php

    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://api.pushengage.com/apiv1/notifications",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => "notification_title=this is title of notification&notification_message=this is message of notification&notification_url=http://www.example.com&notification_type=draft&profile_id[0]=<profile_id>&profile_id[1]=<profile_id>",
      CURLOPT_HTTPHEADER => array(
        "api_key: <your_pushengage_api_key>",
        "cache-control: no-cache",
        "content-type: application/x-www-form-urlencoded"
      ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }
?>

Response

  • 200 OK
  • 401 Unauthorized
  • 400 Bad Request
  • 400 Bad Request
  • 400 Bad Request
  • 400 Bad Request
  • 500 Internal Server Error
{
  "success": true,
  "notification_id": 12345671
}
{
  "success": false,
  "message": "API KEY Invalid"
}
{
  "message": "The Title field is required.",
  "success": false
}
{
  "message": "The Message field is required.",
  "success": false
}
{
  "message": "The URL field is required.",
  "success": false
}
{
  "success": false,
  "message": "No Subcribers Found for the given profile_id"
}
{
  "success": false,
  "message": "sending notification failed"
}

Draft Push with Segment#

Notifications will be sent to only those subscribers which are subscribed to this segment. For this push notification the required parameters are; notification_title, notification_message, notification_url, notification_type and include_segments.

Example#

Request

  • cURL
  • PHP
curl -X POST
-H "api_key: <your_pushengage_api_key>"
-H "Content-Type: application/x-www-form-urlencoded"
-d 'notification_title=this is title of notification&notification_message=this is message of notification&notification_url=http://www.example.com&notification_type=draft&include_segments[0]=123456'
"https://api.pushengage.com/apiv1/notifications"
<?php

    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://api.pushengage.com/apiv1/notifications",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => "notification_title=this is title of notification&notification_message=this is message of notification&notification_url=http://www.example.com&notification_type=draft&include_segments[0]=123456",
      CURLOPT_HTTPHEADER => array(
        "api_key: <your_pushengage_api_key>",
        "cache-control: no-cache",
        "content-type: application/x-www-form-urlencoded"
      ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }
?>

Response

  • 200 OK
  • 401 Unauthorized
  • 400 Bad Request
  • 400 Bad Request
  • 400 Bad Request
  • 500 Internal Server Error
{
  "success": true,
  "notification_id": 12345672
}
{
  "success": false,
  "message": "API KEY Invalid"
}
{
  "message": "The Title field is required.",
  "success": false
}
{
  "message": "The Message field is required.",
  "success": false
}
{
  "message": "The URL field is required.",
  "success": false
}
{
  "success": false,
  "message": "sending notification failed"
}

Draft Push with Geo segmentation#

Notifications will be sent to only those subscribers which are subscribed from these geos. For this push notification the required parameters are -

  • notification_title
  • notification_message
  • notification_url
  • include_countries
  • include_states
  • include_cities

Example#

Request

  • cURL
  • PHP
curl -X POST
-H "api_key: <your_pushengage_api_key>"
-H "Content-Type: application/x-www-form-urlencoded"
-d 'notification_title=this is title of notification&notification_message=this is message of notification&notification_url=http://www.example.com&include_countries[0]=countryname&include_states[0]=statename&include_cities[0]=cityname'
"https://api.pushengage.com/apiv1/notifications"
<?php

    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://api.pushengage.com/apiv1/notifications",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => "notification_title=this is title of notification&notification_message=this is message of notification&notification_url=http://www.example.com&include_countries[0]=countryname&include_states[0]=statename&include_cities[0]=citiesname",
      CURLOPT_HTTPHEADER => array(
        "api_key: <your_pushengage_api_key>",
        "cache-control: no-cache",
        "content-type: application/x-www-form-urlencoded"
      ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }
?>

Response

  • 200 OK
  • 401 Unauthorized
  • 400 Bad Request
  • 400 Bad Request
  • 400 Bad Request
  • 500 Internal Server Error
{
  "success": true,
  "notification_id": 12348
}
{
  "success": false,
  "message": "API KEY Invalid"
}
{
  "message": "The Title field is required.",
  "success": false
}
{
  "message": "The Message field is required.",
  "success": false
}
{
  "message": "The URL field is required.",
  "success": false
}
{
  "success": false,
  "message": "sending notification failed"
}

Draft Push with Device Segmentation#

Notifications will be sent to only those subscribers which are subscribed from these devices. For this push notification the required parameters are -

  • notification_title
  • notification_message
  • notification_url
  • include_device_types

Example#

Request

  • cURL
  • PHP
curl -X POST
-H "api_key: <your_pushengage_api_key>"
-H "Content-Type: application/x-www-form-urlencoded"
-d 'notification_title=this is title of notification&notification_message=this is message of notification&notification_url=http://www.example.com&include_device_types[0]=desktop'
"https://api.pushengage.com/apiv1/notifications"
<?php

    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://api.pushengage.com/apiv1/notifications",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => "notification_title=this is title of notification&notification_message=this is message of notification&notification_url=http://www.example.com&include_device_types[0]=desktop",
      CURLOPT_HTTPHEADER => array(
        "api_key: <your_pushengage_api_key>",
        "cache-control: no-cache",
        "content-type: application/x-www-form-urlencoded"
      ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }
?>

Response

  • 200 OK
  • 401 Unauthorized
  • 400 Bad Request
  • 400 Bad Request
  • 400 Bad Request
  • 500 Internal Server Error
{
  "success": true,
  "notification_id": 12348
}
{
  "success": false,
  "message": "API KEY Invalid"
}
{
  "message": "The Title field is required.",
  "success": false
}
{
  "message": "The Message field is required.",
  "success": false
}
{
  "message": "The URL field is required.",
  "success": false
}
{
  "success": false,
  "message": "sending notification failed"
}

Draft Push with Browser Segmentation#

Notifications will be sent to only those subscribers which are subscribed from these browsers. For this push notification the required parameters are -

  • notification_title
  • notification_message
  • notification_url
  • include_browsers

Example#

Request

  • cURL
  • PHP
curl -X POST
-H "api_key: <your_pushengage_api_key>"
-H "Content-Type: application/x-www-form-urlencoded"
-d 'notification_title=this is title of notification&notification_message=this is message of notification&notification_url=http://www.example.com&include_browsers[0]=chrome'
"https://api.pushengage.com/apiv1/notifications"
<?php

    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://api.pushengage.com/apiv1/notifications",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => "notification_title=this is title of notification&notification_message=this is message of notification&notification_url=http://www.example.com&include_browsers[0]=chrome",
      CURLOPT_HTTPHEADER => array(
        "api_key: <your_pushengage_api_key>",
        "cache-control: no-cache",
        "content-type: application/x-www-form-urlencoded"
      ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }
?>

Response

  • 200 OK
  • 401 Unauthorized
  • 400 Bad Request
  • 400 Bad Request
  • 400 Bad Request
  • 500 Internal Server Error
{
  "success": true,
  "notification_id": 12348
}
{
  "success": false,
  "message": "API KEY Invalid"
}
{
  "message": "The Title field is required.",
  "success": false
}
{
  "message": "The Message field is required.",
  "success": false
}
{
  "message": "The URL field is required.",
  "success": false
}
{
  "success": false,
  "message": "sending notification failed"
}

Draft Push with Require Interaction#

This feature is available for Chrome 47 and above versions only. For the chrome browser below version 47 default notification duration is 20 seconds. For this push notification the required parameters are; notification_title, notification_message, notification_url, notification_type and require_interaction, its value should be 0 or 1. If require_interaction value is 0 means notification duration is 20 seconds and 1 means notification duration is 28 days. The require_interaction default value is 1.

Example#

Request

  • cURL
  • PHP
curl -X POST
-H "api_key: <your_pushengage_api_key>"
-H "Content-Type: application/x-www-form-urlencoded"
-d 'notification_title=this is title of notification&notification_message=this is message of notification&notification_url=http://www.example.com&notification_type=draft&require_interaction=0'
"https://api.pushengage.com/apiv1/notifications"
<?php

    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://api.pushengage.com/apiv1/notifications",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => "notification_title=this is title of notification&notification_message=this is message of notification&notification_url=http://www.example.com&notification_type=draft&require_interaction=0",
      CURLOPT_HTTPHEADER => array(
        "api_key: <your_pushengage_api_key>",
        "cache-control: no-cache",
        "content-type: application/x-www-form-urlencoded"
      ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }
?>

Response

  • 200 OK
  • 401 Unauthorized
  • 400 Bad Request
  • 400 Bad Request
  • 400 Bad Request
  • 500 Internal Server Error
{
  "success": true,
  "notification_id": 12345673
}
{
  "success": false,
  "message": "API KEY Invalid"
}
{
  "message": "The Title field is required.",
  "success": false
}
{
  "message": "The Message field is required.",
  "success": false
}
{
  "message": "The URL field is required.",
  "success": false
}
{
  "success": false,
  "message": "sending notification failed"
}

Draft Push with Notification Expiry#

This defines the expiry time for a notification. If a user is not available online with a browser running, then the notification will be retried until expiration time. The maximum and default value is 1 month. For this push notification the required parameters are; notification_title, notification_message, notification_url, notification_type and notification_expiry, its value should be in minutes.

Example#

Request

  • cURL
  • PHP
curl -X POST
-H "api_key: <your_pushengage_api_key>"
-H "Content-Type: application/x-www-form-urlencoded"
-d 'notification_title=this is title of notification&notification_message=this is message of notification&notification_url=http://www.example.com&notification_type=draft&notification_expiry=10'
"https://api.pushengage.com/apiv1/notifications"
<?php

    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://api.pushengage.com/apiv1/notifications",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => "notification_title=this is title of notification&notification_message=this is message of notification&notification_url=http://www.example.com&notification_type=draft&notification_expiry=10",
      CURLOPT_HTTPHEADER => array(
        "api_key: <your_pushengage_api_key>",
        "cache-control: no-cache",
        "content-type: application/x-www-form-urlencoded"
      ),
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }
?>

Response

  • 200 OK
  • 401 Unauthorized
  • 400 Bad Request
  • 400 Bad Request
  • 400 Bad Request
  • 500 Internal Server Error
{
  "success": true,
  "notification_id": 12345674
}
{
  "success": false,
  "message": "API KEY Invalid"
}
{
  "message": "The Title field is required.",
  "success": false
}
{
  "message": "The Message field is required.",
  "success": false
}
{
  "message": "The URL field is required.",
  "success": false
}
{
  "success": false,
  "message": "sending notification failed"
}

Note

Draft your notification with combination of optional parameters according to your requirements.