Messages
API methods to manage push messages
To get started with Pushwoosh Remote API, please check out the descriptions of the /createMessage request parameters.

createMessage

post
https://cp.pushwoosh.com/json/1.3
/createMessage
/createMessage
/createMessage method supports content templates. To learn more, please refer to the Liquid Templates guide.

Request example

Example
1
{
2
"request": {
3
"application": "XXXXX-XXXXX", // Pushwoosh application code
4
"applications_group": "GROUP_CODE", // optional. Can be used instead of "application".
5
"auth": "yxoPUlwqm…………pIyEX4H", // API access token from Pushwoosh Control Panel
6
"notifications": [
7
{
8
// Content settings
9
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
10
"ignore_user_timezone": true, // or false, required
11
"timezone": "America/New_York", // optional. If ignored UTC-0 is default for "send_date". See http://php.net/manual/timezones.php for supported timezones.
12
"campaign": "CAMPAIGN_CODE", // optional. Campaign code to which you want to assign this push message.
13
"geozone": { // optional, send to Geozone
14
"lat": 22.22,
15
"lng": 33.33,
16
"range": 110
17
},
18
"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")
19
"en": "English",
20
"ru": "Русский",
21
"de": "Deutsch"
22
},
23
"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).
24
"en": "Title",
25
"ru": "Заголовок"
26
},
27
"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).
28
"en": "Subtitle",
29
"ru": "Подзаголовок"
30
},
31
"page_id": 39, // optional, integer. HTML Page ID.
32
"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.
33
"remote_page": "http://myremoteurl.com", // optional, string. Remote Rich HTML Page URL. <scheme>://<authority>
34
"link": "http://google.com", // optional, string. For deeplinks add "minimize_link":0
35
"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.
36
"data": {
37
"key": "value" // optional, JSON string or JSON object, will be passed as "u" parameter in the payload (converted to JSON string).
38
},
39
"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 1 day.
40
"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
41
"preset": "Q1A2Z-6X8SW", // optional. Push Preset Code from your Control Panel.
42
"send_rate": 100, // optional. Throttling. Valid values are from 100 to 1000 pushes/second.
43
44
// Templating related, please refer to the Template Engine guide to learn more
45
"use_template" : true, // optional. Default 'false'
46
"template_bindings" : {
47
"TemplatePlaceholder" : "Value"
48
},
49
50
// Frequency capping params
51
"capping_days": 30, // Amount of days for frequency capping (max 30 days)
52
"capping_count": 10, // 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.
53
54
// 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.
55
"inbox_date": "2017-02-02", // optional. Specify when to remove a message from the Inbox. If not specified, the default removal date is the next day after the send date.
56
"inbox_image": "Inbox image URL", // optional. The image to be shown near the message.
57
"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.
58
"dec301908b9ba8df85e57a58e40f96f523f4c2068674f5fe2ba25cdc250a2a41"
59
],
60
61
// user-centric push notifications
62
"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.
63
"user_3078a"
64
],
65
66
//filters and conditions
67
"filter": "FILTER_NAME", // optional
68
"dynamic_content_placeholders": { // optional. Placeholders for dynamic content instead of device tags.
69
"firstname": "John",
70
"lastname": "Doe"
71
},
72
"conditions": [TAG_CONDITION1, TAG_CONDITION2, ..., TAG_CONDITIONN], // optional. See the remark below.
73
"conditions_operator": "AND" // optional, logical operator for conditions arrays. Possible values: AND | OR. AND is default.
74
}
75
]
76
}
77
}
Copied!

Platform-specific parameters

iOS

