POST Send Push to All Subscribers
Please use the endpoing URL below to send a notification to all subscribers. The request method of this call needs to be "POST".
The title, message and URL of the notification and the Image URL have to be sent as POST parameters to the API endpoint.
URL of the icon to be shown in the notification needs to point to a 192 x 192 PNG.
Endpoint URL
https://api.webpushr.com/v1/notification/send/all
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 | |||||||||
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.
|
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","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/all
$end_point = 'https://api.webpushr.com/v1/notification/send/all';
$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',
'icon' => 'https://www.webpushr.com/logo.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"}'
response = requests.post('https://api.webpushr.com/v1/notification/send/all', 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"}';
var options = {
url: 'https://api.webpushr.com/v1/notification/send/all',
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/all")
.headers(headers)
.body("{\"title\":\"notification_title\",\"message\":\"notification message\",\"target_url\":\"https://www.webpushr.com\"}")
.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"}`)
req, err := http.NewRequest("POST", "https://api.webpushr.com/v1/notification/send/all", 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"
}
- Got any questions? Ask the Webpushr Forum New