{"_id":"56c41dafc0c4630d004e86c3","parentDoc":null,"category":{"_id":"56c4184c28bd680d005e7ac7","__v":5,"project":"56bc8e679afb8b0d00d62dcf","pages":["56c41d876063071700500d06","56c41d92bb64720d00552b94","56c41d9e4f0aed1700afabac","56c41dafc0c4630d004e86c3","56c41dbbc0c4630d004e86c5"],"version":"56bc8e689afb8b0d00d62dd2","sync":{"url":"","isSync":false},"reference":true,"createdAt":"2016-02-17T06:50:52.926Z","from_sync":false,"order":6,"slug":"push","title":"Push"},"project":"56bc8e679afb8b0d00d62dcf","user":"56b98db7bb36440d0001f492","version":{"_id":"56bc8e689afb8b0d00d62dd2","project":"56bc8e679afb8b0d00d62dcf","__v":18,"createdAt":"2016-02-11T13:36:40.146Z","releaseDate":"2016-02-11T13:36:40.146Z","categories":["56bc8e689afb8b0d00d62dd3","56c3c837bc41330d009f25ed","56c3c83e521f350d00d348eb","56c3c8452d97560d00e23cd8","56c3c85234df460d00c2beb8","56c4180d70187b17005f43b4","56c418162d97560d00e23cf6","56c4181cc4796b0d007ef039","56c4182370187b17005f43b5","56c418292e75e01700986052","56c4183328bd680d005e7ac6","56c4183bbb64720d00552b88","56c418414040602b0064cea0","56c4184754b6030d00ec29a1","56c4184c28bd680d005e7ac7","56c4185370187b17005f43b6","56c4185b6063071700500cfc","582a98b6f8c0a0190053d7a5"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"__v":6,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-17T07:13:51.670Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"[block:api-header]\n{\n  \"type\": \"post\",\n  \"title\": \"/notifications\"\n}\n[/block]\nSends a push notification to a list of users by User ID. This will filter a user's registered devices by capability and send the notifications through the platform-specific push providers.\n\n#### Supporting Custom Push\n\nThe Buddy push notifications API is designed to make the most common push scenarios very simple and consistent across providers.  However, many of the push providers support features that are not present across devices.  To support this, we offer the `osCustomData` parameter, which allows you to pass the raw notification payload for each platform.  The value of this should be a JSON object structured in accordance with the following example:\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"    {\\n      \\\"MPNS\\\":\\\"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><wp:Notification xmlns:wp=\\\"WPNotification\\\"><wp:Toast><wp:Text1></wp:Text1>Whoa!<wp:Text2>MyCustomToast</wp:Text2><wp:Param></wp:Param></wp:Toast></wp:Notification>\\\",\\n\\n      \\\"iOS\\\": {\\\"aps\\\":{\\\"alert\\\":\\\"Whoa!\\\",\\\"sound\\\":\\\"a_sound.caf\\\"}},\\n\\n      \\\"Android\\\": {\\\"data\\\":{\\\"message\\\":\\\"Whoa!\\\"}}\\n    }\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nThe appropriate payload will be sent directly to the underlying push provider and will override any values sent in the `message`, `title`, `counterValue`, or `payload` parameters.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\nvar options = {\\n\\tpushType: \\\"Raw\\\",\\n\\trecipients: \\\"['bv.LNjbvtMsLCrq','bv.wPjbbctlLGrq','bv.dCkbvvdLqbvq']\\\",\\n\\tmessage: \\\"Hey your app crashed\\\",\\n\\tcounterValue: 6,\\n\\tpayload: \\\"This looks like some random string to send to the recipient(s)\\\",\\n\\tosCustomData: \\\"{key1: 'value 1', key2: 7}\\\",\\n\\ttitle: \\\"Some Title\\\"\\n};\\n\\nBuddy.post('/notifications',\\n\\t\\toptions,\\n\\t\\tfunction(err, result) {\\n\\t\\t\\t \\n\\t\\t\\tif (result.success) {\\n\\t\\t\\t\\t// Do something with the result!\\n\\t\\t\\t} else { \\n\\t\\t\\t\\t// Otherwise log the error\\n\\t\\t\\t\\tconsole.log(err); \\n\\t\\t\\t} \\n\\t\\t}\\n\\t);\",\n      \"language\": \"javascript\"\n    },\n    {\n      \"code\": \"NSDictionary *params = :::at:::{\\n\\t\\t\\[email protected]\\\"pushType\\\": \\\"Raw\\\",\\n\\t\\t\\[email protected]\\\"recipients\\\": @\\\"['bv.LNjbvtMsLCrq','bv.wPjbbctlLGrq','bv.dCkbvvdLqbvq']\\\",\\n\\t\\t\\[email protected]\\\"message\\\": @\\\"Hey your app crashed\\\",\\n\\t\\t\\[email protected]\\\"counterValue\\\": 6,\\n\\t\\t\\[email protected]\\\"payload\\\": @\\\"This looks like some random string to send to the recipient(s)\\\",\\n\\t\\t\\[email protected]\\\"osCustomData\\\": @\\\"{key1: 'value 1', key2: 7}\\\",\\n\\t\\t\\[email protected]\\\"title\\\": @\\\"Some Title\\\"\\n\\t\\t};\\n\\n[Buddy POST:@\\\"/notifications\\\" parameters:params class:[NSDictionary class] callback:^(id obj, NSError *error) {\\n\\t// Your callback code here\\n}];\",\n      \"language\": \"objectivec\",\n      \"name\": \"iOS\"\n    },\n    {\n      \"code\": \"\\nMap<String, Object> parameters = new HashMap<String, Object>();\\nparameters.put(\\\"pushType\\\", \\\"Raw\\\");\\nparameters.put(\\\"recipients\\\", \\\"['bv.LNjbvtMsLCrq','bv.wPjbbctlLGrq','bv.dCkbvvdLqbvq']\\\");\\nparameters.put(\\\"message\\\", \\\"Hey your app crashed\\\");\\nparameters.put(\\\"counterValue\\\", 6);\\nparameters.put(\\\"payload\\\", \\\"This looks like some random string to send to the recipient(s)\\\");\\nparameters.put(\\\"osCustomData\\\", \\\"{key1: 'value 1', key2: 7}\\\");\\nparameters.put(\\\"title\\\", \\\"Some Title\\\");\\n\\nBuddy.<JsonObject>post(\\\"/notifications\\\", parameters, new BuddyCallback<JsonObject>(JsonObject.class) {\\n\\[email protected]\\n\\tpublic void completed(BuddyResult<JsonObject> result) {\\n\\t\\t// Your callback code here\\n\\t}\\n});\",\n      \"language\": \"java\",\n      \"name\": \"Android\"\n    },\n    {\n      \"code\": \"var options = new {\\n\\t\\t\\tpushType = \\\"Raw\\\",\\n\\t\\t\\trecipients = \\\"['bv.LNjbvtMsLCrq','bv.wPjbbctlLGrq','bv.dCkbvvdLqbvq']\\\",\\n\\t\\t\\tmessage = \\\"Hey your app crashed\\\",\\n\\t\\t\\tcounterValue = 6,\\n\\t\\t\\tpayload = \\\"This looks like some random string to send to the recipient(s)\\\",\\n\\t\\t\\tosCustomData = new {key1 = 'value 1', key2 = 7},\\n\\t\\t\\ttitle = \\\"Some Title\\\"\\n\\t\\t};\\n\\nvar result = await Buddy.PostAsync<Notification>(\\\"/notifications\\\", options);\",\n      \"language\": \"csharp\",\n      \"name\": \".Net\"\n    }\n  ],\n  \"sidebar\": true\n}\n[/block]\n###Body Parameters\n\nThese parameters should be specified as part of the request body.\n[block:parameters]\n{\n  \"data\": {\n    \"0-0\": \"pushType\",\n    \"1-0\": \"recipients\",\n    \"2-0\": \"message\",\n    \"3-0\": \"counterValue\",\n    \"4-0\": \"payload\",\n    \"5-0\": \"osCustomData\",\n    \"6-0\": \"title\",\n    \"0-1\": \"The type of push notification to send to the device. Available options are\\n\\n  * Raw\\n  * Alert\\nIf you do not pass this value, we will imply the type based on the values provided. If only payload is provided we assume Raw, otherwise Alert.\",\n    \"1-1\": \"A list of user ids to receive this notification. If you omit this value the notification will be sent to all app users.\",\n    \"2-1\": \"A message to send in the body of the notification.\",\n    \"3-1\": \"For platforms that support badge counters, update the counter to this value.\",\n    \"4-1\": \"Additional unstructured data to be delivered to the application. For raw notifications, this is the body that will be sent. For other notification types, this will be included as a parameter called payload.\",\n    \"5-1\": \"A JSON-formatted dictionary to pass additional structured data to the application. Keys beginning with \\\"_Buddy\\\" and \\\"_bId\\\" are reserved for consumption by the Buddy SDK for analytics.\",\n    \"6-1\": \"The title for the message. This is ignored for APNS (iOS) notifications.\",\n    \"0-2\": \"string\",\n    \"2-2\": \"string\",\n    \"4-2\": \"string\",\n    \"6-2\": \"string\",\n    \"5-2\": \"JSON\",\n    \"3-2\": \"number\",\n    \"1-2\": \"object\",\n    \"0-3\": \"Optional\",\n    \"1-3\": \"Optional\",\n    \"2-3\": \"Optional\",\n    \"3-3\": \"Optional\",\n    \"4-3\": \"Optional\",\n    \"5-3\": \"Optional\",\n    \"6-3\": \"Optional\"\n  },\n  \"cols\": 4,\n  \"rows\": 7\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"status\\\": 200,\\n  \\\"result\\\": {\\n    \\\"sentByPlatform\\\": {\\n      \\\"apple\\\": 0,\\n      \\\"appleSandbox\\\": 0,\\n      \\\"mpns\\\": 0,\\n      \\\"android\\\": 0,\\n      \\\"htmL5\\\": 0,\\n      \\\"fireOS\\\": 0,\\n      \\\"unknown\\\": 0,\\n      \\\"wns\\\": 0\\n    }\\n  },\\n  \\\"request_id\\\": \\\"53c5b0c5b32fad0f9c61c580\\\",\\n  \\\"success\\\": true\\n} \",\n      \"language\": \"json\",\n      \"name\": \"Response\"\n    }\n  ],\n  \"sidebar\": true\n}\n[/block]","excerpt":"","slug":"send-push-notification","type":"basic","title":"Send Push Notification"}

Send Push Notification


[block:api-header] { "type": "post", "title": "/notifications" } [/block] Sends a push notification to a list of users by User ID. This will filter a user's registered devices by capability and send the notifications through the platform-specific push providers. #### Supporting Custom Push The Buddy push notifications API is designed to make the most common push scenarios very simple and consistent across providers. However, many of the push providers support features that are not present across devices. To support this, we offer the `osCustomData` parameter, which allows you to pass the raw notification payload for each platform. The value of this should be a JSON object structured in accordance with the following example: [block:code] { "codes": [ { "code": " {\n \"MPNS\":\"<?xml version=\"1.0\" encoding=\"UTF-8\"?><wp:Notification xmlns:wp=\"WPNotification\"><wp:Toast><wp:Text1></wp:Text1>Whoa!<wp:Text2>MyCustomToast</wp:Text2><wp:Param></wp:Param></wp:Toast></wp:Notification>\",\n\n \"iOS\": {\"aps\":{\"alert\":\"Whoa!\",\"sound\":\"a_sound.caf\"}},\n\n \"Android\": {\"data\":{\"message\":\"Whoa!\"}}\n }", "language": "text" } ] } [/block] The appropriate payload will be sent directly to the underlying push provider and will override any values sent in the `message`, `title`, `counterValue`, or `payload` parameters. [block:code] { "codes": [ { "code": "\nvar options = {\n\tpushType: \"Raw\",\n\trecipients: \"['bv.LNjbvtMsLCrq','bv.wPjbbctlLGrq','bv.dCkbvvdLqbvq']\",\n\tmessage: \"Hey your app crashed\",\n\tcounterValue: 6,\n\tpayload: \"This looks like some random string to send to the recipient(s)\",\n\tosCustomData: \"{key1: 'value 1', key2: 7}\",\n\ttitle: \"Some Title\"\n};\n\nBuddy.post('/notifications',\n\t\toptions,\n\t\tfunction(err, result) {\n\t\t\t \n\t\t\tif (result.success) {\n\t\t\t\t// Do something with the result!\n\t\t\t} else { \n\t\t\t\t// Otherwise log the error\n\t\t\t\tconsole.log(err); \n\t\t\t} \n\t\t}\n\t);", "language": "javascript" }, { "code": "NSDictionary *params = @{\n\t\t\[email protected]\"pushType\": \"Raw\",\n\t\t\[email protected]\"recipients\": @\"['bv.LNjbvtMsLCrq','bv.wPjbbctlLGrq','bv.dCkbvvdLqbvq']\",\n\t\t\[email protected]\"message\": @\"Hey your app crashed\",\n\t\t\[email protected]\"counterValue\": 6,\n\t\t\[email protected]\"payload\": @\"This looks like some random string to send to the recipient(s)\",\n\t\t\[email protected]\"osCustomData\": @\"{key1: 'value 1', key2: 7}\",\n\t\t\[email protected]\"title\": @\"Some Title\"\n\t\t};\n\n[Buddy POST:@\"/notifications\" parameters:params class:[NSDictionary class] callback:^(id obj, NSError *error) {\n\t// Your callback code here\n}];", "language": "objectivec", "name": "iOS" }, { "code": "\nMap<String, Object> parameters = new HashMap<String, Object>();\nparameters.put(\"pushType\", \"Raw\");\nparameters.put(\"recipients\", \"['bv.LNjbvtMsLCrq','bv.wPjbbctlLGrq','bv.dCkbvvdLqbvq']\");\nparameters.put(\"message\", \"Hey your app crashed\");\nparameters.put(\"counterValue\", 6);\nparameters.put(\"payload\", \"This looks like some random string to send to the recipient(s)\");\nparameters.put(\"osCustomData\", \"{key1: 'value 1', key2: 7}\");\nparameters.put(\"title\", \"Some Title\");\n\nBuddy.<JsonObject>post(\"/notifications\", parameters, new BuddyCallback<JsonObject>(JsonObject.class) {\n\[email protected]\n\tpublic void completed(BuddyResult<JsonObject> result) {\n\t\t// Your callback code here\n\t}\n});", "language": "java", "name": "Android" }, { "code": "var options = new {\n\t\t\tpushType = \"Raw\",\n\t\t\trecipients = \"['bv.LNjbvtMsLCrq','bv.wPjbbctlLGrq','bv.dCkbvvdLqbvq']\",\n\t\t\tmessage = \"Hey your app crashed\",\n\t\t\tcounterValue = 6,\n\t\t\tpayload = \"This looks like some random string to send to the recipient(s)\",\n\t\t\tosCustomData = new {key1 = 'value 1', key2 = 7},\n\t\t\ttitle = \"Some Title\"\n\t\t};\n\nvar result = await Buddy.PostAsync<Notification>(\"/notifications\", options);", "language": "csharp", "name": ".Net" } ], "sidebar": true } [/block] ###Body Parameters These parameters should be specified as part of the request body. [block:parameters] { "data": { "0-0": "pushType", "1-0": "recipients", "2-0": "message", "3-0": "counterValue", "4-0": "payload", "5-0": "osCustomData", "6-0": "title", "0-1": "The type of push notification to send to the device. Available options are\n\n * Raw\n * Alert\nIf you do not pass this value, we will imply the type based on the values provided. If only payload is provided we assume Raw, otherwise Alert.", "1-1": "A list of user ids to receive this notification. If you omit this value the notification will be sent to all app users.", "2-1": "A message to send in the body of the notification.", "3-1": "For platforms that support badge counters, update the counter to this value.", "4-1": "Additional unstructured data to be delivered to the application. For raw notifications, this is the body that will be sent. For other notification types, this will be included as a parameter called payload.", "5-1": "A JSON-formatted dictionary to pass additional structured data to the application. Keys beginning with \"_Buddy\" and \"_bId\" are reserved for consumption by the Buddy SDK for analytics.", "6-1": "The title for the message. This is ignored for APNS (iOS) notifications.", "0-2": "string", "2-2": "string", "4-2": "string", "6-2": "string", "5-2": "JSON", "3-2": "number", "1-2": "object", "0-3": "Optional", "1-3": "Optional", "2-3": "Optional", "3-3": "Optional", "4-3": "Optional", "5-3": "Optional", "6-3": "Optional" }, "cols": 4, "rows": 7 } [/block] [block:code] { "codes": [ { "code": "{\n \"status\": 200,\n \"result\": {\n \"sentByPlatform\": {\n \"apple\": 0,\n \"appleSandbox\": 0,\n \"mpns\": 0,\n \"android\": 0,\n \"htmL5\": 0,\n \"fireOS\": 0,\n \"unknown\": 0,\n \"wns\": 0\n }\n },\n \"request_id\": \"53c5b0c5b32fad0f9c61c580\",\n \"success\": true\n} ", "language": "json", "name": "Response" } ], "sidebar": true } [/block]