{"__v":30,"_id":"5540ce1d31827a0d007ab1d2","category":{"__v":14,"_id":"5540ce1c31827a0d007ab1d0","project":"5540ce1b31827a0d007ab1cc","version":"5540ce1c31827a0d007ab1cf","pages":["5540ce1d31827a0d007ab1d2","5540ff9dbb9e762d00f59557","554109205cf9682100d61b65","554109c35cf9682100d61b6b","55a635b6249a40190051d9a2","55bb5de0a8400c2d00873e19","55bb5f4174f10a0d002209a2","55bb607374f10a0d002209a6","55bb614f7313650d00c46e88","55bb61d8a8400c2d00873e20","55bb629874f10a0d002209aa","55bb6318a8400c2d00873e23","55bb63a07313650d00c46e8a","55d5dc84988e130d000b4110"],"reference":false,"createdAt":"2015-04-29T12:27:08.888Z","from_sync":false,"order":1,"slug":"remote-api","title":"Remote API"},"project":"5540ce1b31827a0d007ab1cc","user":"5540cdbf5cf9682100d61a97","version":{"__v":27,"_id":"5540ce1c31827a0d007ab1cf","project":"5540ce1b31827a0d007ab1cc","createdAt":"2015-04-29T12:27:08.390Z","releaseDate":"2015-04-29T12:27:08.390Z","categories":["5540ce1c31827a0d007ab1d0","5540d91bbb9e762d00f594ad","5540e5f131827a0d007ab212","5540e5febb9e762d00f594d3","5540e61331827a0d007ab213","5540e6195cf9682100d61afa","5540e62631827a0d007ab214","5540e63031827a0d007ab215","5540e63531827a0d007ab216","5540e63e5cf9682100d61afc","5540e6445cf9682100d61afd","5540e64a5cf9682100d61afe","55a4ff5b2e70c0250038050f","55acb28318eefd0d0071d504","55ae1abe8576b92300291c80","55ae453ef302af23000ac109","55af586d555b900d0036d296","55af91dac8a85321007a53c3","55b9fee204775a2f00628071","55b9ff0e04775a2f00628072","55b9ff4604775a2f00628073","55b9ff5fd72d1e1900276a38","55b9ff7f04775a2f00628074","55b9ff90eb08801900f833e5","55b9ffa5d72d1e1900276a39","55b9ffca04775a2f00628075","55b9fffdd72d1e1900276a3a"],"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"createdAt":"2015-04-29T12:27:09.615Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"order":0,"body":"Service URL is `https://cp.pushwoosh.com/json/1.3/%method%`\nSend **POST** request with the JSON data as per API below.\nThe total size of the POST request must not exceed 10Mb. Some methods require you to provide the Auth Token. You can create this token at [API Access page](https://cp.pushwoosh.com/api_access) of your account.\n\nCreates a new push notification.\n\n## Request:\nHere’s the simple request that will just send a **Hello world!** push notification to all subscribers of the app:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n    \\\"request\\\": {\\n        \\\"application\\\": \\\"APPLICATION_CODE\\\",\\n        \\\"auth\\\": \\\"API_ACCESS_TOKEN\\\",\\n        \\\"notifications\\\": [{\\n            \\\"send_date\\\": \\\"now\\\", // YYYY-MM-DD HH:mm  OR 'now'\\n            \\\"ignore_user_timezone\\\": true, // or false\\n            \\\"content\\\": \\\"Hello world!\\\"\\n        }]\\n    }\\n}\",\n      \"language\": \"json\",\n      \"name\": \"\"\n    }\n  ]\n}\n[/block]\nBelow is the advanced `/createMessage` request that contains *all available* parameters:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n   \\\"request\\\":{\\n      \\\"application\\\":\\\"APPLICATION_CODE\\\",\\n      \\\"applications_group\\\":\\\"GROUP_CODE\\\",       // Optional. Can be used instead of \\\"application\\\"\\n      \\\"auth\\\": \\\"API_ACCESS_TOKEN\\\",\\n      \\\"notifications\\\":[\\n         {\\n            // Content settings \\n            \\\"send_date\\\":\\\"now\\\",           // YYYY-MM-DD HH:mm  OR 'now'\\n            \\\"ignore_user_timezone\\\": true,   // or false\\n            \\\"timezone\\\":\\\"America/New_York\\\", // Optional, if ignored UTC-0 is default in \\\"send_date\\\". See http://php.net/manual/timezones.php for the list of the supported timezones\\n            \\\"campaign\\\":\\\"CAMPAIGN_CODE\\\",     // Optional. Campaign code to which you want to assign this push message\\n            \\\"content\\\":{                  // Object( language1: 'content1', language2: 'content2' ) OR string. For Windows 8 this parameter is ignored, use \\\"wns_content\\\" instead.\\n               \\\"en\\\":\\\"English\\\",\\n               \\\"ru\\\":\\\"Русский\\\",\\n               \\\"de\\\":\\\"Deutsch\\\"\\n            }, \\n            \\\"page_id\\\": 39,               // Optional. old HTML Pages. integer\\n            \\\"rich_page_id\\\": 42,       // Optional, new Rich Pages. integer\\n            \\\"remote_page\\\" : \\\"http://myremoteurl.com\\\",    // Remote Rich HTML Page URL. <scheme>://<authority>\\n            \\\"link\\\": \\\"http://google.com\\\",  // Optional. string\\n            \\\"minimize_link\\\": 0,  // Optional param:  0 or false - not minimize, 1 - google, 2 - bitly, 3 - baidu (china) . Default = 1 \\n            \\\"data\\\":{                     // JSON string or JSON object, will be passed as \\\"u\\\" parameter in the payload\\n                  \\\"custom\\\": \\\"json data\\\"\\n            },\\n            \\\"platforms\\\": [1,2,3,4,5,6,7,8,9,10,11], // 1 - iOS; 2 - BB; 3 - Android; 4 - Nokia ASHA; 5 - Windows Phone; 7 - OS X; 8 - Windows 8; 9 - Amazon; 10 - Safari; 11 - Chrome\\n            \\\"preset\\\":\\\"Q1A2Z-6X8SW\\\",  // Push Preset ID from your Control Panel\\n            \\\"send_rate\\\": 100, // Throttling. Valid values are from 100 to 1000 pushes/second.\\n \\n            // iOS related\\n            \\\"ios_badges\\\": 5,               // Optional. Integer. This value will be sent to ALL devices given in \\\"devices\\\"\\n            \\\"ios_sound\\\": \\\"sound file.wav\\\",    // Optional. Sound file name in the main bundle of application\\n            \\\"ios_ttl\\\": 3600, // Optional. Time to live parameter - the maximum lifespan of a message in seconds\\n            \\\"ios_category_id\\\": \\\"1\\\",       // Optional. Integer. iOS8 category ID from Pushwoosh\\n            \\\"ios_root_params\\\" : {     //Optional - root level parameters to the aps dictionary\\n                      \\\"aps\\\":{\\n                                \\\"content-available\\\": \\\"1\\\"\\n                      }\\n            },\\n            \\\"apns_trim_content\\\":1,     // Optional. (0|1) Trims the exceeding content strings with ellipsis\\n            \\\"ios_trim_content\\\": 1,       // Deprecated, use \\\"apns_trim_content\\\" instead.\\n \\n            // Android related\\n            \\\"android_root_params\\\": {\\\"key\\\": \\\"value\\\"}, // custom key-value object. root level parameters for the android payload recipients\\n            \\\"android_sound\\\" : \\\"soundfile\\\", // Optional. Sound file name in the \\\"res/raw\\\" folder, do not include the extension\\n            \\\"android_header\\\":\\\"header\\\",    // Optional. Android notification header\\n            \\\"android_icon\\\": \\\"icon\\\",\\n            \\\"android_custom_icon\\\": \\\"http://example.com/image.png\\\", // Optional. Full path URL to the image file\\n            \\\"android_banner\\\": \\\"http://example.com/banner.png\\\", // Optional. Full path URL to the image file\\n            \\\"android_gcm_ttl\\\": 3600, // Optional. Time to live parameter - the maximum lifespan of a message in seconds\\n \\n            \\\"android_vibration\\\": 0,   // Android force-vibration for high-priority pushes, boolean\\n            \\\"android_led\\\":\\\"#rrggbb\\\",  // LED hex color, device will do its best approximation\\n            \\\"android_priority\\\":-1,  // Priority of the push in the Android push drawer, valid values are -2, -1, 0, 1 and 2\\n            \\\"android_ibc\\\":\\\"#RRGGBB\\\",  // Icon background color on Lollipop, #RRGGBB, #AARRGGBB, \\\"red\\\", \\\"black\\\", \\\"yellow\\\", etc.\\n \\n            // Amazon related\\n            \\\"adm_root_params\\\": {\\\"key\\\": \\\"value\\\"}, // custom key-value object\\n            \\\"adm_sound\\\": \\\"push.mp3\\\",\\n            \\\"adm_header\\\": \\\"Header\\\",\\n            \\\"adm_icon\\\": \\\"icon\\\",\\n            \\\"adm_custom_icon\\\": \\\"http://example.com/image.png\\\",\\n            \\\"adm_banner\\\": \\\"http://example.com/banner.png\\\",\\n            \\\"adm_ttl\\\": 3600, // Optional. Time to live parameter - the maximum lifespan of a message in seconds\\n            \\\"adm_priority\\\":-1,  // Priority of the push in the Amazon push drawer, valid values are -2, -1, 0, 1 and 2\\n \\n            // Windows Phone related.\\n            \\\"wp_type\\\": \\\"Tile\\\",           // Windows Phone notification type. 'Tile' or 'Toast'. Raw notifications are not supported. 'Tile' if default \\n            \\\"wp_background\\\": \\\"/Resources/Red.jpg\\\", // Tile image\\n            \\\"wp_backbackground\\\": \\\"/Resources/Green.jpg\\\", // Back tile image\\n            \\\"wp_backtitle\\\": \\\"back title\\\",  // Back tile title \\n            \\\"wp_backcontent\\\": \\\"back content\\\",  // Back tile content\\n            \\\"wp_count\\\": 3,               // Optional. Integer. Badge for Windows Phone notification\\n \\n            // BlackBerry related.\\n            \\\"blackberry_header\\\": \\\"header\\\",           // BlackBerry header, applicable to BB10 Series devices\\n \\n            // Mac OS X related\\n            \\\"mac_badges\\\": 3,\\n            \\\"mac_sound\\\": \\\"sound.caf\\\",\\n            \\\"mac_root_params\\\": {\\\"content-available\\\":1},\\n            \\\"mac_ttl\\\": 3600, // Optional. Time to live parameter - the maximum lifespan of a message in seconds\\n \\n            // WNS related\\n            \\\"wns_content\\\": { // Content (XML or raw) of notification encoded in MIME's base64 in form of Object( language1: 'content1', language2: 'content2' ) OR String\\n               \\\"en\\\": \\\"PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48YmFkZ2UgdmFsdWU9ImF2YWlsYWJsZSIvPg==\\\",\\n               \\\"de\\\": \\\"PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48YmFkZ2UgdmFsdWU9Im5ld01lc3NhZ2UiLz4=\\\"\\n            },\\n            \\\"wns_type\\\": \\\"Badge\\\", // 'Tile' | 'Toast' | 'Badge' | 'Raw'\\n            \\\"wns_tag\\\": \\\"myTag\\\", // Optional. Used in the replacement policy of the Tile. An alphanumeric string of no more than 16 characters.\\n \\n             // Safari related\\n            \\\"safari_title\\\": \\\"Title\\\", // Obligatory, title of the notification\\n            \\\"safari_action\\\": \\\"Click here\\\", // Optional\\n            \\\"safari_url_args\\\": [\\\"firstArgument\\\", \\\"secondArgument\\\"], // Obligatory, but the value may be empty\\n            \\\"safari_ttl\\\": 3600, // Optional. Time to live parameter - the maximum lifespan of a message in seconds\\n \\n            \\\"chrome_title\\\":\\\"\\\", // Optional. You can specify the header of the message in this parameter\\n            \\\"chrome_icon\\\":\\\"\\\", // Either the full path URL to the icon, or the path to the file in resources of the extension\\n            \\\"chrome_gcm_ttl\\\":\\\"\\\", // Optional. Time to live parameter - the maximum lifespan of a message in seconds\\n \\n            \\\"devices\\\":[                  // Optional. Not more than 1000 tokens in an array. If set, message will only be delivered to the devices in the list. Ignored if the applications group is used. Only lower case for iOS\\n               \\\"dec301908b9ba8df85e57a58e40f96f523f4c2068674f5fe2ba25cdc250a2a41\\\"\\n            ],\\n            \\\"filter\\\": \\\"FILTER_NAME\\\", //Optional.\\n            \\\"conditions\\\": [TAG_CONDITION1, TAG_CONDITION2, ..., TAG_CONDITIONN] //Optional. See remark\\n         }\\n      ]\\n   }\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n## Response:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"HTTP Status code\",\n    \"h-1\": \"status_code\",\n    \"h-2\": \"Description\",\n    \"0-0\": \"200\",\n    \"1-0\": \"200\",\n    \"2-0\": \"400\",\n    \"3-0\": \"500\",\n    \"0-1\": \"200\",\n    \"1-1\": \"210\",\n    \"2-1\": \"N/A\",\n    \"3-1\": \"500\",\n    \"0-2\": \"Message successfully created\",\n    \"1-2\": \"Argument error. See status_message for more info\",\n    \"2-2\": \"Malformed request string\",\n    \"3-2\": \"Internal error\"\n  },\n  \"cols\": 3,\n  \"rows\": 4\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Debug Mode\",\n  \"body\": \"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 Push History.\\n\\nHowever, as it’s necessary to see push reports during the testing phase, there’s a **Debug Mode** that you can use during your tests. Turning Debug Mode **ON** allows you to *override this limit for 1 hour and save such pushes in the push history*. Debug mode turns OFF automatically after 1 hour.\\nThe Debug Mode can be activated on the [Push History](https://cp.pushwoosh.com/notifications) page by switching the toggle in the upper right corner.\\n\\nIf the Debug Mode is turned OFF, and you send the /createMessage request that contains less than 10 device tokens to Pushwoosh API, the server returns the `“CODE_NOT_AVAILABLE”` value for `“Messages”`, and an empty key for Unknown Devices instead of the Message Code unless the message is scheduled to be sent in future with the `\\\"date\\\"` parameter.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Parameters\"\n}\n[/block]\n\n[block:parameters]\n{\n  \"data\": {\n    \"0-0\": \"auth\",\n    \"h-0\": \"Parameter\",\n    \"h-1\": \"Description\",\n    \"h-2\": \"Description\",\n    \"0-2\": \"API access token from the Pushwoosh control panel (create this token at https://cp.pushwoosh.com/api_access)\",\n    \"0-1\": \"API access token from the Pushwoosh control panel (create this token at https://cp.pushwoosh.com/api_access)\",\n    \"1-0\": \"application\",\n    \"1-2\": \"your Pushwoosh application ID where you send the message to (cannot be used together with “applications_group”)\",\n    \"2-0\": \"applications_group\",\n    \"2-2\": \"your Pushwoosh Application group code (cannot be used together with “application”)\",\n    \"3-0\": \"content\",\n    \"3-2\": \"is the text push message delivered to the application\",\n    \"4-0\": \"data\",\n    \"4-2\": \"use this only if you want to pass custom data to the application (JSON format) or omit this parameter. Please note that Mac OSX push is limited to 256 bytes\",\n    \"5-0\": \"page_id\",\n    \"5-2\": \"HTML page id (created from Application’s HTML Pages). Use this if you want to deliver additional HTML content to the application or omit this parameter\",\n    \"6-0\": \"send_date\",\n    \"6-2\": \"set the time you want the message to be sent (in UTC) or use ‘now’ to send it immediately\",\n    \"7-0\": \"wp_count\",\n    \"7-2\": \"sets the badge for WP7 platform\",\n    \"8-0\": \"ios_badges\",\n    \"8-2\": \"sets the badge on the icon for iOS platform. This value will be sent to ALL devices given in the “devices” list.\",\n    \"9-0\": \"devices\",\n    \"9-2\": \"omit this field (push notification will be delivered to all the devices for the application), or provide the list of devices IDs as described\",\n    \"10-0\": \"ios_root_params\",\n    \"10-2\": \"root level parameters to the aps dictionary. For example to use with NewsStand apps.\",\n    \"1-1\": \"your Pushwoosh application ID where you send the message to (cannot be used together with “applications_group”)\",\n    \"2-1\": \"your Pushwoosh Application group code (cannot be used together with “application”)\",\n    \"3-1\": \"is the text push message delivered to the application\",\n    \"4-1\": \"use this only if you want to pass custom data to the application (JSON format) or omit this parameter. Please note that Mac OSX push is limited to 256 bytes\",\n    \"5-1\": \"HTML page id (created from Application’s HTML Pages). Use this if you want to deliver additional HTML content to the application or omit this parameter\",\n    \"6-1\": \"set the time you want the message to be sent (in UTC) or use ‘now’ to send it immediately\",\n    \"7-1\": \"sets the badge for WP7 platform\",\n    \"8-1\": \"sets the badge on the icon for iOS platform. This value will be sent to ALL devices given in the “devices” list.\",\n    \"9-1\": \"omit this field (push notification will be delivered to all the devices for the application), or provide the list of devices IDs as described\",\n    \"10-1\": \"root level parameters to the aps dictionary. For example to use with NewsStand apps.\",\n    \"11-0\": \"conditions\",\n    \"11-1\": \"Tag condition is an array like: [tagName, operator, operand], where\\n\\n  * tagName: string\\n  * operator: “LTE”|”GTE”|”EQ”|”BETWEEN”|”IN”\\n  * operand: string|integer|array\\n\\nValid operators for String tags:\\n  * EQ: tag value equals to operand. Operand must be a string.\\n\\nValid operators for Integer tags:\\n  * GTE: tag value greater then or equals to operand. Operand must be an integer;\\n  * LTE: tag value less then or equals to operand. Operand must be an integer;\\n  * EQ: tag value equals to operand. Operand must be an integer;\\n  * BETWEEN: tag value greater then or equals to min_operand value and tag value less then or equals to max operand value. Operand must be an array like: [min_value, max_value].\\n\\nValid operators for List tags:\\n  * IN: Intersect user values and operand. Operand must be an array of strings like: [\\\"value 1\\\", \\\"value 2\\\", \\\"value N\\\"].\\n\\n**You cannot use “filter” and “conditions” parameters together.** \\n\\n**Country and Language tags**:\\nLanguage tag value is a lowercase two-letter code according to the [ISO-639-1](http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)\\nCountry tag value is an UPPERCASE two-letter code according to the [ISO_3166-2](http://en.wikipedia.org/wiki/ISO_3166-2)\\nFor example, to send push notification to subscribers in Brazil that speak Portuguese language you need to specify condition like this: `\\\"conditions\\\": [[\\\"Country\\\", \\\"EQ\\\", \\\"BR\\\"],[\\\"Language\\\", \\\"EQ\\\", \\\"pt\\\"]]`\"\n  },\n  \"cols\": 2,\n  \"rows\": 12\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"/createMessage snippets\"\n}\n[/block]\nSample `/createMessage` requests in BASH, PHP, Erlang, Ruby, Java and Python:\n[block:callout]\n{\n  \"type\": \"success\",\n  \"body\": \"Check out PHP-Pushwoosh library by goomob:\\nhttp://gomoob.github.io/php-pushwoosh/\\nhttp://gomoob.github.io/php-pushwoosh/create-message.html\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#!/bin/bash\\n \\n#Usage\\nif [ ! -n \\\"$1\\\" ] || [ ! -n \\\"$2\\\" ]\\nthen\\n  echo \\\"`basename $0` usage: api_token appid message\\\";\\n  exit 1;\\nfi;\\nMESSAGE=\\\"$3\\\";\\nif [ -z \\\"$3\\\" ]\\nthen\\nMESSAGE='One push to rule them all!'\\nfi;\\n \\necho -e \\\"Response:\\\"\\ncurl --data-binary \\\"\\n{\\\\\\\"request\\\\\\\":\\n    {\\\\\\\"application\\\\\\\":\\\\\\\"$2\\\\\\\",\\n     \\\\\\\"auth\\\\\\\":\\\\\\\"$1\\\\\\\",\\n     \\\\\\\"notifications\\\\\\\":\\n        [{\\n                        \\\\\\\"send_date\\\\\\\": \\\\\\\"now\\\\\\\",\\n            \\\\\\\"content\\\\\\\": \\\\\\\"$MESSAGE\\\\\\\"\\n        }]\\n    }\\n}\\\" \\\\\\n-H \\\"Content-type: application/json\\\" \\\\\\n\\\"https://cp.pushwoosh.com/json/1.3/createMessage\\\"\\necho\\\"\\\";\\nexit 0;\",\n      \"language\": \"java\",\n      \"name\": \"BASH\"\n    },\n    {\n      \"code\": \"<?php \\ndefine('PW_AUTH', 'API TOKEN');\\ndefine('PW_APPLICATION', 'APPLICATION CODE');\\ndefine('PW_DEBUG', true);\\n \\nfunction pwCall($method, $data) {\\n    $url = 'https://cp.pushwoosh.com/json/1.3/' . $method;\\n    $request = json_encode(['request' =--> $data]);\\n \\n    $ch = curl_init($url);\\n    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\\n    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);\\n    curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');\\n    curl_setopt($ch, CURLOPT_HEADER, true);\\n    curl_setopt($ch, CURLOPT_POST, true);\\n    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);\\n \\n    $response = curl_exec($ch);\\n    $info = curl_getinfo($ch);\\n    curl_close($ch);\\n \\n    if (defined('PW_DEBUG') && PW_DEBUG) {\\n        print \\\"[PW] request: $request\\\\n\\\";\\n        print \\\"[PW] response: $response\\\\n\\\";\\n        print \\\"[PW] info: \\\" . print_r($info, true);\\n    }\\n}\\n \\npwCall('createMessage', array(\\n    'application' => PW_APPLICATION,\\n    'auth' => PW_AUTH,\\n    'notifications' => array(\\n            array(\\n                'send_date' => 'now',\\n                'content' => 'test',\\n                'data' => array('custom' => 'json data'),\\n                'link' => 'http://pushwoosh.com/'\\n            )\\n        )\\n    )\\n);\",\n      \"language\": \"php\"\n    },\n    {\n      \"code\": \"-module(pushwoosh).\\n-export([run/0, stop/0, sendMessage/1]).\\n%% sendMessage argument: message text %%\\n \\n%% Authentication & App_id %%\\n-define(PW_AUTH, \\\"YOUR_AUTH_TOKEN\\\").\\n-define(PW_APPLICATION, \\\"YOUR_PUSHWOOSH_APP_CODE\\\").\\n \\n%% KickStart %%\\nrun() ->\\n    application:start(unicode),\\n    application:start(crypto),\\n    application:start(public_key),\\n    application:start(ssl),\\n    application:start(inets),\\n    %% HTTP Client verbosity options flase, verbose, debug\\n    httpc:set_options([{verbose, false}]).  \\nstop() ->\\n    application:stop(ssl),\\n    application:stop(public_key),       \\n    application:stop(crypto),\\n    application:stop(inets).\\n%% JSON Wars !\\nencode(S) -> encode(S, [$\\\"]).\\nencode([], Acc) -> lists:reverse([$\\\" | Acc]);\\nencode([C | Cs], Acc) ->\\n        Hex = lists:flatten(io_lib:format(\\\"~4.16.0b\\\", [C])),\\n        encode(Cs, lists:reverse(Hex) ++ \\\"u\\\\\\\\\\\" ++ Acc).\\n \\nsendMessage(Message_text) ->\\n    %% URL to JSON API 1.3\\n    Url = \\\"https://cp.pushwoosh.com/json/1.3/createMessage\\\",\\n    EncodedMessage = encode(Message_text),\\n    {ok, Response} = httpc:request(\\n        %%Method \\n        post, \\n        %%Request\\n        {Url, [{\\\"User-Agent\\\", \\\"Erlang exemple\\\"}], \\\"application/json; charset=UTF-8\\\", \\n        \\\"{\\\\\\\"request\\\\\\\":{\\n        \\\\\\\"application\\\\\\\": \\\\\\\"\\\"?PW_APPLICATION\\\"\\\\\\\",\\n        \\\\\\\"auth\\\\\\\": \\\\\\\"\\\"?PW_AUTH\\\"\\\\\\\",\\n        \\\\\\\"notifications\\\\\\\": [{\\n        \\\\\\\"send_date\\\\\\\": \\\\\\\"now\\\\\\\",\\n        \\\\\\\"content\\\\\\\": \\\"++EncodedMessage++\\\"\\n        }]}}\\\"},\\n        %%HTTP options\\n        [{ssl,[{verify, verify_none}]}, {version, \\\"HTTP/1.0\\\"}],\\n        %%Options\\n        []),\\n    io:format(\\\"And received ~p\\\", [Response]).\",\n      \"language\": \"erlang\"\n    },\n    {\n      \"code\": \"class PushNotification\\n \\n  #- PushWoosh API Documentation http://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/ \\n  #- Two methods here:\\n  #     - PushNotification.new.notify_all(message) Notifies all with the same option\\n  #     - PushNotification.new.notify_devices(notification_options = {}) Notifies specific devices with custom options\\n \\n  include HTTParty #Make sure to have the HTTParty gem declared in your gemfile https://github.com/jnunemaker/httparty\\n  default_params :output => 'json'\\n  format :json\\n \\n  def initialize\\n    #- Change to your settings\\n    :::at:::auth = {:application  => \\\"00000-00000\\\",:auth => \\\"auth_token\\\"}\\n  end\\n \\n  # PushNotification.new.notify_all(\\\"This is a test notification to all devices\\\")\\n  def notify_all(message)\\n    notify_devices({:content  => message})\\n  end\\n \\n  # PushNotification.new.notify_device({\\n  #  :content  => \\\"TEST\\\",\\n  #  :data  => {:custom_data  => value},\\n  #  :devices  => array_of_tokens\\n  #})\\n  def notify_devices(notification_options = {})\\n    #- Default options, uncomment :data or :devices if needed\\n    default_notification_options = {\\n                        # YYYY-MM-DD HH:mm  OR 'now'\\n                        :send_date  => \\\"now\\\",\\n                        # Object( language1: 'content1', language2: 'content2' ) OR string\\n                        :content  => {\\n                            :fr  => \\\"Test\\\",\\n                            :en  => \\\"Test\\\"\\n                        },\\n                        # JSON string or JSON object \\\"custom\\\": \\\"json data\\\"\\n                        #:data  => {\\n                        #    :custom_data  => value\\n                        #},\\n                        # omit this field (push notification will be delivered to all the devices for the application), or provide the list of devices IDs\\n                        #:devices  => {}\\n                      }\\n \\n    #- Merging with specific options\\n    final_notification_options = default_notification_options.merge(notification_options)\\n \\n    #- Constructing the final call\\n    options = @auth.merge({:notifications  => [final_notification_options]})\\n    options = {:request  => options}                                                                                                                             \\n    #- Executing the POST API Call with HTTPARTY - :body => options.to_json allows us to send the json as an object instead of a string\\n    response = self.class.post(\\\"https://cp.pushwoosh.com/json/1.3/createMessage\\\", :body  => options.to_json,:headers => { 'Content-Type' => 'application/json' })\\n  end\\nend\",\n      \"language\": \"ruby\"\n    },\n    {\n      \"code\": \"// Uses JSON classes from http://json.org/java/\\n\\npackage com.arellomobile;\\n \\nimport org.json.*;\\nimport java.io.*;\\nimport java.net.*;\\n \\npublic class SendPushNotificationSample\\n{\\n    public static final String PUSHWOOSH_SERVICE_BASE_URL = \\\"https://cp.pushwoosh.com/json/1.3/\\\";\\n    private static final String AUTH_TOKEN = \\\"YOUR_AUTH_TOKEN\\\";\\n    private static final String APPLICATION_CODE = \\\"PW_APPLICATION_CODE\\\";\\n \\n    public static void main(String[] args) throws JSONException, MalformedURLException\\n    {\\n        String method = \\\"createMessage\\\";\\n        URL url = new URL(PUSHWOOSH_SERVICE_BASE_URL + method);\\n \\n        JSONArray notificationsArray = new JSONArray()\\n                .put(new JSONObject().put(\\\"send_date\\\", \\\"now\\\")\\n                                     .put(\\\"content\\\", \\\"test\\\")\\n                                     .put(\\\"link\\\", \\\"http://pushwoosh.com/\\\"));\\n \\n        JSONObject requestObject = new JSONObject()\\n                .put(\\\"application\\\", APPLICATION_CODE)\\n                .put(\\\"auth\\\", AUTH_TOKEN)\\n                .put(\\\"notifications\\\", notificationsArray);\\n \\n        JSONObject mainRequest = new JSONObject().put(\\\"request\\\", requestObject);\\n        JSONObject response = SendServerRequest.sendJSONRequest(url, mainRequest.toString());\\n \\n        System.out.println(\\\"Response is: \\\" + response);\\n    }\\n}\\n \\nclass SendServerRequest\\n{\\n    static JSONObject sendJSONRequest(URL url, String request)\\n    {\\n        HttpURLConnection connection = null;\\n        try\\n        {\\n            connection = (HttpURLConnection) url.openConnection();\\n            connection.setRequestMethod(\\\"POST\\\");\\n            connection.setRequestProperty(\\\"Content-Type\\\", \\\"application/json\\\");\\n            connection.setDoInput(true);\\n            connection.setDoOutput(true);\\n \\n            DataOutputStream writer = new DataOutputStream(connection.getOutputStream());\\n            writer.write(request.getBytes(\\\"UTF-8\\\"));\\n            writer.flush();\\n            writer.close();\\n \\n            return parseResponse(connection);\\n        }\\n        catch (Exception e)\\n        {\\n            System.out.println(\\\"An error occurred: \\\" + e.getMessage());\\n            return null;\\n        }\\n        finally\\n        {\\n            if (connection != null)\\n            {\\n                connection.disconnect();\\n            }\\n        }\\n    }\\n \\n    static JSONObject parseResponse(HttpURLConnection connection) throws IOException, JSONException\\n    {\\n        String line;\\n        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));\\n        StringBuilder response = new StringBuilder();\\n \\n        while ((line = reader.readLine()) != null)\\n        {\\n            response.append(line).append('\\\\r');\\n        }\\n        reader.close();\\n \\n        return new JSONObject(response.toString());\\n    }\\n}\",\n      \"language\": \"java\"\n    },\n    {\n      \"code\": \"import json\\n \\nPW_AUTH = 'API TOKEN'\\nPW_APPLICATION_CODE = 'APPLICATION CODE'\\n \\ntry:\\n    # For Python 3.0 and later\\n    from urllib.request import urlopen\\n    from urllib.request import Request\\nexcept ImportError:\\n    # Fall back to Python 2's urllib2\\n    from urllib2 import urlopen\\n    from urllib2 import Request\\n \\ndef pw_call(method, data):\\n    url = 'https://cp.pushwoosh.com/json/1.3/' + method\\n    data = json.dumps({'request': data})\\n    req = Request(url, data.encode('UTF-8'), {'Content-Type': 'application/json'})\\n    try:\\n        f = urlopen(req)\\n        response = f.read()\\n        f.close()\\n        print('Pushwoosh response: ' + str(response))\\n    except Exception as e:\\n        print ('Request error: ' + str(e))\\n \\nif __name__ == '__main__':\\n    pw_call('createMessage', {\\n        'auth': PW_AUTH,\\n        'application': PW_APPLICATION_CODE,\\n        'notifications': [\\n            {\\n                'send_date': 'now',\\n                'content': 'test',\\n                'data': {\\\"custom\\\": \\\"json data\\\"},\\n                'link': 'http://pushwoosh.com'\\n            }\\n        ]\\n    }\\n    )\",\n      \"language\": \"python\"\n    },\n    {\n      \"code\": \"[sourcecode language=\\\"csharp\\\"]\\nusing System;\\nusing System.IO;\\nusing System.Net;\\nusing Newtonsoft.Json.Linq;\\n\\nnamespace WebApplication1\\n{\\n   public partial class Default : System.Web.UI.Page\\n   {\\n       protected void Page_Load(object sender, EventArgs e)\\n       {\\n           string pwAuth = \\\"YOUR_AUTH_TOKEN\\\";\\n           string pwApplication = \\\"PW_APPLICATION_CODE\\\";\\n           JObject json = new JObject(\\n               new JProperty(\\\"application\\\", pwApplication),\\n               new JProperty(\\\"auth\\\", pwAuth),\\n               new JProperty(\\\"notifications\\\",\\n                   new JArray(\\n                       new JObject(\\n                           new JProperty(\\\"send_date\\\", \\\"now\\\"),\\n                           new JProperty(\\\"content\\\", \\\"test\\\"),\\n                           new JProperty(\\\"wp_type\\\", \\\"Toast\\\"),\\n                           new JProperty(\\\"wp_count\\\", 3),\\n                           new JProperty(\\\"data\\\",\\n                               new JObject(\\n                                   new JProperty(\\\"custom\\\", \\\"json data\\\"))),\\n                           new JProperty(\\\"link\\\", \\\"http://pushwoosh.com/\\\"),\\n                           new JProperty(\\\"conditions\\\",\\n                               new JArray(\\n                                   (object)new JArray(\\\"Color\\\", \\\"EQ\\\", \\\"black\\\")))))));\\n           PWCall(\\\"createMessage\\\", json);\\n       }\\n       private void PWCall(string action, JObject data)\\n       {\\n           Uri url = new Uri(\\\"https://cp.pushwoosh.com/json/1.3/\\\" + action);\\n           JObject json = new JObject(new JProperty(\\\"request\\\", data));\\n           DoPostRequest(url, json);\\n       }\\n       private void DoPostRequest(Uri url, JObject data)\\n       {\\n           HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);\\n           req.ContentType = \\\"text/json\\\";\\n           req.Method = \\\"POST\\\";\\n           using (var streamWriter = new StreamWriter(req.GetRequestStream()))\\n           {\\n               streamWriter.Write(data.ToString());\\n           }\\n           HttpWebResponse httpResponse;\\n           try\\n           {\\n               httpResponse = (HttpWebResponse)req.GetResponse();\\n           }\\n           catch (Exception exc)\\n           {\\n               throw new Exception(string.Format(\\\"Problem with {0}, {1}\\\", url, exc.Message));\\n           }\\n           using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))\\n           {\\n               var responseText = streamReader.ReadToEnd();\\n               Page.Response.Write(responseText);\\n           }\\n       }\\n   }\\n}\",\n      \"language\": \"csharp\",\n      \"name\": \".NET\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"createmessage","type":"basic","title":"/createMessage"}
Service URL is `https://cp.pushwoosh.com/json/1.3/%method%` Send **POST** request with the JSON data as per API below. The total size of the POST request must not exceed 10Mb. Some methods require you to provide the Auth Token. You can create this token at [API Access page](https://cp.pushwoosh.com/api_access) of your account. Creates a new push notification. ## Request: Here’s the simple request that will just send a **Hello world!** push notification to all subscribers of the app: [block:code] { "codes": [ { "code": "{\n \"request\": {\n \"application\": \"APPLICATION_CODE\",\n \"auth\": \"API_ACCESS_TOKEN\",\n \"notifications\": [{\n \"send_date\": \"now\", // YYYY-MM-DD HH:mm OR 'now'\n \"ignore_user_timezone\": true, // or false\n \"content\": \"Hello world!\"\n }]\n }\n}", "language": "json", "name": "" } ] } [/block] Below is the advanced `/createMessage` request that contains *all available* parameters: [block:code] { "codes": [ { "code": "{\n \"request\":{\n \"application\":\"APPLICATION_CODE\",\n \"applications_group\":\"GROUP_CODE\", // Optional. Can be used instead of \"application\"\n \"auth\": \"API_ACCESS_TOKEN\",\n \"notifications\":[\n {\n // Content settings \n \"send_date\":\"now\", // YYYY-MM-DD HH:mm OR 'now'\n \"ignore_user_timezone\": true, // or false\n \"timezone\":\"America/New_York\", // Optional, if ignored UTC-0 is default in \"send_date\". See http://php.net/manual/timezones.php for the list of the supported timezones\n \"campaign\":\"CAMPAIGN_CODE\", // Optional. Campaign code to which you want to assign this push message\n \"content\":{ // Object( language1: 'content1', language2: 'content2' ) OR string. For Windows 8 this parameter is ignored, use \"wns_content\" instead.\n \"en\":\"English\",\n \"ru\":\"Русский\",\n \"de\":\"Deutsch\"\n }, \n \"page_id\": 39, // Optional. old HTML Pages. integer\n \"rich_page_id\": 42, // Optional, new Rich Pages. integer\n \"remote_page\" : \"http://myremoteurl.com\", // Remote Rich HTML Page URL. <scheme>://<authority>\n \"link\": \"http://google.com\", // Optional. string\n \"minimize_link\": 0, // Optional param: 0 or false - not minimize, 1 - google, 2 - bitly, 3 - baidu (china) . Default = 1 \n \"data\":{ // JSON string or JSON object, will be passed as \"u\" parameter in the payload\n \"custom\": \"json data\"\n },\n \"platforms\": [1,2,3,4,5,6,7,8,9,10,11], // 1 - iOS; 2 - BB; 3 - Android; 4 - Nokia ASHA; 5 - Windows Phone; 7 - OS X; 8 - Windows 8; 9 - Amazon; 10 - Safari; 11 - Chrome\n \"preset\":\"Q1A2Z-6X8SW\", // Push Preset ID from your Control Panel\n \"send_rate\": 100, // Throttling. Valid values are from 100 to 1000 pushes/second.\n \n // iOS related\n \"ios_badges\": 5, // Optional. Integer. This value will be sent to ALL devices given in \"devices\"\n \"ios_sound\": \"sound file.wav\", // Optional. Sound file name in the main bundle of application\n \"ios_ttl\": 3600, // Optional. Time to live parameter - the maximum lifespan of a message in seconds\n \"ios_category_id\": \"1\", // Optional. Integer. iOS8 category ID from Pushwoosh\n \"ios_root_params\" : { //Optional - root level parameters to the aps dictionary\n \"aps\":{\n \"content-available\": \"1\"\n }\n },\n \"apns_trim_content\":1, // Optional. (0|1) Trims the exceeding content strings with ellipsis\n \"ios_trim_content\": 1, // Deprecated, use \"apns_trim_content\" instead.\n \n // Android related\n \"android_root_params\": {\"key\": \"value\"}, // custom key-value object. root level parameters for the android payload recipients\n \"android_sound\" : \"soundfile\", // Optional. Sound file name in the \"res/raw\" folder, do not include the extension\n \"android_header\":\"header\", // Optional. Android notification header\n \"android_icon\": \"icon\",\n \"android_custom_icon\": \"http://example.com/image.png\", // Optional. Full path URL to the image file\n \"android_banner\": \"http://example.com/banner.png\", // Optional. Full path URL to the image file\n \"android_gcm_ttl\": 3600, // Optional. Time to live parameter - the maximum lifespan of a message in seconds\n \n \"android_vibration\": 0, // Android force-vibration for high-priority pushes, boolean\n \"android_led\":\"#rrggbb\", // LED hex color, device will do its best approximation\n \"android_priority\":-1, // Priority of the push in the Android push drawer, valid values are -2, -1, 0, 1 and 2\n \"android_ibc\":\"#RRGGBB\", // Icon background color on Lollipop, #RRGGBB, #AARRGGBB, \"red\", \"black\", \"yellow\", etc.\n \n // Amazon related\n \"adm_root_params\": {\"key\": \"value\"}, // custom key-value object\n \"adm_sound\": \"push.mp3\",\n \"adm_header\": \"Header\",\n \"adm_icon\": \"icon\",\n \"adm_custom_icon\": \"http://example.com/image.png\",\n \"adm_banner\": \"http://example.com/banner.png\",\n \"adm_ttl\": 3600, // Optional. Time to live parameter - the maximum lifespan of a message in seconds\n \"adm_priority\":-1, // Priority of the push in the Amazon push drawer, valid values are -2, -1, 0, 1 and 2\n \n // Windows Phone related.\n \"wp_type\": \"Tile\", // Windows Phone notification type. 'Tile' or 'Toast'. Raw notifications are not supported. 'Tile' if default \n \"wp_background\": \"/Resources/Red.jpg\", // Tile image\n \"wp_backbackground\": \"/Resources/Green.jpg\", // Back tile image\n \"wp_backtitle\": \"back title\", // Back tile title \n \"wp_backcontent\": \"back content\", // Back tile content\n \"wp_count\": 3, // Optional. Integer. Badge for Windows Phone notification\n \n // BlackBerry related.\n \"blackberry_header\": \"header\", // BlackBerry header, applicable to BB10 Series devices\n \n // Mac OS X related\n \"mac_badges\": 3,\n \"mac_sound\": \"sound.caf\",\n \"mac_root_params\": {\"content-available\":1},\n \"mac_ttl\": 3600, // Optional. Time to live parameter - the maximum lifespan of a message in seconds\n \n // WNS related\n \"wns_content\": { // Content (XML or raw) of notification encoded in MIME's base64 in form of Object( language1: 'content1', language2: 'content2' ) OR String\n \"en\": \"PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48YmFkZ2UgdmFsdWU9ImF2YWlsYWJsZSIvPg==\",\n \"de\": \"PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48YmFkZ2UgdmFsdWU9Im5ld01lc3NhZ2UiLz4=\"\n },\n \"wns_type\": \"Badge\", // 'Tile' | 'Toast' | 'Badge' | 'Raw'\n \"wns_tag\": \"myTag\", // Optional. Used in the replacement policy of the Tile. An alphanumeric string of no more than 16 characters.\n \n // Safari related\n \"safari_title\": \"Title\", // Obligatory, title of the notification\n \"safari_action\": \"Click here\", // Optional\n \"safari_url_args\": [\"firstArgument\", \"secondArgument\"], // Obligatory, but the value may be empty\n \"safari_ttl\": 3600, // Optional. Time to live parameter - the maximum lifespan of a message in seconds\n \n \"chrome_title\":\"\", // Optional. You can specify the header of the message in this parameter\n \"chrome_icon\":\"\", // Either the full path URL to the icon, or the path to the file in resources of the extension\n \"chrome_gcm_ttl\":\"\", // Optional. Time to live parameter - the maximum lifespan of a message in seconds\n \n \"devices\":[ // Optional. Not more than 1000 tokens in an array. If set, message will only be delivered to the devices in the list. Ignored if the applications group is used. Only lower case for iOS\n \"dec301908b9ba8df85e57a58e40f96f523f4c2068674f5fe2ba25cdc250a2a41\"\n ],\n \"filter\": \"FILTER_NAME\", //Optional.\n \"conditions\": [TAG_CONDITION1, TAG_CONDITION2, ..., TAG_CONDITIONN] //Optional. See remark\n }\n ]\n }\n}", "language": "json" } ] } [/block] ## Response: [block:parameters] { "data": { "h-0": "HTTP Status code", "h-1": "status_code", "h-2": "Description", "0-0": "200", "1-0": "200", "2-0": "400", "3-0": "500", "0-1": "200", "1-1": "210", "2-1": "N/A", "3-1": "500", "0-2": "Message successfully created", "1-2": "Argument error. See status_message for more info", "2-2": "Malformed request string", "3-2": "Internal error" }, "cols": 3, "rows": 4 } [/block] [block:callout] { "type": "info", "title": "Debug Mode", "body": "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 Push History.\n\nHowever, as it’s necessary to see push reports during the testing phase, there’s a **Debug Mode** that you can use during your tests. Turning Debug Mode **ON** allows you to *override this limit for 1 hour and save such pushes in the push history*. Debug mode turns OFF automatically after 1 hour.\nThe Debug Mode can be activated on the [Push History](https://cp.pushwoosh.com/notifications) page by switching the toggle in the upper right corner.\n\nIf the Debug Mode is turned OFF, and you send the /createMessage request that contains less than 10 device tokens to Pushwoosh API, the server returns the `“CODE_NOT_AVAILABLE”` value for `“Messages”`, and an empty key for Unknown Devices instead of the Message Code unless the message is scheduled to be sent in future with the `\"date\"` parameter." } [/block] [block:api-header] { "type": "basic", "title": "Parameters" } [/block] [block:parameters] { "data": { "0-0": "auth", "h-0": "Parameter", "h-1": "Description", "h-2": "Description", "0-2": "API access token from the Pushwoosh control panel (create this token at https://cp.pushwoosh.com/api_access)", "0-1": "API access token from the Pushwoosh control panel (create this token at https://cp.pushwoosh.com/api_access)", "1-0": "application", "1-2": "your Pushwoosh application ID where you send the message to (cannot be used together with “applications_group”)", "2-0": "applications_group", "2-2": "your Pushwoosh Application group code (cannot be used together with “application”)", "3-0": "content", "3-2": "is the text push message delivered to the application", "4-0": "data", "4-2": "use this only if you want to pass custom data to the application (JSON format) or omit this parameter. Please note that Mac OSX push is limited to 256 bytes", "5-0": "page_id", "5-2": "HTML page id (created from Application’s HTML Pages). Use this if you want to deliver additional HTML content to the application or omit this parameter", "6-0": "send_date", "6-2": "set the time you want the message to be sent (in UTC) or use ‘now’ to send it immediately", "7-0": "wp_count", "7-2": "sets the badge for WP7 platform", "8-0": "ios_badges", "8-2": "sets the badge on the icon for iOS platform. This value will be sent to ALL devices given in the “devices” list.", "9-0": "devices", "9-2": "omit this field (push notification will be delivered to all the devices for the application), or provide the list of devices IDs as described", "10-0": "ios_root_params", "10-2": "root level parameters to the aps dictionary. For example to use with NewsStand apps.", "1-1": "your Pushwoosh application ID where you send the message to (cannot be used together with “applications_group”)", "2-1": "your Pushwoosh Application group code (cannot be used together with “application”)", "3-1": "is the text push message delivered to the application", "4-1": "use this only if you want to pass custom data to the application (JSON format) or omit this parameter. Please note that Mac OSX push is limited to 256 bytes", "5-1": "HTML page id (created from Application’s HTML Pages). Use this if you want to deliver additional HTML content to the application or omit this parameter", "6-1": "set the time you want the message to be sent (in UTC) or use ‘now’ to send it immediately", "7-1": "sets the badge for WP7 platform", "8-1": "sets the badge on the icon for iOS platform. This value will be sent to ALL devices given in the “devices” list.", "9-1": "omit this field (push notification will be delivered to all the devices for the application), or provide the list of devices IDs as described", "10-1": "root level parameters to the aps dictionary. For example to use with NewsStand apps.", "11-0": "conditions", "11-1": "Tag condition is an array like: [tagName, operator, operand], where\n\n * tagName: string\n * operator: “LTE”|”GTE”|”EQ”|”BETWEEN”|”IN”\n * operand: string|integer|array\n\nValid operators for String tags:\n * EQ: tag value equals to operand. Operand must be a string.\n\nValid operators for Integer tags:\n * GTE: tag value greater then or equals to operand. Operand must be an integer;\n * LTE: tag value less then or equals to operand. Operand must be an integer;\n * EQ: tag value equals to operand. Operand must be an integer;\n * BETWEEN: tag value greater then or equals to min_operand value and tag value less then or equals to max operand value. Operand must be an array like: [min_value, max_value].\n\nValid operators for List tags:\n * IN: Intersect user values and operand. Operand must be an array of strings like: [\"value 1\", \"value 2\", \"value N\"].\n\n**You cannot use “filter” and “conditions” parameters together.** \n\n**Country and Language tags**:\nLanguage tag value is a lowercase two-letter code according to the [ISO-639-1](http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)\nCountry tag value is an UPPERCASE two-letter code according to the [ISO_3166-2](http://en.wikipedia.org/wiki/ISO_3166-2)\nFor example, to send push notification to subscribers in Brazil that speak Portuguese language you need to specify condition like this: `\"conditions\": [[\"Country\", \"EQ\", \"BR\"],[\"Language\", \"EQ\", \"pt\"]]`" }, "cols": 2, "rows": 12 } [/block] [block:api-header] { "type": "basic", "title": "/createMessage snippets" } [/block] Sample `/createMessage` requests in BASH, PHP, Erlang, Ruby, Java and Python: [block:callout] { "type": "success", "body": "Check out PHP-Pushwoosh library by goomob:\nhttp://gomoob.github.io/php-pushwoosh/\nhttp://gomoob.github.io/php-pushwoosh/create-message.html" } [/block] [block:code] { "codes": [ { "code": "#!/bin/bash\n \n#Usage\nif [ ! -n \"$1\" ] || [ ! -n \"$2\" ]\nthen\n echo \"`basename $0` usage: api_token appid message\";\n exit 1;\nfi;\nMESSAGE=\"$3\";\nif [ -z \"$3\" ]\nthen\nMESSAGE='One push to rule them all!'\nfi;\n \necho -e \"Response:\"\ncurl --data-binary \"\n{\\\"request\\\":\n {\\\"application\\\":\\\"$2\\\",\n \\\"auth\\\":\\\"$1\\\",\n \\\"notifications\\\":\n [{\n \\\"send_date\\\": \\\"now\\\",\n \\\"content\\\": \\\"$MESSAGE\\\"\n }]\n }\n}\" \\\n-H \"Content-type: application/json\" \\\n\"https://cp.pushwoosh.com/json/1.3/createMessage\"\necho\"\";\nexit 0;", "language": "java", "name": "BASH" }, { "code": "<?php \ndefine('PW_AUTH', 'API TOKEN');\ndefine('PW_APPLICATION', 'APPLICATION CODE');\ndefine('PW_DEBUG', true);\n \nfunction pwCall($method, $data) {\n $url = 'https://cp.pushwoosh.com/json/1.3/' . $method;\n $request = json_encode(['request' =--> $data]);\n \n $ch = curl_init($url);\n curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\n curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);\n curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');\n curl_setopt($ch, CURLOPT_HEADER, true);\n curl_setopt($ch, CURLOPT_POST, true);\n curl_setopt($ch, CURLOPT_POSTFIELDS, $request);\n \n $response = curl_exec($ch);\n $info = curl_getinfo($ch);\n curl_close($ch);\n \n if (defined('PW_DEBUG') && PW_DEBUG) {\n print \"[PW] request: $request\\n\";\n print \"[PW] response: $response\\n\";\n print \"[PW] info: \" . print_r($info, true);\n }\n}\n \npwCall('createMessage', array(\n 'application' => PW_APPLICATION,\n 'auth' => PW_AUTH,\n 'notifications' => array(\n array(\n 'send_date' => 'now',\n 'content' => 'test',\n 'data' => array('custom' => 'json data'),\n 'link' => 'http://pushwoosh.com/'\n )\n )\n )\n);", "language": "php" }, { "code": "-module(pushwoosh).\n-export([run/0, stop/0, sendMessage/1]).\n%% sendMessage argument: message text %%\n \n%% Authentication & App_id %%\n-define(PW_AUTH, \"YOUR_AUTH_TOKEN\").\n-define(PW_APPLICATION, \"YOUR_PUSHWOOSH_APP_CODE\").\n \n%% KickStart %%\nrun() ->\n application:start(unicode),\n application:start(crypto),\n application:start(public_key),\n application:start(ssl),\n application:start(inets),\n %% HTTP Client verbosity options flase, verbose, debug\n httpc:set_options([{verbose, false}]). \nstop() ->\n application:stop(ssl),\n application:stop(public_key), \n application:stop(crypto),\n application:stop(inets).\n%% JSON Wars !\nencode(S) -> encode(S, [$\"]).\nencode([], Acc) -> lists:reverse([$\" | Acc]);\nencode([C | Cs], Acc) ->\n Hex = lists:flatten(io_lib:format(\"~4.16.0b\", [C])),\n encode(Cs, lists:reverse(Hex) ++ \"u\\\\\" ++ Acc).\n \nsendMessage(Message_text) ->\n %% URL to JSON API 1.3\n Url = \"https://cp.pushwoosh.com/json/1.3/createMessage\",\n EncodedMessage = encode(Message_text),\n {ok, Response} = httpc:request(\n %%Method \n post, \n %%Request\n {Url, [{\"User-Agent\", \"Erlang exemple\"}], \"application/json; charset=UTF-8\", \n \"{\\\"request\\\":{\n \\\"application\\\": \\\"\"?PW_APPLICATION\"\\\",\n \\\"auth\\\": \\\"\"?PW_AUTH\"\\\",\n \\\"notifications\\\": [{\n \\\"send_date\\\": \\\"now\\\",\n \\\"content\\\": \"++EncodedMessage++\"\n }]}}\"},\n %%HTTP options\n [{ssl,[{verify, verify_none}]}, {version, \"HTTP/1.0\"}],\n %%Options\n []),\n io:format(\"And received ~p\", [Response]).", "language": "erlang" }, { "code": "class PushNotification\n \n #- PushWoosh API Documentation http://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/ \n #- Two methods here:\n # - PushNotification.new.notify_all(message) Notifies all with the same option\n # - PushNotification.new.notify_devices(notification_options = {}) Notifies specific devices with custom options\n \n include HTTParty #Make sure to have the HTTParty gem declared in your gemfile https://github.com/jnunemaker/httparty\n default_params :output => 'json'\n format :json\n \n def initialize\n #- Change to your settings\n @auth = {:application => \"00000-00000\",:auth => \"auth_token\"}\n end\n \n # PushNotification.new.notify_all(\"This is a test notification to all devices\")\n def notify_all(message)\n notify_devices({:content => message})\n end\n \n # PushNotification.new.notify_device({\n # :content => \"TEST\",\n # :data => {:custom_data => value},\n # :devices => array_of_tokens\n #})\n def notify_devices(notification_options = {})\n #- Default options, uncomment :data or :devices if needed\n default_notification_options = {\n # YYYY-MM-DD HH:mm OR 'now'\n :send_date => \"now\",\n # Object( language1: 'content1', language2: 'content2' ) OR string\n :content => {\n :fr => \"Test\",\n :en => \"Test\"\n },\n # JSON string or JSON object \"custom\": \"json data\"\n #:data => {\n # :custom_data => value\n #},\n # omit this field (push notification will be delivered to all the devices for the application), or provide the list of devices IDs\n #:devices => {}\n }\n \n #- Merging with specific options\n final_notification_options = default_notification_options.merge(notification_options)\n \n #- Constructing the final call\n options = @auth.merge({:notifications => [final_notification_options]})\n options = {:request => options} \n #- Executing the POST API Call with HTTPARTY - :body => options.to_json allows us to send the json as an object instead of a string\n response = self.class.post(\"https://cp.pushwoosh.com/json/1.3/createMessage\", :body => options.to_json,:headers => { 'Content-Type' => 'application/json' })\n end\nend", "language": "ruby" }, { "code": "// Uses JSON classes from http://json.org/java/\n\npackage com.arellomobile;\n \nimport org.json.*;\nimport java.io.*;\nimport java.net.*;\n \npublic class SendPushNotificationSample\n{\n public static final String PUSHWOOSH_SERVICE_BASE_URL = \"https://cp.pushwoosh.com/json/1.3/\";\n private static final String AUTH_TOKEN = \"YOUR_AUTH_TOKEN\";\n private static final String APPLICATION_CODE = \"PW_APPLICATION_CODE\";\n \n public static void main(String[] args) throws JSONException, MalformedURLException\n {\n String method = \"createMessage\";\n URL url = new URL(PUSHWOOSH_SERVICE_BASE_URL + method);\n \n JSONArray notificationsArray = new JSONArray()\n .put(new JSONObject().put(\"send_date\", \"now\")\n .put(\"content\", \"test\")\n .put(\"link\", \"http://pushwoosh.com/\"));\n \n JSONObject requestObject = new JSONObject()\n .put(\"application\", APPLICATION_CODE)\n .put(\"auth\", AUTH_TOKEN)\n .put(\"notifications\", notificationsArray);\n \n JSONObject mainRequest = new JSONObject().put(\"request\", requestObject);\n JSONObject response = SendServerRequest.sendJSONRequest(url, mainRequest.toString());\n \n System.out.println(\"Response is: \" + response);\n }\n}\n \nclass SendServerRequest\n{\n static JSONObject sendJSONRequest(URL url, String request)\n {\n HttpURLConnection connection = null;\n try\n {\n connection = (HttpURLConnection) url.openConnection();\n connection.setRequestMethod(\"POST\");\n connection.setRequestProperty(\"Content-Type\", \"application/json\");\n connection.setDoInput(true);\n connection.setDoOutput(true);\n \n DataOutputStream writer = new DataOutputStream(connection.getOutputStream());\n writer.write(request.getBytes(\"UTF-8\"));\n writer.flush();\n writer.close();\n \n return parseResponse(connection);\n }\n catch (Exception e)\n {\n System.out.println(\"An error occurred: \" + e.getMessage());\n return null;\n }\n finally\n {\n if (connection != null)\n {\n connection.disconnect();\n }\n }\n }\n \n static JSONObject parseResponse(HttpURLConnection connection) throws IOException, JSONException\n {\n String line;\n BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));\n StringBuilder response = new StringBuilder();\n \n while ((line = reader.readLine()) != null)\n {\n response.append(line).append('\\r');\n }\n reader.close();\n \n return new JSONObject(response.toString());\n }\n}", "language": "java" }, { "code": "import json\n \nPW_AUTH = 'API TOKEN'\nPW_APPLICATION_CODE = 'APPLICATION CODE'\n \ntry:\n # For Python 3.0 and later\n from urllib.request import urlopen\n from urllib.request import Request\nexcept ImportError:\n # Fall back to Python 2's urllib2\n from urllib2 import urlopen\n from urllib2 import Request\n \ndef pw_call(method, data):\n url = 'https://cp.pushwoosh.com/json/1.3/' + method\n data = json.dumps({'request': data})\n req = Request(url, data.encode('UTF-8'), {'Content-Type': 'application/json'})\n try:\n f = urlopen(req)\n response = f.read()\n f.close()\n print('Pushwoosh response: ' + str(response))\n except Exception as e:\n print ('Request error: ' + str(e))\n \nif __name__ == '__main__':\n pw_call('createMessage', {\n 'auth': PW_AUTH,\n 'application': PW_APPLICATION_CODE,\n 'notifications': [\n {\n 'send_date': 'now',\n 'content': 'test',\n 'data': {\"custom\": \"json data\"},\n 'link': 'http://pushwoosh.com'\n }\n ]\n }\n )", "language": "python" }, { "code": "[sourcecode language=\"csharp\"]\nusing System;\nusing System.IO;\nusing System.Net;\nusing Newtonsoft.Json.Linq;\n\nnamespace WebApplication1\n{\n public partial class Default : System.Web.UI.Page\n {\n protected void Page_Load(object sender, EventArgs e)\n {\n string pwAuth = \"YOUR_AUTH_TOKEN\";\n string pwApplication = \"PW_APPLICATION_CODE\";\n JObject json = new JObject(\n new JProperty(\"application\", pwApplication),\n new JProperty(\"auth\", pwAuth),\n new JProperty(\"notifications\",\n new JArray(\n new JObject(\n new JProperty(\"send_date\", \"now\"),\n new JProperty(\"content\", \"test\"),\n new JProperty(\"wp_type\", \"Toast\"),\n new JProperty(\"wp_count\", 3),\n new JProperty(\"data\",\n new JObject(\n new JProperty(\"custom\", \"json data\"))),\n new JProperty(\"link\", \"http://pushwoosh.com/\"),\n new JProperty(\"conditions\",\n new JArray(\n (object)new JArray(\"Color\", \"EQ\", \"black\")))))));\n PWCall(\"createMessage\", json);\n }\n private void PWCall(string action, JObject data)\n {\n Uri url = new Uri(\"https://cp.pushwoosh.com/json/1.3/\" + action);\n JObject json = new JObject(new JProperty(\"request\", data));\n DoPostRequest(url, json);\n }\n private void DoPostRequest(Uri url, JObject data)\n {\n HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);\n req.ContentType = \"text/json\";\n req.Method = \"POST\";\n using (var streamWriter = new StreamWriter(req.GetRequestStream()))\n {\n streamWriter.Write(data.ToString());\n }\n HttpWebResponse httpResponse;\n try\n {\n httpResponse = (HttpWebResponse)req.GetResponse();\n }\n catch (Exception exc)\n {\n throw new Exception(string.Format(\"Problem with {0}, {1}\", url, exc.Message));\n }\n using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))\n {\n var responseText = streamReader.ReadToEnd();\n Page.Response.Write(responseText);\n }\n }\n }\n}", "language": "csharp", "name": ".NET" } ] } [/block]