Example
1
{
2
"request": {
3
"application": "12345-67891", // Pushwoosh application code
4
"auth": "yxoPUlwqm…………pIyEX4H", // API access token from Pushwoosh Control Panel
5
"notifications": [{
6
// Content settings
7
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
8
"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")
9
"en": "English",
10
"de": "Deutsch"
11
},
12
13
"ios_badges": 5, // optional, integer. iOS application badge number. Use "+n" or "-n" to increment/decrement the badge value by n.
14
"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.
15
"ios_ttl": 3600, // optional. Time to live parameter - maximum message lifespan in seconds.
16
"ios_silent": 1, // optional. Enables silent notifications (ignore "sound" and "content").
17
"ios_category_id": "1", // optional, string. iOS8 category ID from Pushwoosh.
18
"ios_root_params": { // optional. Root level parameters to the aps dictionary.
19
"aps": {
20
"content-available": "1",
21
"mutable-content": 1 // required for iOS 10 Media attachments.
22
},
23
"data": <<User supplied data, max of 4KB>>
24
},
25
"apns_trim_content": 1, // optional. (0|1) Trims the exceeding content strings with ellipsis.
26
"ios_trim_content": 1, // Deprecated, use "apns_trim_content" instead.
27
"ios_attachment" : "YOUR_ATTACHMENT_MEDIA_URL", // optional. Insert media content in notification.
28
"ios_title": "Title", // optional. Adds Title for push notification.
29
"ios_subtitle": "SubTitle", // optional. Adds sub-title for push notification.
30
"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.
31
"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.
32
"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.
33
}]
34
}
35
}
Copied!

Android

Example
1
{
2
"request": {
3
"application": "12345-67891", // Pushwoosh application code
4
"auth": "yxoPUlwqm…………pIyEX4H", // API access token from Pushwoosh Control Panel
5
"notifications": [{
6
// Content settings
7
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
8
"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")
9
"en": "English",
10
"de": "Deutsch"
11
},
12
13
"android_root_params": {
14
"key": "value"
15
}, // optional. Custom key-value object. Root level parameters for the android payload recipients.
16
"android_sound": "soundfile", // optional. No file extension. If left empty, the device will produce no sound upon receiving a push.
17
"android_header": "header", // optional. Android notification header.
18
"android_icon": "icon.png",
19
"android_custom_icon": "http://example.com/image.png", // optional. Full path URL to the image file.
20
"android_banner": "http://example.com/banner.png", // optional. Full path URL to the image file.
21
"android_badges": 5, // optional, integer. Android application icon badge number. Use "+n" or "-n" to increment/decrement the badge value by n.
22
"android_gcm_ttl": 3600, // optional. Time to live parameter — maximum message lifespan in seconds.
23
"android_vibration": 0, // boolean. Android force-vibration for high-priority pushes.
24
"android_led": "#rrggbb", // LED hex color, device will do its best approximation.
25
"android_priority": -1, // 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.
26
"android_delivery_priority": "normal", // or "high", optional. Enables notification’s delivery when the device is in the power saving mode.
27
"android_ibc": "#RRGGBB", // icon background color on Lollipop, #RRGGBB, #AARRGGBB, "red", "black", "yellow", etc.
28
"android_silent": 1 // optional. 0 or 1, enable silent notificaiton (ignore sound and content).
29
}]
30
}
31
}
Copied!

Safari

Safari
1
{
2
"request": {
3
"application": "12345-67891", // Pushwoosh application code
4
"auth": "yxoPUlwqm…………pIyEX4H", // API access token from Pushwoosh Control Panel
5
"notifications": [{
6
// Content settings
7
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
8
"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")
9
"en": "English",
10
"de": "Deutsch"
11
},
12
13
"safari_title": "Title", // obligatory. Title of the notification.
14
"safari_action": "Click here", // optional
15
"safari_url_args": ["firstArgument", "secondArgument"], // obligatory, but the value may be empty
16
"safari_ttl": 3600 // optional. Time to live parameter — the maximum lifespan of a message in seconds.
17
}]
18
}
19
}
20
21
Copied!

Chrome parameters

