POST Send Push to Segment(s)

Use the endpoint URL below to send a push notification campaign to subscribers of a particular segment(s). The request method of this call needs to be "POST".

The required paramaters of title, message, target_url and segmentof the notification message must be sent as POST parameters as part of the JSON to the API endpoint.

Endpoint URL

https://api.webpushr.com/v1/notification/send/segment

Request Parameters

Parameter Type Description
title string required Title of the notification Character limit: 100
message string required Body of the notification Character limit: 255
target_url string required This is the URL that will be opened when someone clicks on the notification. This will be URL to your article, product listing or any other page on your site that you are promoting via push notification. Character limit: 255
segment array required An arrray containting segment ID(s). You can get the ID(s) from Webpushr dashboard.
name string optional This is only used for internal reporting and Webpushr dashboard views. We recommend naming each campaign based on the campaign's purpose. Character limit: 100
icon string optional URL of the icon to be shown in the notification. URL needs to be on HTTPS and needs to point to a 192 x 192 PNG.
image string optional URL of the big image to be shown in the notification. URL needs to be on HTTPS and needs to point to an image file. Please note that this only works for Chrome subscribers on Android & Edge Browsers. Chrome on Desktop & Firefox does not support this as of now.
expire_push string optional This parameter is used to set the time (in minutes, hours or days) up till which the notification should be attempted if the subscriber is offline. If this is not set, the default value of 4 weeks is used. Pass a number followed by 'm' for minutes, 'h' for hours & 'd' for days. Example: '5d' for 5 days, '50d' for 50 days.
auto_hide integer optional To be sent as a POST parameter and should be a binary (1 or 0) value. '0' will keep the notification on recepients' screen until it is actively clicked upon or closed. '1' will close the notification automatically, after a few seconds, after it appears on the screen.
send_at date optional You will set this if you want to send the notification at a scheduled time in the future. The date is expressed in UTC format. Example: for PST schedule time of 2020-03-04 13:30 (San Francisco time), it should be expressed as "2020-03-04 13:30 -08:00" since PST is 8 hours behind UTC.
action_buttons array optional A multi-diminsional array containting the list of buttons. Note that these OPTIONAL buttons are not supported by all browsers and devices at this time.
Parameter Type Description
title string required Title of the action button Character limit: 100
url string required URL of the action button. Character limit: 100

Examples

curl -X POST \
-H "webpushrKey: <YOUR REST API KEY>" \
-H "webpushrAuthToken: <YOUR AUTHENTICATION TOKEN>" \
-H "Content-Type: application/json" \
-d '{"title":"notification_title","message":"notification message","target_url":"https://www.webpushr.com","segment":[1,2,3],"action_buttons":[{"title":"Demo", "url":"https://www.webpushr.com/demo"},{"title":"Pricing", "url":"https://www.webpushr.com/pricing"}]}' \
https://api.webpushr.com/v1/notification/send/segment
	$end_point = 'https://api.webpushr.com/v1/notification/send/segment';
	$http_header = array( 
		"Content-Type: Application/Json", 
		"webpushrKey: <YOUR REST API KEY>", 
		"webpushrAuthToken: <YOUR AUTHENTICATION TOKEN>"
	);
	$req_data = array(
		'title' 			=> "Notification title", //required
		'message' 		=> "Notification message", //required
		'target_url'	=> 'https://www.webpushr.com', //required
		'name'			=> 'Test campain',
		'segment'		=> array(1,2,3), //required
		'icon'			=> 'https://www.webpushr.com/logo.png',
		'image'			=> 'https://www.webpushr.com/image.png',
		'auto_hide'		=> 1,
		'expire_push'	=> '5m',
		'send_at'		=> '2019-10-10 19:31 +5:30',
		'action_buttons'=> array(	
			array('title'=> 'Demo', 'url' => 'https://www.webpushr.com/demo'),
			array('title'=> 'Rates', 'url' => 'https://www.webpushr.com/pricing')
		)
	);
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_HTTPHEADER, $http_header);
	curl_setopt($ch, CURLOPT_URL, $end_point );
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($req_data) );
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$response = curl_exec($ch);
	echo $response;
