API usage
Using HTTP Post (not GET) in the programming language of your application and send a request to http://www.pushsafer.com/api or over a secure connection to https://www.pushsafer.com/api! To customize the push notification to your needs, the following values can be transmitted: title, message, icon, sound, vibration, image(s), device or device group, url, url title, time to live.

Here are some examples:

PHP (HTTP CONTEXT)
<?php
$url = 'https://www.pushsafer.com/api';
$data = array(
	't' => urldecode($title),
	'm' => urldecode($message),
	's' => $sound,
	'v' => $vibration,
	'i' => $icon,
	'd' => $device,
	'u' => urldecode($url),
	'ut' => urldecode($urltitle),
	'p' => $picture,
	'k' => $private_key
);
$options = array(
	'http' => array(
		'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
		'method'  => 'POST',
		'content' => http_build_query($data)
	)
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
?>

PHP (CURL)
<?php
$ch = curl_init();
$data = array(
	't' => urldecode($title),
	'm' => urldecode($message),
	's' => $sound,
	'v' => $vibration,
	'i' => $icon,
	'd' => $device,
	'u' => urldecode($url),
	'ut' => urldecode($urltitle),
	'p' => $picture,
	'k' => $private_key
);
$postString = http_build_query($data, '', '&');
curl_setopt($ch, CURLOPT_URL, 'https://www.pushsafer.com/api' );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false );
$response = curl_exec($ch);
curl_close($ch);
?>

jQuery
$.ajax({
  type: "POST",
  url: 'https://www.pushsafer.com/api',
  data:  {
		t: escape(title),
		m: escape(message),
		s: sound,
		v: vibration,
		i: icon,
		d: device,
		u: escape(url),
		ut: escape(urltitle),
		p: picture,
		k: private_key
  }
});