Chrome
1
{
2
"request": {
3
"application": "12345-67891", // Pushwoosh application code
4
"auth": "yxoPUlwqm…………pIyEX4H", // API access token from Pushwoosh Control Panel
5
"notifications": [{
6
// Content settings
7
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
8
"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")
9
"en": "English",
10
"de": "Deutsch"
11
},
12
13
"chrome_title": "Title", // optional. You can specify the header of the message in this parameter.
14
"chrome_icon": "icon_URL", // full path URL to the icon or extension resources file path
15
"chrome_gcm_ttl": 3600, // optional. Time to live parameter – maximum message lifespan in seconds.
16
"chrome_duration": 20, // optional. max. 50 seconds. Changes chrome push display time. Set to 0 to display push until user interacts with it.
17
"chrome_image": "image_URL", // optional. URL to large image.
18
"chrome_root_params": {
19
"key": "value"
20
}, // optional. Set parameters specific to messages sent to Chrome.
21
"chrome_button_text1": "1", // optional
22
"chrome_button_url1": "button1_URL", // optional. Ignored if chrome_button_text1 is not set.
23
"chrome_button_text2": "2", // optional
24
"chrome_button_url2": "button2_url" // optional. Ignored if chrome_button_text2 is not set.
25
}]
26
}
27
}
Copied!

Firefox parameters

Firefox
1
{
2
"request": {
3
"application": "12345-67891", // Pushwoosh application code
4
"auth": "yxoPUlwqm…………pIyEX4H", // API access token from Pushwoosh Control Panel
5
"notifications": [{
6
// Content settings
7
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
8
"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")
9
"en": "English",
10
"de": "Deutsch"
11
},
12
13
"firefox_title": "Title", // optional. You can specify message header here.
14
"firefox_icon": "icon_URL", // full path URL to the icon or path to the file in extension resources.
15
"firefox_root_params": {
16
"key": "value"
17
} // optional. Set parameters specific to messages sent to Firefox.
18
}]
19
}
20
}
Copied!

Amazon parameters

Amazon
1
{
2
"request": {
3
"application": "12345-67891", // Pushwoosh application code
4
"auth": "yxoPUlwqm…………pIyEX4H", // API access token from Pushwoosh Control Panel
5
"notifications": [{
6
// Content settings
7
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
8
"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")
9
"en": "English",
10
"de": "Deutsch"
11
},
12
13
"adm_root_params": {
14
"key": "value"
15
}, // custom key-value object
16
"adm_sound": "push.mp3",
17
"adm_header": "Header",
18
"adm_icon": "icon",
19
"adm_custom_icon": "http://example.com/image.png",
20
"adm_banner": "http://example.com/banner.png",
21
"adm_ttl": 3600, // optional. Time to live parameter — the maximum message lifespan in seconds.
22
"adm_priority": -1 // priority of the push in Amazon push drawer, valid values are -2, -1, 0, 1 and 2.
23
}]
24
}
25
}
Copied!

Windows Phone parameters

Windows Phone
1
{
2
"request": {
3
"application": "12345-67891", // Pushwoosh application code
4
"auth": "yxoPUlwqm…………pIyEX4H", // API access token from Pushwoosh Control Panel
5
"notifications": [{
6
// Content settings
7
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
8
"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")
9
"en": "English",
10
"de": "Deutsch"
11
},
12
13
"wp_type": "Tile", // Windows Phone notification type. 'Tile' or 'Toast'. Raw notifications are not supported. 'Tile' is default.
14
"wp_background": "/Resources/Red.jpg", // tile image
15
"wp_backbackground": "/Resources/Green.jpg", // back tile image
16
"wp_backtitle": "back title", // back tile title
17
"wp_backcontent": "back content", // back tile content
18
"wp_count": 3 // optional, integer. Badge for Windows Phone notification.
19
}]
20
}
21
}
Copied!

Mac OS X parameters

Mac OS X
1
{
2
"request": {
3
"application": "12345-67891", // Pushwoosh application code
4
"auth": "yxoPUlwqm…………pIyEX4H", // API access token from Pushwoosh Control Panel
5
"notifications": [{
6
// Content settings
7
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
8
"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")
9
"en": "English",
10
"de": "Deutsch"
11
},
12
13
"mac_badges": 3,
14
"mac_sound": "sound.caf",
15
"mac_root_params": {
16
"content-available": 1
17
},
18
"mac_ttl": 3600 // optional. Time to live parameter — maximum message lifespan in seconds.
19
}]
20
}
21
}
Copied!

Windows parameters