import requests

headers = {
    'webpushrKey': '<YOUR REST API KEY>',
    'webpushrAuthToken': '<YOUR AUTHENTICATION TOKEN>',
    'Content-Type': 'application/json',
}

data = '{"title":"notification_title","message":"notification message","target_url":"https://www.webpushr.com","segment":[<SEGMENT ID 1 >,<SEGMENT ID 2 >,<SEGMENT ID 3>]}'

response = requests.post('https://api.webpushr.com/v1/notification/send/segment', headers=headers, data=data)
var request = require('request');

var headers = {
    'webpushrKey': '<YOUR REST API KEY>',
    'webpushrAuthToken': '<YOUR AUTHENTICATION TOKEN>',
    'Content-Type': 'application/json'
};

var dataString = '{"title":"notification_title","message":"notification message","target_url":"https://www.webpushr.com","segment":[<SEGMENT ID 1 >,<SEGMENT ID 2 >,<SEGMENT ID 3>]}';

var options = {
    url: 'https://api.webpushr.com/v1/notification/send/segment',
    method: 'POST',
    headers: headers,
    body: dataString
};

function callback(error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(body);
    }
}

request(options, callback);
extern crate reqwest;
use reqwest::header;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut headers = header::HeaderMap::new();
    headers.insert("webpushrKey", "<YOUR REST API KEY>".parse().unwrap());
    headers.insert("webpushrAuthToken", "<YOUR AUTHENTICATION TOKEN>".parse().unwrap());
    headers.insert("Content-Type", "application/json".parse().unwrap());

    let res = reqwest::Client::new()
        .post("https://api.webpushr.com/v1/notification/send/segment")
        .headers(headers)
        .body("{\"title\":\"notification_title\",\"message\":\"notification message\",\"target_url\":\"https://www.webpushr.com\",\"segment\":[<SEGMENT ID 1 >,<SEGMENT ID 2 >,<SEGMENT ID 3>]}")
        .send()?
        .text()?;
    println!("{}", res);

    Ok(())
}
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"strings"
)

func main() {
	client := &http.Client{}
	var data = strings.NewReader(`{"title":"notification_title","message":"notification message","target_url":"https://www.webpushr.com","segment":[<SEGMENT ID 1 >,<SEGMENT ID 2 >,<SEGMENT ID 3>]}`)
	req, err := http.NewRequest("POST", "https://api.webpushr.com/v1/notification/send/segment", data)
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("webpushrKey", "<YOUR REST API KEY>")
	req.Header.Set("webpushrAuthToken", "<YOUR AUTHENTICATION TOKEN>")
	req.Header.Set("Content-Type", "application/json")
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	bodyText, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s\n", bodyText)
}

Result Format

{
   "status" : "success",
   "description" : "Campaign created successfully!", 
   "ID" : 1
}
{
    "status": "failure",
    "type" : "header_invalid",
    "description": "Missing webpushrKey in header"
}
{
    "status": "failure",
    "type" : "bad_request",
    "description": "Invalid JSON request"
}
{
    "status": "failure",
    "type" : "authentication_failure",
    "description": "You are not authorized"
}
{
    "status": "failure",
    "type" : "rate_limit",
    "description": "Too many requests"
}
{
    "status": "failure",
    "description": "Something went wrong. Please try again after some time"
}
{
    "status": "failure",
    "type": "missing_parameter",
    "description": "Missing required parameter title"
}
{
    "status": "failure",
    "type": "invalid_format",
    "description": "Schedule date must be in valid format YYYY-MM-DD HH:MM +0"
}
{
    "status": "failure",
    "type": "invalid_format",
    "description": "Please provide the valid format for expire_push perameter."
}
{
    "status": "failure",
    "type": "invalid_value",
    "description": "Schedule date must be at least 5 minutes in future"
}
{
    "status": "failure",
    "type": "invalid_value",
    "description": "Invalid parameter 'action_buttons' values"
}
{
    "status": "failure",
    "type": "invalid_type",
    "description": "Parameter action_buttons must be an array"
}