POST Send Push to a Webpushr Subscriber ID

This section explains how you can send website push notifications to a specific Webpushr Subscriber ID. You can get this ID either from our web console or by using our JavaScript Method.

The required paramaters of title, message, target_url and sid associated with 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/sid

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
sid number required A single Webpushr Subscriber ID
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 not supported Not supported by this API endpoint
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","sid":"6676l"}' \
https://api.webpushr.com/v1/notification/send/sid
	$end_point = 'https://api.webpushr.com/v1/notification/send/sid';
	$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
		'sid'		=> '36252' //required
	);
	$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","sid":"64546"}'

response = requests.post('https://api.webpushr.com/v1/notification/send/sid', 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","sid":"64546"}';

var options = {
    url: 'https://api.webpushr.com/v1/notification/send/sid',
    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/sid")
        .headers(headers)
        .body("{\"title\":\"notification_title\",\"message\":\"notification message\",\"target_url\":\"https://www.webpushr.com\",\"sid\":\"64546\"}")
        .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","sid":"64546"}`)
	req, err := http.NewRequest("POST", "https://api.webpushr.com/v1/notification/send/sid", 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)
}

Webpushr API Playground

Try this API with your own data.

Try now

Result Format

{
   "status" : "success",
   "description" : "Notification sent successfully!", 
}
{
    "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"
}
{
    "status": "failure",
    "type": "invalid_sid",
    "description": "Subscriber not found"
}

Limitations

This endpoint does support Icon image but it does NOT support large images.