Windows
1
{
2
"request": {
3
"application": "12345-67891", // Pushwoosh application code
4
"auth": "yxoPUlwqm…………pIyEX4H", // API access token from Pushwoosh Control Panel
5
"notifications": [{
6
// Content settings
7
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
8
"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")
9
"en": "English",
10
"de": "Deutsch"
11
},
12
13
"wns_content": { // Content (XML or raw) of notification encoded in MIME's base64 in form of Object( language1: 'content1', language2: 'content2' ) OR String
14
"en": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48YmFkZ2UgdmFsdWU9ImF2YWlsYWJsZSIvPg==",
15
"de": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48YmFkZ2UgdmFsdWU9Im5ld01lc3NhZ2UiLz4="
16
},
17
"wns_type": "Badge", // 'Tile' | 'Toast' | 'Badge' | 'Raw'
18
"wns_tag": "myTag", // optional. Used in Tile replacement policy. An alphanumeric string of no more than 16 characters.
19
"wns_cache": 1, // optional. (1|0) Translates into X-WNS-Cache-Policy value.
20
"wns_ttl": 600 // optional. Expiration time for notification in seconds.
21
}]
22
}
23
}
Copied!

Huawei parameters

1
{
2
"request": {
3
"application": "12345-67891", // Pushwoosh application code
4
"auth": "yxoPUlwqm…………pIyEX4H", // API access token from Pushwoosh Control Panel
5
"notifications": [{
6
// Content settings
7
"send_date": "now", // required. YYYY-MM-DD HH:mm OR 'now'
8
"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")
9
"en": "English",
10
"de": "Deutsch"
11
},
12
13
"huawei_android_badges": true, // boolean
14
"huawei_android_silent": 0, // 0 or 1, enable silent notificaiton (ignore sound and content).
15
"huawei_android_icon": "http://example.com/icon.png",
16
"huawei_android_led": "#FF0011", // LED hex color, device will do its best approximation.
17
"huawei_android_vibration": 1, // boolean. Huawei force-vibration for high-priority pushes.
18
"huawei_android_sound": "sound.wav", // optional. No file extension. If left empty, the device will produce no sound upon receiving a push.
19
"huawei_android_sound_off": true,
20
"huawei_android_custom_icon": "http://example.com/custom_icon.png",
21
"huawei_android_header": "Huawei Header", // string. Notification title.
22
"huawei_android_gcm_ttl": 2400, // integer. Time to live parameter - maximum message lifespan in seconds.
23
"huawei_android_banner": "http://example.com/banner.png", // Full path URL to the image file.
24
"huawei_android_root_params": { // Custom key-value object. Root level parameters for the Huawei payload recipients.
25
"key": "value"
26
},
27
"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.
28
"huawei_android_ibc": "#0011AA", // icon background color on Lollipop, #RRGGBB, #AARRGGBB, "red", "black", "yellow", etc.
29
"huawei_android_lockscreen": 1,
30
"huawei_android_delivery_priority": "normal" // or "high", optional. Enables notification’s delivery when the device is in the power saving mode.
31
}]
32
}
33
}
Copied!

/createMessage Throttling

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 the debug mode 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

An error in an array of notifications

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.

Debug Mode

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, there’s Debug Mode. Turning Debug Mode ON allows you to override this limit for 1 hour and save such pushes in the Message History. Debug mode turns OFF automatically after 1 hour.
Debug Mode can be activated on the Message History page by switching the toggle in the upper right corner.
If the Debug Mode 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.

Tag conditions

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

Operator description

  • 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.

String tags

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.

Integer tags

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.

Date tags

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

Boolean tags

Valid operators: EQ, NOTSET, ANY Valid operands: 0, 1, true, false

List tags

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.

Country and Language tags

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

/createMessage snippets

Important!

