<
Send messages API

How can I send push notifications with the message API?

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, icon color, sound, vibration, image(s), device or device group, url, url title, time to live, priority, retry, expire, answer.

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,
	'c' => $iconcolor,
	'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,
	'c' => $iconcolor,
	'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,
		c: iconcolor,
		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+"&c="+iconcolor+"&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-50) 
    v: '2',                                // vibration (empty or value 1-3) 
    i: '5',                                // icon (value 1-176)
    c: '#FF0000',                          // iconcolor (optional)
    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 "c=iconcolor" \
  --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,
  :c => iconcolor,
  :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 },
		{ "c", iconcolor },
		{ "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,
  "c" => iconcolor,
  "d" => device,
  "u" => url,
  "ut" => urltitle,
  "p" => picture,
  "k" => private_key,
]);

TCL - Tool Command Language
package require http
set url "https://www.pushsafer.com/api"
::http::geturl $url -query [::http::formatQuery k "privateKey" t "Title" m "Message" d "deviceID" i "Icon" s "Sound" v "Vibration" c "IconColor" u "URL" ut "URLTitle" l "Time2Live" p "Base64EncodedImageString"]

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,
	"c" : iconcolor,
	"d" : device,
	"u" : url,
	"ut" : urltitle,
	"k" : private_key
	}

request = Request(url, urlencode(post_fields).encode())
json = urlopen(request).read().decode()
print(json)
Read API
With the Read API use Private Key and Device ID to retrieve all messages of a device (including all parameters). The request can be made by GET or POST.

A simple example:

https://www.pushsafer.com/api-m?k={private_key}&d={device}

Reading API Response Codes

HTTP/1.0 200 OK
JSON
{
"status": 1, "messages": { "21231": { "id": "21231", "title": "Pushsafer Test Push", "message": "This is only a test", "icon": "22", "iconcolor": "#FFCCCC", "sound": "12", "vibration": "3", "url": "https:\/\/www.pushsafer.com", "url_title": "Open Pushsafer", "image1": "", "image2": "", "image3": "", "time2live": "", "date_sent": "2018-08-21 16:00:23", "status_sent": "1", "priority": "2", "retry": "1", "retries": "10", "expire": "2018-08-21 18:00:23", "expired": "1", "reply": "1", "replied": "1", "answer": "This is a test answer" } } }

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

Device API
With the device API and your private key and username, you can read out your registered devices. The call to the device API is similar to the message API. The following parameters must be passed, you can use POST or GET method:
k = private key
u = username or email address

Easy example:

https://www.pushsafer.com/api-d?k={private_key}&u={user}

Device API response code

HTTP/1.0 200 OK
JSON
{
"status":1, "devices":{ "a":"All Devices", "gs40":"Group: iOS", "gs44":"Group: Windows", "gs46":"Group: Android", "gs47":"Group: Browser", "53":"iPhone4", "78":"GT-P5110", "82":"Cindys iPhone6", "86":"iPad Air", "119":"iPhone6p", "143":"Windows Firefox", "267":"Lumia 550", "269":"PC Office WIN10", "318":"Windows Chrome", "418":"BV2000s", "484":"CUBOT GT72E", "1351":"HUAWEI MT7-L09", "1520":"Cindy's SATELLITE PRO" } }

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

Key API
With the key API and your private key and username, you can check if your private key is valid. The call to the key API is similar to the message or device API. The following parameters must be passed, you can use POST or GET method:
k = private key
u = username or email address

Easy example:

https://www.pushsafer.com/api-k?k={private_key}&u={user}

Key API response codes

HTTP/1.0 200 OK
JSON
{ "status":1, "success":"valid key" }

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

Firewall

If a firewall denied the access, please allow this ip address!

IPv4 = 212.83.36.91

IPv6 = 2a00:f48:cafe:a911::1

Parameter

Use parameters to configure your push-notification, press the orange parameter to get a more detailed description:

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-50

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

(only iOS & Android)

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

c = Icon Color Standard = Empty

or a Hexadecimal Colorcode, Example: #FF0000

(only Android >5.0, Windows 10 & Client APP)

LED Notification Color
(only Android, device needs a RGB LED)

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.

pr = Priority

-2 = lowest priority

-1 = lower priority

0 = normal priority

1 = high priority

2 = highest priority

re = Retry / resend

Integer 60-10800 (60s steps): Time in seconds, after a message shuld resend.

ex = Expire

Integer 60-10800: Time in seconds, after the retry/resend should stop.

a = Answer

1 = Answer is possible
0 = Answer is not possible.

* required parameters

max. size of all POST parameters = 8192kb

API Response-Codes

With every message 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":1823, "message_ids":"1324312:118,1324313:324" }


available available API calls

message_ids unique message ids separated by comma
and associated device ID with seperated by colon

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" }

HTTP/1.0 280 not enough API calls
JSON
{ "status":0, "error":"not enough API calls" }

HTML 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
Line break: \n or BBCode [br]

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
29 = Man Saying Goodbye
30 = Man Saying Hello
31 = Man Saying No
32 = Man Saying Ok
33 = Man Saying Ooohhhweee
34 = Man Saying Warning
35 = Man Saying Welcome
36 = Man Saying Yeah
37 = Man Saying Yes
38 = Beep short
39 = Weeeee short
40 = Cut in and out short
41 = Finger flicking glas short
42 = Wa Wa Waaaa short
43 = Laser short
44 = Wind Chime short
45 = Echo short
46 = Zipper short
47 = HiHat short
48 = Beep 2 short
49 = Beep 3 short
50 = Beep 4 short
51 = The Alarm is armed
52 = The Alarm is disarmed
53 = The Backup is ready
54 = The Door is closed
55 = The Door is opend
56 = The Window is closed
57 = The Window is open
58 = The Light is off
59 = The Light is on
60 = The Doorbell rings
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 = 99 = 100 = 101 = 102 = 103 = 104 = 105 = 106 = 107 = 108 = 109 = 110 = 111 = 112 = 113 = 114 = 115 = 116 = 117 = 118 = 119 = 120 = 121 = 122 = 123 = 124 = 125 = 126 = 127 = 128 = 129 = 130 = 131 = 132 = 133 = 134 = 135 = 136 = 137 = 138 = 139 = 140 = 141 = 142 = 143 = 144 = 145 = 146 = 147 = 148 = 149 = 150 = 151 = 152 = 153 = 154 = 155 = 156 = 157 = 158 = 159 = 160 = 161 = 162 = 163 = 164 = 165 = 166 = 167 = 168 = 169 = 170 = 171 = 172 = 173 = 174 = 175 = 176 = 177

Copyright © Pushsafer.com, All rights reserved.