POST Send Push to All Users With Matching Custom Attribute(s)

This section explains how you can send a push notification to users that you have programatically (via JavaScript) tagged with a Custom Attribute(s). The most common usecase is if you want to send notification to a user tagged with a certain user ID or e-mail address.

Use the endpoint URL below to send a push notification campaign to subscribers with a matching custom attribute. The request method of this call needs to be "POST".

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

Request Parameters

Parameter Type Description
title string required Title of the notification Character limit: 100
message string required Body of the notification Character limit: 250
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
attribute array required An arrray containting custom attributes
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 not supported Not supported on this 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. '1' will keep the notification on recepients' screen until it is actively clicked upon or closed. '0' 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","attribute":{"userEmail":"johndoe@example.com"}}' \
https://api.webpushr.com/v1/notification/send/attribute
	$end_point = 'https://api.webpushr.com/v1/notification/send/attribute';
	$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
		'attribute'		=> array('userEmail' => 'johndoe@example.com'), //required - in Key/Value Pair(s)
	);
	$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","attribute":{"email":"johndoe@example.com"}}'

response = requests.post('https://api.webpushr.com/v1/notification/send/attribute', 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","attribute":{"email":"johndoe@example.com"}}';

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