Please be careful when using the snippets. Limit the number of recipients by specifying “users”, “devices”, “filter”, or “conditions” parameter. If none of these parameters is specified, the message will be sent to every device subscribed to push notifications from the application.
Sample /createMessage requests:
Bash
PHP
Erlang
Ruby
Java
Python
.NET
Go
JavaScript
1
#!/bin/bash
2
3
#Usage
4
if [ ! -n "$1" ] || [ ! -n "$2" ]
5
then
6
echo "`basename $0` usage: api_token appid message";
7
exit 1;
8
fi;
9
MESSAGE="$3";
10
if [ -z "$3" ]
11
then
12
MESSAGE='One push to rule them all!'
13
fi;
14
15
echo -e "Response:"
16
curl --data-binary "
17
{\"request\":
18
{\"application\":\"$2\",
19
\"auth\":\"$1\",
20
\"notifications\":
21
[{
22
\"send_date\": \"now\",
23
\"content\": \"$MESSAGE\"
24
}]
25
}
26
}" \
27
-H "Content-type: application/json" \
28
"https://cp.pushwoosh.com/json/1.3/createMessage"
29
echo "";
30
exit 0;
Copied!
1
<?php
2
define('PW_AUTH', 'API TOKEN');
3
define('PW_APPLICATION', 'APPLICATION CODE');
4
define('PW_DEBUG', true);
5
6
function pwCall($method, $data) {
7
$url = 'https://cp.pushwoosh.com/json/1.3/' . $method;
8
$request = json_encode(['request' => $data]);
9
10
$ch = curl_init($url);
11
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
12
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
13
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
14
curl_setopt($ch, CURLOPT_HEADER, true);
15
curl_setopt($ch, CURLOPT_POST, true);
16
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
17
18
$response = curl_exec($ch);
19
$info = curl_getinfo($ch);
20
curl_close($ch);
21
22
if (defined('PW_DEBUG') && PW_DEBUG) {
23
print "[PW] request: $request\n";
24
print "[PW] response: $response\n";
25
print '[PW] info: ' . print_r($info, true);
26
}
27
}
28
29
pwCall('createMessage', array(
30
'application' => PW_APPLICATION,
31
'auth' => PW_AUTH,
32
'notifications' => array(
33
array(
34
'send_date' => 'now',
35
'content' => 'test',
36
'data' => array('custom' => 'json data'),
37
'link' => 'http://pushwoosh.com/'
38
)
39
)
40
)
41
);
Copied!
1
-module(pushwoosh).
2
-export([run/0, stop/0, sendMessage/1]).
3
%% sendMessage argument: message text %%
4
5
%% Authentication & App_id %%
6
-define(PW_AUTH, "YOUR_AUTH_TOKEN").
7
-define(PW_APPLICATION, "YOUR_PUSHWOOSH_APP_CODE").
8
9
%% KickStart %%
10
run() ->
11
application:start(unicode),
12
application:start(crypto),
13
application:start(public_key),
14
application:start(ssl),
15
application:start(inets),
16
%% HTTP Client verbosity options flase, verbose, debug
17
httpc:set_options([{verbose, false}]).
18
stop() ->
19
application:stop(ssl),
20
application:stop(public_key),
21
application:stop(crypto),
22
application:stop(inets).
23
%% JSON Wars !
24
encode(S) -> encode(S, [quot;]).
25
encode([], Acc) -> lists:reverse([quot; | Acc]);
26
encode([C | Cs], Acc) ->
27
Hex = lists:flatten(io_lib:format("~4.16.0b", [C])),
28
encode(Cs, lists:reverse(Hex) ++ "u\\" ++ Acc).
29
30
sendMessage(Message_text) ->
31
%% URL to JSON API 1.3
32
Url = "https://cp.pushwoosh.com/json/1.3/createMessage",
33
EncodedMessage = encode(Message_text),
34
{ok, Response} = httpc:request(
35
%%Method
36
post,
37
%%Request
38
{Url, [{"User-Agent", "Erlang exemple"}], "application/json; charset=UTF-8",
39
"{\"request\":{
40
\"application\": \""?PW_APPLICATION"\",
41
\"auth\": \""?PW_AUTH"\",
42
\"notifications\": [{
43
\"send_date\": \"now\",
44
\"content\": "++EncodedMessage++"
45
}]}}"},
46
%%HTTP options
47
[{ssl,[{verify, verify_none}]}, {version, "HTTP/1.0"}],
48
%%Options
49
[]),
50
io:format("And received ~p", [Response]).
Copied!
1
class PushNotification
2
3
#- PushWoosh API Documentation http://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/
4
#- Two methods here:
5
# - PushNotification.new.notify_all(message) Notifies all with the same option
6
# - PushNotification.new.notify_devices(notification_options = {}) Notifies specific devices with custom options
7
8
include HTTParty #Make sure to have the HTTParty gem declared in your gemfile https://github.com/jnunemaker/httparty
9
default_params :output => 'json'
10
format :json
11
12
def initialize
13
#- Change to your settings
14
@auth = {:application => "00000-00000",:auth => "auth_token"}
15
end
16
17
# PushNotification.new.notify_all("This is a test notification to all devices")
18
def notify_all(message)
19
notify_devices({:content => message})
20
end
21
22
# PushNotification.new.notify_device({
23
# :content => "TEST",
24
# :data => {:custom_data => value},
25
# :devices => array_of_tokens
26
#})
27
def notify_devices(notification_options = {})
28
#- Default options, uncomment :data or :devices if needed
29
default_notification_options = {
30
# YYYY-MM-DD HH:mm OR 'now'
31
:send_date => "now",
32
# Object( language1: 'content1', language2: 'content2' ) OR string
33
:content => {
34
:fr => "Test",
35
:en => "Test"
36
},
37
# JSON string or JSON object "custom": "json data"
38
#:data => {
39
# :custom_data => value
40
#},
41
# omit this field (push notification will be delivered to all the devices for the application), or provide the list of devices IDs
42
#:devices => {}
43
}
44
45
#- Merging with specific options
46
final_notification_options = default_notification_options.merge(notification_options)
47
48
#- Constructing the final call
49
options = @auth.merge({:notifications => [final_notification_options]})
50
options = {:request => options}
51
#- Executing the POST API Call with HTTPARTY - :body => options.to_json allows us to send the json as an object instead of a string
52
response = self.class.post("https://cp.pushwoosh.com/json/1.3/createMessage", :body => options.to_json,:headers => { 'Content-Type' => 'application/json' })
53
end
54
end
Copied!
1
// Uses JSON classes from http://json.org/java/
2
3
package com.arellomobile;
4
5
import org.json.*;
6
import java.io.*;
7
import java.net.*;
8
9
public class SendPushNotificationSample
10
{
11
public static final String PUSHWOOSH_SERVICE_BASE_URL = "https://cp.pushwoosh.com/json/1.3/";
12
private static final String AUTH_TOKEN = "YOUR_AUTH_TOKEN";
13
private static final String APPLICATION_CODE = "PW_APPLICATION_CODE";
14
15
public static void main(String[] args) throws JSONException, MalformedURLException
16
{
17
String method = "createMessage";
18
URL url = new URL(PUSHWOOSH_SERVICE_BASE_URL + method);
19
20
JSONArray notificationsArray = new JSONArray()
21
.put(new JSONObject().put("send_date", "now")
22
.put("content", "test")
23
.put("link", "http://pushwoosh.com/"));
24
25
JSONObject requestObject = new JSONObject()
26
.put("application", APPLICATION_CODE)
27
.put("auth", AUTH_TOKEN)
28
.put("notifications", notificationsArray);
29
30
JSONObject mainRequest = new JSONObject().put("request", requestObject);
31
JSONObject response = SendServerRequest.sendJSONRequest(url, mainRequest.toString());
32
33
System.out.println("Response is: " + response);
34
}
35
}
36
37
class SendServerRequest
38
{
39
static JSONObject sendJSONRequest(URL url, String request)
40
{
41
HttpURLConnection connection = null;
42
try
43
{
44
connection = (HttpURLConnection) url.openConnection();
45
connection.setRequestMethod("POST");
46
connection.setRequestProperty("Content-Type", "application/json");
47
connection.setDoInput(true);
48
connection.setDoOutput(true);
49
50
DataOutputStream writer = new DataOutputStream(connection.getOutputStream());
51
writer.write(request.getBytes("UTF-8"));
52
writer.flush();
53
writer.close();
54
55
return parseResponse(connection);
56
}
57
catch (Exception e)
58
{
59
System.out.println("An error occurred: " + e.getMessage());
60
return null;
61
}
62
finally
63
{
64
if (connection != null)
65
{
66
connection.disconnect();
67
}
68
}
69
}
70
71
static JSONObject parseResponse(HttpURLConnection connection) throws IOException, JSONException
72
{
73
String line;
74
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
75
StringBuilder response = new StringBuilder();
76
77
while ((line = reader.readLine()) != null)
78
{
79
response.append(line).append('\r');
80
}
81
reader.close();
82
83
return new JSONObject(response.toString());
84
}
85
}
Copied!
1
import json
2
3
PW_AUTH = 'API TOKEN'
4
PW_APPLICATION_CODE = 'APPLICATION CODE'
5
6
try:
7
# For Python 3.0 and later
8
from urllib.request import urlopen
9
from urllib.request import Request
10
except ImportError:
11
# Fall back to Python 2's urllib2
12
from urllib2 import urlopen
13
from urllib2 import Request
14
15
def pw_call(method, data):
16
url = 'https://cp.pushwoosh.com/json/1.3/' + method
17
data = json.dumps({'request': data})
18
req = Request(url, data.encode('UTF-8'), {'Content-Type': 'application/json'})
19
try:
20
f = urlopen(req)
21
response = f.read()
22
f.close()
23
print('Pushwoosh response: ' + str(response))
24
except Exception as e:
25
print ('Request error: ' + str(e))
26
27
if __name__ == '__main__':
28
pw_call('createMessage', {
29
'auth': PW_AUTH,
30
'application': PW_APPLICATION_CODE,
31
'notifications': [
32
{
33
'send_date': 'now',
34
'content': 'test',
35
'data': {"custom": "json data"},
36
'link': 'http://pushwoosh.com'
37
}
38
]
39
}
40
)
Copied!
1
using System;
2
using System.IO;
3
using System.Net;
4
using Newtonsoft.Json.Linq;
5
6
namespace WebApplication1
7
{
8
public partial class Default : System.Web.UI.Page
9
{
10
protected void Page_Load(object sender, EventArgs e)
11
{
12
string pwAuth = "YOUR_AUTH_TOKEN";
13
string pwApplication = "PW_APPLICATION_CODE";
14
JObject json = new JObject(
15
new JProperty("application", pwApplication),
16
new JProperty("auth", pwAuth),
17
new JProperty("notifications",
18
new JArray(
19
new JObject(
20
new JProperty("send_date", "now"),
21
new JProperty("content", "test"),
22
new JProperty("wp_type", "Toast"),
23
new JProperty("wp_count", 3),
24
new JProperty("data",
25
new JObject(
26
new JProperty("custom", "json data"))),
27
new JProperty("link", "http://pushwoosh.com/"),
28
new JProperty("conditions",
29
new JArray(
30
(object)new JArray("Color", "EQ", "black")))))));
31
PWCall("createMessage", json);
32
}
33
private void PWCall(string action, JObject data)
34
{
35
Uri url = new Uri("https://cp.pushwoosh.com/json/1.3/" + action);
36
JObject json = new JObject(new JProperty("request", data));
37
DoPostRequest(url, json);
38
}
39
private void DoPostRequest(Uri url, JObject data)
40
{
41
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
42
req.ContentType = "text/json";
43
req.Method = "POST";
44
using (var streamWriter = new StreamWriter(req.GetRequestStream()))
45
{
46
streamWriter.Write(data.ToString());
47
}
48
HttpWebResponse httpResponse;
49
try
50
{
51
httpResponse = (HttpWebResponse)req.GetResponse();
52
}
53
catch (Exception exc)
54
{
55
throw new Exception(string.Format("Problem with {0}, {1}", url, exc.Message));
56
}
57
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
58
{
59
var responseText = streamReader.ReadToEnd();
60
Page.Response.Write(responseText);
61
}
62
}
63
}
64
}
Copied!
1
package main
2
3
import
4
(
5
"fmt"
6