JavaScript
var xhttp;
if (window.XMLHttpRequest) {
    xhttp = new XMLHttpRequest();
    } else {
    // code for IE6, IE5
    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("POST", "https://www.pushsafer.com/api", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("t="+escape(title)+"&m="+escape(message)+"&s="+sound+"&v="+vibration+"&i="+icon+"&d="+device+"&u="+escape(url)+"&ut="+escape(urltitle)+"&k="+private_key);

Node.JS

npm install pushsafer-notifications

var push = require( 'pushsafer-notifications' );
 
var p = new push( {
    k: 'Your20CharPrivateKey',             // your 20 chars long private key 
    debug: true
});
 
var msg = {
    m: 'This is a Node.js test message',   // message (required)
    t: "Node.js Test",                     // title (optional)
    s: '8',                                // sound (value 0-28) 
    v: '2',                                // vibration (empty or value 1-3) 
    i: '5',                                // icon (value 1-98)
    u: 'https://www.pushsafer.com',        // url (optional)
    ut: 'Open Link',                       // url title (optional)
    d: '221'                               // the device or device group id 
};
 
// console.log( p ); 
 
p.send( msg, function( err, result ) {
    //console.log( 'ERROR:', err ); 
    console.log( 'RESULT', result );
    // process.exit(0); 
});

Unix Command Line
curl -s \
  --form-string "t=title" \
  --form-string "m=message" \
  --form-string "s=sound" \
  --form-string "v=vibration" \
  --form-string "i=icon" \
  --form-string "d=device" \
  --form-string "u=url" \
  --form-string "ut=urltitle" \
  --form-string "p=picture" \
  --form-string "k=private_key" \  
  https://www.pushsafer.com/api

Ruby
require "net/https"
url = URI.parse("https://www.pushsafer.com/api")
req = Net::HTTP::Post.new(url.path)
req.set_form_data({
  :t => title,
  :m => message,
  :s => sound,
  :v => vibration,
  :i => icon,
  :d => device,
  :u => url,
  :ut => urltitle,
  :p => picture,
  :k => private_key,
})
res = Net::HTTP.new(url.host, url.port)
res.use_ssl = true
res.verify_mode = OpenSSL::SSL::VERIFY_PEER
res.start {|http| http.request(req) }

C#/.NET
var options= new NameValueCollection {
		{ "t", title },
		{ "m", message },
		{ "s", sound },
		{ "v", vibration },
		{ "i", icon },
		{ "d", device },
		{ "u", url },
		{ "ut", urltitle },
		{ "p", picture },
		{ "k", private_key }
};
using (var client = new WebClient())
{
    client.UploadValues("https://www.pushsafer.com/api", options);
}

Perl
use LWP::UserAgent;
LWP::UserAgent->new()->post(
  "https://www.pushsafer.com/api", [
  "t" => title,
  "m" => message,
  "s" => sound,
  "v" => vibration,
  "i" => icon,
  "d" => device,
  "u" => url,
  "ut" => urltitle,
  "p" => picture,
  "k" => private_key,
]);

Python 3
from urllib.parse import urlencode
from urllib.request import Request, urlopen

url = 'https://www.pushsafer.com/api' # Set destination URL here
post_fields = {                       # Set POST fields here
	"t" : title,
	"m" : message,
	"s" : sound,
	"v" : vibration,
	"i" : icon,
	"d" : device,
	"u" : url,
	"ut" : urltitle,
	"k" : private_key
	}

request = Request(url, urlencode(post_fields).encode())
json = urlopen(request).read().decode()
print(json)
Firewall

If a firewall denied the access, please allow these ip addresses!

IPv4 = 85.114.132.122
IPv6 = 2001:4ba0:fff4:153::2

User Defined Variables

Use variables to configure your push-notification:

k = Private or Alias Key* Example: 3SAz1a2iTYsh19eXIMiO

d = Device
Single Device ID or Device Group ID or all Devices

d=a = all Devices
d=gs23 = a Device Group
d=52 = a Single Device

t = Title

m = Message*

s = Sound empty=device default or a number 0-28

v = Vibration empty=device default or a number 1-3

(only iOS & Android)

i = Icon Standard = 1 or a number 1-98

u = URL/Link u="https://www.pushsafer.com"

ut = URL Title ut="Open Link"

Open other apps through push notifications by using
URL schemes

p = Picture Data URL with Base64-encoded string
p2 = Picture 2 Data URL with Base64-encoded string
p3 = Picture 3 Data URL with Base64-encoded string

data:image/gif;base64,R0l...BOw==
data:image/jpeg;base64,C4s...Cc1==
data:image/png;base64,G0G...h5r==

l = Time to Live Integer number 0-43200: Time in minutes,

after which message automatically gets purged.

* required variables
HTML/Message Styling
The message can be formatted using BBCode. Formatting can only be displayed in the client apps but not in the Push-Notification itselfs. The following BBCodes are accepted:

[b]Word[/b] Word bold
[i]Word[/i] Word italic
[u]Word[/u] Word underline
[s]Word[/s] Word crossed out
[left]Word[/left] Text left-aligned
[center]Word[/center] Text center-aligned
[right]Word[/right] Text right-aligned
[size=18]Word[/size] Text in font-size 18 pixel
optimal font size 8-48
[color=blue]Word[/color] Word blue
[color=#FF0000]Word[/color] Word red
Hex codes and most color names are supported.
[url=http://www.domain.com]Link[/url] display a link
Combined values are also possible:
[b][u][color=#980000]Word[/color][/u][/b] = Word

Sound
Values in brackets applies to Windows 10 (UWP)

empty = Device Default
0 = silent
1 = Ahem (IM)
2 = Applause (Mail)
3 = Arrow (Reminder)
4 = Baby (SMS)
5 = Bell (Alarm)
6 = Bicycle (Alarm2)
7 = Boing (Alarm3)
8 = Buzzer (Alarm4)
9 = Camera (Alarm5)
10 = Car Horn (Alarm6)
11 = Cash Register (Alarm7)
12 = Chime (Alarm8)
13 = Creaky Door (Alarm9)
14 = Cuckoo Clock (Alarm10)
15 = Disconnect (Call)
16 = Dog (Call2)
17 = Doorbell (Call3)
18 = Fanfare (Call4)
19 = Gun Shot (Call5)
20 = Honk (Call6)
21 = Jaw Harp (Call7)
22 = Morse (Call8)
23 = Electricity (Call9)
24 = Radio Tuner (Call10)
25 = Sirens
26 = Military Trumpets
27 = Ufo
28 = Whah Whah Whah
Icon
= 1 = 2 = 3 = 4 = 5 = 6 = 7 = 8 = 9 = 10 = 11 = 12 = 13 = 14 = 15 = 16 = 17 = 18 = 19 = 20 = 21 = 22 = 23 = 24 = 25 = 26 = 27 = 28 = 29 = 30 = 31 = 32 = 33 = 34 = 35 = 36 = 37 = 38 = 39 = 40 = 41 = 42 = 43 = 44 = 45 = 46 = 47 = 48 = 49 = 50 = 51 = 52 = 53 = 54 = 55 = 56 = 57 = 58 = 59 = 60 = 61 = 62 = 63 = 64 = 65 = 66 = 67 = 68 = 69 = 70 = 71 = 72 = 73 = 74 = 75 = 76 = 77 = 78 = 79 = 80 = 81 = 82 = 83 = 84 = 85 = 86 = 87 = 88 = 89 = 90 = 91 = 92 = 93 = 94 = 95 = 96 = 97 = 98
API Response-Codes

With every api call you get a response with http header code and a JSON string for evaluation

HTTP/1.0 200 OK
JSON
{ "status":1, "success":"message transmitted", "available":{ "80":{"iPhone 6":"1182"}, "122":{"WIN 10":"32"}, "211":{"Cubot":"3182"} } }


available registered devices with available API calls

HTTP/1.0 250 invalid key
JSON
{ "status":0, "error":"invalid key" }

HTTP/1.0 255 invalid key or empty message
JSON
{ "status":0, "error":"invalid key or empty message" }

HTTP/1.0 260 empty message
JSON
{ "status":0, "error":"empty message" }

HTTP/1.0 270 invalid device
JSON
{ "status":0, "error":"invalid device" }

HTTP/1.0 275 invalid device group
JSON
{ "status":0, "error":"invalid device group" }


Copyright © Pushsafer.com, All rights reserved.