{"_id":"584fa746d74a1a0f00c55337","parentDoc":null,"project":"5540ce1b31827a0d007ab1cc","user":"567bb6833241c20d00b730db","version":{"_id":"5540ce1c31827a0d007ab1cf","project":"5540ce1b31827a0d007ab1cc","__v":31,"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","56bc2f033ee9e70d008b46af","56c2f6efbbf9ec2d00e0fe4f","57595bbb18760817001e8bbe","57d8d9793916800e003dde53"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"__v":0,"category":{"_id":"55a4ff5b2e70c0250038050f","pages":["55a4ff7d750a9a23005332af","55a4ff8b750a9a23005332b1","55a4ff9b750a9a23005332b3","55a60bfcaaf9cf1900114efb","55a6184880c8a30d00b32526","55a61ba780c8a30d00b32532","55a61c97aaf9cf1900114f40","55a61ea9aaf9cf1900114f48","55a6206580c8a30d00b32544","55a64277aaf9cf1900114fc2","55a694d1aaf9cf1900115102","55a6a23eaaf9cf19001151e2","55a6a9b389c9da1900e2a41d","55a6aba45f88a70d0065b255","55a90687c8bd450d000dd157","55af84f3aa902f1700300daa","55afa3e3902fd51700f5f858","55b0cc5cb3171b3700b153fa","56015bdc3aa0520d00da0ced","5603fe3490ee490d004404c2","5633dd18d28a340d004004f5","56448c697a8cb50d00a3ea3f","56d7a2ec5208281500a2506c","56d859b8b159f10b00304577","56d9822add90610b002708a1","56ef44c6e8d6fa17006f244f"],"version":"5540ce1c31827a0d007ab1cf","project":"5540ce1b31827a0d007ab1cc","__v":26,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-07-14T12:23:55.603Z","from_sync":false,"order":2,"slug":"features","title":"Features"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-12-13T07:46:14.047Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":30,"body":"This method allows you to send targeted push notifications to your users across their multiple devices. The push notification will be delivered to the last used device.\n\n**How do I send a push by User ID?** \n\n**1.** Call **setUserId** with the first app launch or in case your **User ID** has changed.\n\nFor example User ID could be a user identifier you keep in your own database.\n\nExample (iOS, Android):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[[PushNotificationManager pushManager] setUserId::::at:::“external_user_1”];\",\n      \"language\": \"objectivec\",\n      \"name\": \"iOS\"\n    },\n    {\n      \"code\": \"PushManager.setUserId(context, \\\"external_user_1\\\");\",\n      \"language\": \"java\",\n      \"name\": \"Android\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Login/Logout behavior\",\n  \"body\": \"By default, when an app with Pushwoosh SDK is launched for the first time, it sets a device HWID as a UserID. You can call **setUserId** on a login to set any required value to associate a device with a particular user. When a user logs out, you can reset this value to a default one with another **setUserId** call, e.g. to an initial HWID value.\"\n}\n[/block]\n**2.** Now you are ready to send a push by **User ID**. \n\nYou can use either `/createMessage` API call or upload CSV file with the User ID's.\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"/createMessage\",\n  \"body\": \"Please note that createMessage parameters are fully customizable, so that you can create a highly tailored push message. Check the full list of parameters **[here](http://docs.pushwoosh.com/v1.0/docs/createmessage#section-createmessage).**\"\n}\n[/block]\n## Request\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n\\t\\\"request\\\": {\\n\\t\\t\\\"application\\\": \\\"APPLICATION_CODE\\\",\\n\\t\\t\\\"auth\\\": \\\"API_ACCESS_TOKEN\\\",\\n\\t\\t\\\"notifications\\\": [{\\n\\t\\t\\t\\\"send_date\\\": \\\"now\\\",\\n\\t\\t\\t\\\"content\\\": \\\"Hello world!\\\",\\n\\t\\t\\t\\\"users\\\":[\\\"external_user_1\\\"]\\n\\t\\t}]\\n\\t}\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n## Response\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n   \\\"status_code\\\":200,\\n   \\\"status_message\\\":\\\"OK\\\",\\n   \\\"response\\\": {\\n      \\\"Messages\\\":[\\\"{Notification code}\\\"]\\n   } \\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n## Parameters\n[block:parameters]\n{\n  \"data\": {\n    \"2-0\": \"`send_date`\",\n    \"0-0\": \"`application`\",\n    \"h-0\": \"Parameter\",\n    \"h-1\": \"Description\",\n    \"0-1\": \"Your Pushwoosh application ID where you send the message to (cannot be used together with “applications_group”).\",\n    \"1-0\": \"`auth`\",\n    \"1-1\": \"API access token from the Pushwoosh control panel (create this token at https://cp.pushwoosh.com/api_access).\",\n    \"2-1\": \"Set the time you want the message to be sent (in UTC) or use ‘now’ to send it immediately.\",\n    \"3-0\": \"`content`\",\n    \"3-1\": \"The text for your push notification.\",\n    \"4-0\": \"`users`\",\n    \"4-1\": \"A list of User IDs your push message is sent to. You can send a push to a 1000 User IDs at once.\"\n  },\n  \"cols\": 2,\n  \"rows\": 5\n}\n[/block]","excerpt":"User-centric push notifications","slug":"user-id-push","type":"basic","title":"Push by User ID"}

Push by User ID

User-centric push notifications

This method allows you to send targeted push notifications to your users across their multiple devices. The push notification will be delivered to the last used device. **How do I send a push by User ID?** **1.** Call **setUserId** with the first app launch or in case your **User ID** has changed. For example User ID could be a user identifier you keep in your own database. Example (iOS, Android): [block:code] { "codes": [ { "code": "[[PushNotificationManager pushManager] setUserId:@“external_user_1”];", "language": "objectivec", "name": "iOS" }, { "code": "PushManager.setUserId(context, \"external_user_1\");", "language": "java", "name": "Android" } ] } [/block] [block:callout] { "type": "info", "title": "Login/Logout behavior", "body": "By default, when an app with Pushwoosh SDK is launched for the first time, it sets a device HWID as a UserID. You can call **setUserId** on a login to set any required value to associate a device with a particular user. When a user logs out, you can reset this value to a default one with another **setUserId** call, e.g. to an initial HWID value." } [/block] **2.** Now you are ready to send a push by **User ID**. You can use either `/createMessage` API call or upload CSV file with the User ID's. [block:callout] { "type": "success", "title": "/createMessage", "body": "Please note that createMessage parameters are fully customizable, so that you can create a highly tailored push message. Check the full list of parameters **[here](http://docs.pushwoosh.com/v1.0/docs/createmessage#section-createmessage).**" } [/block] ## Request [block:code] { "codes": [ { "code": "{\n\t\"request\": {\n\t\t\"application\": \"APPLICATION_CODE\",\n\t\t\"auth\": \"API_ACCESS_TOKEN\",\n\t\t\"notifications\": [{\n\t\t\t\"send_date\": \"now\",\n\t\t\t\"content\": \"Hello world!\",\n\t\t\t\"users\":[\"external_user_1\"]\n\t\t}]\n\t}\n}", "language": "json" } ] } [/block] ## Response [block:code] { "codes": [ { "code": "{\n \"status_code\":200,\n \"status_message\":\"OK\",\n \"response\": {\n \"Messages\":[\"{Notification code}\"]\n } \n}", "language": "json" } ] } [/block] ## Parameters [block:parameters] { "data": { "2-0": "`send_date`", "0-0": "`application`", "h-0": "Parameter", "h-1": "Description", "0-1": "Your Pushwoosh application ID where you send the message to (cannot be used together with “applications_group”).", "1-0": "`auth`", "1-1": "API access token from the Pushwoosh control panel (create this token at https://cp.pushwoosh.com/api_access).", "2-1": "Set the time you want the message to be sent (in UTC) or use ‘now’ to send it immediately.", "3-0": "`content`", "3-1": "The text for your push notification.", "4-0": "`users`", "4-1": "A list of User IDs your push message is sent to. You can send a push to a 1000 User IDs at once." }, "cols": 2, "rows": 5 } [/block]