Messages API
API methods to manage push messages
To get started with Pushwoosh Remote API, please check out the descriptions of the /createMessage request parameters.
post
https://api.pushwoosh.com/json/1.3
/createMessage
/createMessage
/createMessage method supports content templates. To learn more, please refer to the Liquid Templates guide.
Example
{
"request": {
"application": "XXXXX-XXXXX", // required. Pushwoosh application code
"applications_group": "GROUP_CODE", // optional. Can be used instead of "application".
"auth": "yxoPUlwqm…………pIyEX4H", // required. API access token from Pushwoosh Control Panel
"notifications": [
{
// Content settings
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
"ignore_user_timezone": true, // or false, required
"timezone": "America/New_York", // optional. If ignored UTC-0 is default for "send_date". See http://php.net/manual/timezones.php for supported timezones.
"campaign": "CAMPAIGN_CODE", // optional. Campaign code to which you want to assign this push message.
"geozone": { // optional, send to Geozone
"lat": 22.22,
"lng": 33.33,
"range": 110
},
"content": { // required, object( language1: 'content1', language2: 'content2' ) OR string. Ignored for Windows 8, use "wns_content" instead. (Use \n for multiline text. Ex: "hello\nfriend")
"en": "English",
"fr": "French"
},
"title": { // optional, object( language1: 'title1', language2: 'title2' ) OR string. Ignored if platform-specific titles are specified (e.g., 'ios_title', 'android-header', etc.; see the platform-specific parameters examples below).
"en": "Title",
"fr": "Titre"
},
"subtitle":{ // optional, object( language1: 'subtitle1', language2: 'subtitle1' ) OR string. Ignored if platform-specific titles are specified (e.g., 'ios_subtitle'; see the platform-specific parameters examples below).
"en": "Subtitle",
"fr": "Sous-titre"
},
"rich_media": "XXXXX-XXXXX", // optional, string. Copy the Rich Media code from the URL bar of the Rich Media editor page in Pushwoosh Control Panel.
"remote_page": "http://myremoteurl.com", // optional, string. Remote Rich HTML Page URL. <scheme>://<authority>
"link": "http://google.com", // optional, string. For deeplinks add "minimize_link":0
"minimize_link": 0, // optional. 0 — do not minimize, 2 — bitly. Default = 2. Google URL shortener is disabled since March 30, 2019. Please note that shorteners have restrictions on a number of calls.
"data": {
"key": "value" // optional, JSON string or JSON object, will be passed as "u" parameter in the payload (converted to JSON string).
},
"transactionId": "6e22a9af-84e4-46e6-af16-e457a4a6e7e5", // optional, string. Unique message identifier to prevent duplicating in case of network problems. Stored on the side of Pushwoosh for 5 minutes.
"platforms": [1,3,5,7,8,9,10,11,12,13,17], // optional. 1 — iOS; 3 — Android; 5 — Windows Phone; 7 — OS X; 8 — Windows 8; 9 — Amazon; 10 — Safari; 11 — Chrome; 12 — Firefox; 13 - IE11; 17 - Huawei; ignored if "devices" < 10
"preset": "Q1A2Z-6X8SW", // optional. Push Preset Code from your Control Panel. If specific params are sent in the request, they override preset's params.
"send_rate": 100, // optional. Throttling. Valid values are from 100 to 1000 pushes/second.
// Templating related, please refer to the Template Engine guide to learn more
"use_template" : true, // optional. Default 'false'
"template_bindings" : { // optional
"TemplatePlaceholder" : "Value"
},
// Frequency capping params
"capping_days": 30, // , optional. Amount of days for frequency capping (max 30 days)
"capping_count": 10, // , optional. The max number of pushes that can be sent from a specific app to a particular device within a 'capping_days' period. In case the message created exceeds the 'capping_count' limit for a device, it won't be sent to that device.
// To save the message to the Inbox via API, use "inbox_date" or "inbox_image". The message is saved when at least one of these parameters is used.
"inbox_date": "2017-02-02", // optional. Specify when to remove a message from the Inbox. Message will be removed from Inbox at 00:00:01 UTC of the date specified, so the previous date is the last day a user can see the message in their Inbox. If not specified, the default removal date is the next day after the send date.
"inbox_image": "Inbox image URL", // optional. The image to be shown near the message.
"devices": [ // optional. Specify tokens or hwids to send targeted push notifications. Not more than 1000 tokens/hwids in an array. If set, the message will only be sent to the devices on the list. Application Group for devices list is not allowed. iOS push tokens can only be lower case.
"dec301908b9ba8df85e57a58e40f96f523f4c2068674f5fe2ba25cdc250a2a41"
],
// user-centric push notifications
"users": [ // optional. If set, message will only be delivered to the specified user ID's (set via /registerUser call). If specified together with devices parameter, the latter will be ignored. Not more than 1000 user ID's in an array.
"user_3078a"
],
//filters and conditions
"filter": "FILTER_NAME", // optional
"dynamic_content_placeholders": { // optional. Placeholders for dynamic content instead of device tags.
"firstname": "John",
"lastname": "Doe"
},
"conditions": [TAG_CONDITION1, TAG_CONDITION2, ..., TAG_CONDITIONN], // optional. See the remark below.
"conditions_operator": "AND" // optional, logical operator for conditions arrays. Possible values: AND | OR. AND is default.
}
]
}
}
Example
{
"request": {
"application": "12345-67891", // required. Pushwoosh application code
"auth": "yxoPUlwqm…………pIyEX4H", // required. API access token from Pushwoosh Control Panel
"notifications": [{
// Content settings
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
"content": { // required, object( language1: 'content1', language2: 'content2' ) OR string. Ignored for Windows 8, use "wns_content" instead. (Use \n for multiline text. Ex: "hello\nfriend")
"en": "English",
"de": "Deutsch"
},
"ios_badges": 5, // optional, integer. iOS application badge number. Use "+n" or "-n" to increment/decrement the badge value by n.
"ios_sound": "sound file.wav", // optional. Sound file name in the main bundle of application. If left empty, the device will produce no sound upon receiving a push.
"ios_ttl": 3600, // optional. Time to live parameter - maximum message lifespan in seconds.
"ios_silent": 1, // optional. Enables silent notifications (ignore "sound" and "content").
"ios_category_id": "1", // optional, string. iOS8 category ID from Pushwoosh.
"ios_root_params": { // optional. Root level parameters to the aps dictionary.
"aps": {
"content-available": "1",
"mutable-content": 1 // required for iOS 10 Media attachments.
},
"data": <<User supplied data, max of 4KB>>
},
"apns_trim_content": 1, // optional. (0|1) Trims the exceeding content strings with ellipsis.
"ios_trim_content": 1, // Deprecated, use "apns_trim_content" instead.
"ios_attachment" : "YOUR_ATTACHMENT_MEDIA_URL", // optional. Insert media content in notification.
"ios_title": "Title", // optional. Adds Title for push notification.
"ios_subtitle": "SubTitle", // optional. Adds sub-title for push notification.
"ios_thread_id": "some thread id", // optional, string. Identifier to group related notifications. Messages with the same thread ID will be grouped on the lock screen and in the Notification Center.
"ios_critical": true, // optional. Marks iOS notification as a critical alert playing sound even if a device is muted or Do Not Disturb mode is on.
"ios_interruption_level": "active" // optional. One of "passive", "active", "time-sensitive", "critical". Indicates the importance and delivery timing of a notification. Refer to the One-time push guide for details.
}]
}
}
Example
{
"request": {
"application": "12345-67891", // required. Pushwoosh application code
"auth": "yxoPUlwqm…………pIyEX4H", // required. API access token from Pushwoosh Control Panel
"notifications": [{
// Content settings
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
"content": { // required, object( language1: 'content1', language2: 'content2' ) OR string. Ignored for Windows 8, use "wns_content" instead. (Use \n for multiline text. Ex: "hello\nfriend")
"en": "English",
"de": "Deutsch"
},
"android_root_params": { // optional. Custom key-value object. Root level parameters for the android payload recipients.
"key": "value",
"CancelID" : MESSAGE_ID // cancels the push notification with the specified ID (get the ID from the Message History)
},
"android_sound": "soundfile", // optional. No file extension. If left empty, the device will produce no sound upon receiving a push.
"android_header": "header", // optional. Android notification header.
"android_icon": "icon.png", // optional
"android_custom_icon": "http://example.com/image.png", // optional. Full path URL to the image file.
"android_banner": "http://example.com/banner.png", // optional. Full path URL to the image file.
"android_badges": 5, // optional, integer. Android application icon badge number. Use "+n" or "-n" to increment/decrement the badge value by n.
"android_gcm_ttl": 3600, // optional. Time to live parameter — maximum message lifespan in seconds.
"android_vibration": 0, // optional, boolean. Android force-vibration for high-priority pushes.
"android_led": "#rrggbb", // optional. LED hex color, device will do its best approximation.
"android_priority": -1, // optional. Sets the “importance” parameter for devices with Android 8.0 and higher, as well as the “priority” parameter for devices with Android 7.1 and lower. Establishes the interruption level of a notification channel or a particular notification. Valid values are -2, -1, 0, 1, 2.
"android_delivery_priority": "normal", // or "high", optional. Enables notification’s delivery when the device is in the power saving mode.
"android_ibc": "#RRGGBB", // optional, icon background color on Lollipop, #RRGGBB, #AARRGGBB, "red", "black", "yellow", etc.
"android_silent": 1 // optional. 0 or 1, enable silent notificaiton (ignore sound and content).
}]
}
}
Huawei parameters
{
"request": {
"application": "12345-67891", // required. Pushwoosh application code
"auth": "yxoPUlwqm…………pIyEX4H", // required. API access token from Pushwoosh Control Panel
"notifications": [{
// Content settings
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
"content": { // required, object( language1: 'content1', language2: 'content2' ) OR string. Ignored for Windows 8, use "wns_content" instead. (Use \n for multiline text. Ex: "hello\nfriend")
"en": "English",
"de": "Deutsch"
},
"huawei_android_badges": true, // optional, boolean
"huawei_android_silent": 0, // 0 or 1, enable silent notificaiton (ignore sound and content).
"huawei_android_icon": "http://example.com/icon.png", // optional
"huawei_android_led": "#FF0011", // optional. LED hex color, device will do its best approximation.
"huawei_android_vibration": 1, // boolean. Huawei force-vibration for high-priority pushes.
"huawei_android_sound": "sound.wav", // optional. No file extension. If left empty, the device will produce no sound upon receiving a push.
"huawei_android_sound_off": true,
"huawei_android_custom_icon": "http://example.com/custom_icon.png",
"huawei_android_header": "Huawei Header", // string. Notification title.
"huawei_android_gcm_ttl": 2400, // integer. Time to live parameter - maximum message lifespan in seconds.
"huawei_android_banner": "http://example.com/banner.png", // Full path URL to the image file.
"huawei_android_root_params": { // Custom key-value object. Root level parameters for the Huawei payload recipients.
"key": "value"
},
"huawei_android_priority": 0, // Sets the “importance” parameter for devices with Android 8.0 and higher, as well as the “priority” parameter for devices with Android 7.1 and lower. Establishes the interruption level of a notification channel or a particular notification. Valid values are -2, -1, 0, 1, 2.
"huawei_android_ibc": "#0011AA", // icon background color on Lollipop, #RRGGBB, #AARRGGBB, "red", "black", "yellow", etc.
"huawei_android_lockscreen": 1,
"huawei_android_delivery_priority": "normal" // or "high", optional. Enables notification’s delivery when the device is in the power saving mode.
}]
}
}
Safari
{
"request": {
"application": "12345-67891", // required. Pushwoosh application code
"auth": "yxoPUlwqm…………pIyEX4H", // required. API access token from Pushwoosh Control Panel
"notifications": [{
// Content settings
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
"content": { // required, object( language1: 'content1', language2: 'content2' ) OR string. Ignored for Windows 8, use "wns_content" instead. (Use \n for multiline text. Ex: "hello\nfriend")
"en": "English",
"de": "Deutsch"
},
"safari_title": "Title", // required. Title of the notification.
"safari_action": "Click here", // optional
"safari_url_args": ["firstArgument", "secondArgument"], // required, but the value may be empty
"safari_ttl": 3600 // optional. Time to live parameter — the maximum lifespan of a message in seconds.
}]
}
}
Chrome
{
"request": {
"application": "12345-67891", // required. Pushwoosh application code
"auth": "yxoPUlwqm…………pIyEX4H", // required. API access token from Pushwoosh Control Panel
"notifications": [{
// Content settings
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
"content": { // required, object( language1: 'content1', language2: 'content2' ) OR string. Ignored for Windows 8, use "wns_content" instead. (Use \n for multiline text. Ex: "hello\nfriend")
"en": "English",
"de": "Deutsch"
},
"chrome_title": "Title", // optional. You can specify the header of the message in this parameter.
"chrome_icon": "icon_URL", // full path URL to the icon or extension resources file path
"chrome_gcm_ttl": 3600, // optional. Time to live parameter – maximum message lifespan in seconds.
"chrome_duration": 20, // optional. max. 50 seconds. Changes chrome push display time. Set to 0 to display push until user interacts with it.
"chrome_image": "image_URL", // optional. URL to large image.
"chrome_root_params": { // optional. Set parameters specific to messages sent to Chrome.
"key": "value"
},
"chrome_button_text1": "1", // optional
"chrome_button_url1": "button1_URL", // optional. Ignored if chrome_button_text1 is not set.
"chrome_button_text2": "2", // optional
"chrome_button_url2": "button2_url" // optional. Ignored if chrome_button_text2 is not set.
}]
}
}
Firefox
{
"request": {
"application": "12345-67891", // required. Pushwoosh application code
"auth": "yxoPUlwqm…………pIyEX4H", // required. API access token from Pushwoosh Control Panel
"notifications": [{
// Content settings
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
"content": { // required, object( language1: 'content1', language2: 'content2' ) OR string. Ignored for Windows 8, use "wns_content" instead. (Use \n for multiline text. Ex: "hello\nfriend")
"en": "English",
"de": "Deutsch"
},
"firefox_title": "Title", // optional. You can specify message header here.
"firefox_icon": "icon_URL", // full path URL to the icon or path to the file in extension resources.
"firefox_root_params": { // optional. Set parameters specific to messages sent to Firefox.
"key": "value"
}
}]
}
}
Amazon
{
"request": {
"application": "12345-67891", // required. Pushwoosh application code
"auth": "yxoPUlwqm…………pIyEX4H", // required. API access token from Pushwoosh Control Panel
"notifications": [{
// Content settings
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
"content": { // required, object( language1: 'content1', language2: 'content2' ) OR string. Ignored for Windows 8, use "wns_content" instead. (Use \n for multiline text. Ex: "hello\nfriend")
"en": "English",
"de": "Deutsch"
},
"adm_root_params": { // optional, custom key-value object
"key": "value"
},
"adm_sound": "push.mp3", // optional
"adm_header": "Header", // optional
"adm_icon": "icon", // optional
"adm_custom_icon": "http://example.com/image.png", // optional
"adm_banner": "http://example.com/banner.png", // optional
"adm_ttl": 3600, // optional. Time to live parameter — the maximum message lifespan in seconds.
"adm_priority": -1 // optional, priority of the push in Amazon push drawer, valid values are -2, -1, 0, 1 and 2.
}]
}
}
Windows Phone
{
"request": {
"application": "12345-67891", // required. Pushwoosh application code
"auth": "yxoPUlwqm…………pIyEX4H", // required. API access token from Pushwoosh Control Panel
"notifications": [{
// Content settings
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
"content": { // required, object( language1: 'content1', language2: 'content2' ) OR string. Ignored for Windows 8, use "wns_content" instead. (Use \n for multiline text. Ex: "hello\nfriend")
"en": "English",
"de": "Deutsch"
},
"wp_type": "Tile", // Windows Phone notification type. 'Tile' or 'Toast'. Raw notifications are not supported. 'Tile' is default.
"wp_background": "/Resources/Red.jpg", // optional, tile image
"wp_backbackground": "/Resources/Green.jpg", // optional, back tile image
"wp_backtitle": "back title", // optional, back tile title
"wp_backcontent": "back content", // optional, back tile content
"wp_count": 3 // optional, integer. Badge for Windows Phone notification.
}]
}
}
Mac OS X
{
"request": {
"application": "12345-67891", // required. Pushwoosh application code
"auth": "yxoPUlwqm…………pIyEX4H", // required. API access token from Pushwoosh Control Panel
"notifications": [{
// Content settings
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
"content": { // required, object( language1: 'content1', language2: 'content2' ) OR string. Ignored for Windows 8, use "wns_content" instead. (Use \n for multiline text. Ex: "hello\nfriend")
"en": "English",
"de": "Deutsch"
},
"mac_badges": 3, // optional
"mac_sound": "sound.caf", // optional
"mac_root_params": { // optional
"content-available": 1
},
"mac_ttl": 3600 // optional. Time to live parameter — maximum message lifespan in seconds.
}]
}
}
Windows
{
"request": {
"application": "12345-67891", // required. Pushwoosh application code
"auth": "yxoPUlwqm…………pIyEX4H", // required. API access token from Pushwoosh Control Panel
"notifications": [{
// Content settings
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
"content": { // required, object( language1: 'content1', language2: 'content2' ) OR string. Ignored for Windows 8, use "wns_content" instead. (Use \n for multiline text. Ex: "hello\nfriend")
"en": "English",
"de": "Deutsch"
},
"wns_content": { // Content (XML or raw) of notification encoded in MIME's base64 in form of Object( language1: 'content1', language2: 'content2' ) OR String
"en": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48YmFkZ2UgdmFsdWU9ImF2YWlsYWJsZSIvPg==",
"de": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48YmFkZ2UgdmFsdWU9Im5ld01lc3NhZ2UiLz4="
},
"wns_type": "Badge", // 'Tile' | 'Toast' | 'Badge' | 'Raw'
"wns_tag": "myTag", // optional. Used in Tile replacement policy. An alphanumeric string of no more than 16 characters.
"wns_cache": 1, // optional. (1|0) Translates into X-WNS-Cache-Policy value.
"wns_ttl": 600 // optional. Expiration time for notification in seconds.
}]
}
}
SMS
{
"request": {
"application": "12345-67891", // required. Pushwoosh application code
"auth": "yxoPUlwqm…………pIyEX4H", // required. API access token from Pushwoosh Control Panel
"notifications": [{
// Content settings
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
"content": "Hello!", // required. SMS text (string)
"devices":["+1234567890"], // required. Customer phone number (must be associated with a UserId using /registerDevice and specified in the "hwid" parameter). Only one number can be specified here
"platforms":[18] // optional. Platform number
}]
}
}
PHP-Pushwoosh library by Gomoob:
http://gomoob.github.io/php-pushwoosh/
http://gomoob.github.io/php-pushwoosh/create-message.html
Python library by Pushwoosh:
Node JS client
Keep in mind that non-enterprise accounts cannot send more than 600
/createMessage
and/or /createTargetedMessage
requests per minute.However, if you send pushes via the devices parameter to 10 devices or less, there are no restrictions for any account type as long as API messaging tracing is disabled.
Note that we always save scheduled pushes to the Message History, even if you are sending them to less than 10 devices via devices parameter. Therefore, such pushes are also throttled.
Response:
HTTP Status code | status_code | Description |
200 | 200 | Message successfully created |
200 | 210 | Argument error. See status_message for more info |
400 | N/A | Malformed request string |
500 | 500 | Internal error |
If the
createMessage
request has several messages in the notifications
array, they will be processed and sent one by one. If one of the messages cannot be parsed, our API will return "status_code":210
with the codes of successfully sent messages, i.e. those preceding the faulty message in the request.For load balancing purposes, we do not store messages sent through API with the “devices” parameter that contains less than 10 devices in an array. Due to this, such messages will not be displayed in your Message History.
To see push reports during the testing phase, use API messaging tracing. Turning this option ON allows you to override this limit for 1 hour and save such pushes in the Message History. API messaging tracing turns OFF automatically after 1 hour.
API messaging tracing can be activated on the Message History page by clicking Start API messaging tracing in the upper right corner.
If API messaging tracing is turned OFF, and you send a
createMessage
request with less than 10 device tokens to Pushwoosh API, the server will return a “CODE_NOT_AVAILABLE”
value for “Messages”
, and an empty key for Unknown Devices instead of Message Code unless the message is scheduled to be sent in the future with the "send_date"
parameter.Each tag condition is an array like
[tagName, operator, operand]
where- tagName: name of a tag
- operator: "EQ" | "IN" | "NOTEQ" | "NOTIN" | "LTE" | "GTE" | "BETWEEN" | "NOTSET" | "ANY"
- operand: string | integer | array | date
- EQ: tag value is equal to operand;
- IN: tag value intersects with operand (operand must always be an array);
- NOTEQ: tag value is not equal to an operand;
- NOTIN: tag value does not intersect with operand (operand must always be an array);
- GTE: tag value is greater than or equal to operand;
- LTE: tag value is less than or equal to operand;
- BETWEEN: tag value is greater than or equal to min operand value but less than or equal to max operand value (operand must always be an array);
- NOTSET: tag not set. Operand is not considered;
- ANY: tag has any value. Operand is not considered.
Valid operators: EQ, IN, NOTEQ, NOTIN, NOTSET, ANY
Valid operands:
- EQ, NOTEQ: operand must be a string;
- IN, NOTIN: operand must be an array of strings like
["value 1", "value 2", "value N"]
; - NOTSET: tag not set. Operand is not considered;
- ANY: tag has any value. Operand is not considered.
Valid operators: EQ, IN, NOTEQ, NOTIN, BETWEEN, GTE, LTE, NOTSET, ANY
Valid operands:
- EQ, NOTEQ, GTE, LTE: operand must be an integer;
- IN, NOTIN: operand must be an array of integers like
[value 1, value 2, value N]
; - BETWEEN: operand must be an array of integers like
[min_value, max_value]
; - NOTSET: tag not set. Operand is not considered;
- ANY: tag has any value. Operand is not considered.
Valid operators: EQ, IN, NOTEQ, NOTIN, BETWEEN, GTE, LTE, NOTSET, ANY
Valid operands:
"YYYY-MM-DD 00:00"
(string)- unix timestamp
1234567890
(integer) "N days ago"
(string) for operators EQ, BETWEEN, GTE, LTE
Valid operators: EQ, NOTSET, ANY
Valid operands:
0, 1, true, false
Valid operators: IN, NOTIN, NOTSET, ANY
Valid operands: operand must be an array of strings like
["value 1", "value 2", "value N"]
.Remember that “filter” and “conditions” parameters should not be used together.
Also, both of them will be ignored, if the "devices" parameter is used in the same request.
Language tag value is a lowercase two-letter code according to ISO-639-1
Country tag value is an UPPERCASE two-letter code according to ISO_3166-2
For example, to send push a notification to Portuguese-speaking subscribers in Brazil, you will need to specify the following condition:
"conditions": [["Country", "EQ", "BR"],["Language", "EQ", "pt"]]
Sample
/createMessage
requests:Bash
PHP
Erlang
Ruby
Java
Python
.NET
Go
JavaScript
#!/bin/bash
#Usage
if [ ! -n "$1" ] || [ ! -n "$2" ]
then
echo "`basename $0` usage: api_token appid message";
exit 1;
fi;
MESSAGE="$3";
if [ -z "$3" ]
then
MESSAGE='One push to rule them all!'
fi;
echo -e "Response:"
curl --data-binary "
{\"request\":
{\"application\":\"$2\",
\"auth\":\"$1\",
\"notifications\":
[{
\"send_date\": \"now\",
\"content\": \"$MESSAGE\"
}]
}
}" \
-H "Content-type: application/json" \
"https://api.pushwoosh.com/json/1.3/createMessage"
echo "";
exit 0;
<?php
define('PW_AUTH', 'API TOKEN');
define('PW_APPLICATION', 'APPLICATION CODE');
define('PW_DEBUG', true);
function pwCall($method, $data) {
$url = 'https://api.pushwoosh.com/json/1.3/' . $method;
$request = json_encode(['request' => $data]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if (defined('PW_DEBUG') && PW_DEBUG) {
print "[PW] request: $request\n";
print "[PW] response: $response\n";
print '[PW] info: ' . print_r($info, true);
}
}
pwCall('createMessage', array(
'application' => PW_APPLICATION,
'auth' => PW_AUTH,
'notifications' => array(
array(
'send_date' => 'now',
'content' => 'test',
'data' => array('custom' => 'json data'),
'link' => 'http://pushwoosh.com/'
)
)
)
);
-module(pushwoosh).
-export([run/0, stop/0, sendMessage/1]).
%% sendMessage argument: message text %%
%% Authentication & App_id %%
-define(PW_AUTH, "YOUR_AUTH_TOKEN").
-define(PW_APPLICATION, "YOUR_PUSHWOOSH_APP_CODE").
%% KickStart %%
run() ->
application:start(unicode),
application:start(crypto),
application:start(public_key),
application:start(ssl),
application:start(inets),
%% HTTP Client verbosity options flase, verbose, debug
httpc:set_options([{verbose, false}]).
stop() ->
application:stop(ssl),
application:stop(public_key),
application:stop(crypto),
application:stop(inets).
%% JSON Wars !
encode(S) -> encode(S, [$"]).
encode([], Acc) -> lists:reverse([$" | Acc]);
encode([C | Cs], Acc) ->
Hex = lists:flatten(io_lib:format("~4.16.0b", [C])),
encode(Cs, lists:reverse(Hex) ++ "u\\" ++ Acc).
sendMessage(Message_text) ->
%% URL to JSON API 1.3
Url = "https://api.pushwoosh.com/json/1.3/createMessage",
EncodedMessage = encode(Message_text),
{ok, Response} = httpc:request(
%%Method
post,
%%Request
{Url, [{"User-Agent", "Erlang exemple"}], "application/json; charset=UTF-8",
"{\"request\":{
\"application\": \""?PW_APPLICATION"\",
\"auth\": \""?PW_AUTH"\",
\"notifications\": [{
\"send_date\": \"now\",
\"content\": "++EncodedMessage++"
}]}}"},
%%HTTP options
[{ssl,[{verify, verify_none}]}, {version, "HTTP/1.0"}],
%%Options
[]),
io:format("And received ~p", [Response]).
class PushNotification
#- PushWoosh API Documentation http://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/
#- Two methods here:
# - PushNotification.new.notify_all(message) Notifies all with the same option
# - PushNotification.new.notify_devices(notification_options = {}) Notifies specific devices with custom options
include HTTParty #Make sure to have the HTTParty gem declared in your gemfile https://github.com/jnunemaker/httparty
default_params :output => 'json'
format :json
def initialize
#- Change to your settings
@auth = {:application => "00000-00000",:auth => "auth_token"}
end
# PushNotification.new.notify_all("This is a test notification to all devices")
def notify_all(message)
notify_devices({:content => message})
end
# PushNotification.new.notify_device({
# :content => "TEST",
# :data => {:custom_data => value},
# :devices => array_of_tokens
#})
def notify_devices(notification_options = {})
#- Default options, uncomment :data or :devices if needed
default_notification_options = {
# YYYY-MM-DD HH:mm OR 'now'
:send_date => "now",
# Object( language1: 'content1', language2: 'content2' ) OR string
:content => {
:fr => "Test",
:en => "Test"
},
# JSON string or JSON object "custom": "json data"
#:data => {
# :custom_data => value
#},
# omit this field (push notification will be delivered to all the devices for the application), or provide the list of devices IDs
#:devices => {}
}
#- Merging with specific options
final_notification_options = default_notification_options.merge(notification_options)
#- Constructing the final call
options = @auth.merge({:notifications => [final_notification_options]})
options = {:request => options}
#- Executing the POST API Call with HTTPARTY - :body => options.to_json allows us to send the json as an object instead of a string
response = self.class.post("https://api.pushwoosh.com/json/1.3/createMessage", :body => options.to_json,:headers => { 'Content-Type' => 'application/json' })
end
end
// Uses JSON classes from http://json.org/java/
package com.arellomobile;
import org.json.*;
import java.io.*;
import java.net.*;
public class SendPushNotificationSample
{
public static final String PUSHWOOSH_SERVICE_BASE_URL = "https://api.pushwoosh.com/json/1.3/";
private static final String AUTH_TOKEN = "YOUR_AUTH_TOKEN";
private static final String APPLICATION_CODE = "PW_APPLICATION_CODE";
public static void main(String[] args) throws JSONException, MalformedURLException
{
String method = "createMessage";
URL url = new URL(PUSHWOOSH_SERVICE_BASE_URL + method);
JSONArray notificationsArray = new JSONArray()
.put(new JSONObject().put("send_date", "now")
.put("content", "test")
.put("link", "http://pushwoosh.com/"));
JSONObject requestObject = new JSONObject()
.put("application", APPLICATION_CODE)
.put("auth", AUTH_TOKEN)
.put("notifications", notificationsArray);
JSONObject mainRequest = new JSONObject().put("request", requestObject);