{"_id":"55af9322c8a85321007a53c5","category":{"_id":"5540ce1c31827a0d007ab1d0","version":"5540ce1c31827a0d007ab1cf","pages":["5540ce1d31827a0d007ab1d2","5540ff9dbb9e762d00f59557","554109205cf9682100d61b65","554109c35cf9682100d61b6b","55a635b6249a40190051d9a2","55bb5de0a8400c2d00873e19","55bb5f4174f10a0d002209a2","55bb607374f10a0d002209a6","55bb614f7313650d00c46e88","55bb61d8a8400c2d00873e20","55bb629874f10a0d002209aa","55bb6318a8400c2d00873e23","55bb63a07313650d00c46e8a","55d5dc84988e130d000b4110","5620b53d40e2c30d0002a848","567cfe57221af70d00fc5498","567d01fd221af70d00fc549c"],"project":"5540ce1b31827a0d007ab1cc","__v":17,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-04-29T12:27:08.888Z","from_sync":false,"order":1,"slug":"remote-api","title":"Remote API"},"parentDoc":null,"project":"5540ce1b31827a0d007ab1cc","__v":17,"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"},"user":"55a79a4d4a33f92b00b7a111","updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-07-22T12:57:06.377Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":17,"body":"[block:callout]\n{\n  \"type\": \"danger\",\n  \"title\": \"Hard mode\",\n  \"body\": \"Should you be using [createMessage](http://docs.pushwoosh.com/docs/createmessage) instead?\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"The method is intended for advanced targeting of your messages, and can be used for sending messages **across several or all of your apps**. If you do not include Application Code in your device filters, the message will be sent to any device registered in your account, that fits the Tag condition.\\nPlease make sure that you target proper applications in order to avoid sending test pushes to the production application.\"\n}\n[/block]\nThe basics are very simple – all filters are performed on the **sets** of entities.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Sets\"\n}\n[/block]\nSets are defined as:\n\n**1.** Devices subscribed to the particular app\n**2.** Devices that match the specific tag value\n**3.** Devices subscribed to one app of the app group\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Syntax\"\n}\n[/block]\nLet’s try with some samples according to the list above.\n\n`A(\"XXXXX-XXXXX\", [\"iOS\", \"Android\", \"Blackberry\", \"Windows_Phone”, \"OsX\", \"Windows\", \"Amazon\", \"Safari\", \"Chrome\", \"Firefox\"])`\n\nDefines the set of devices that are subscribed to the app with the App Code “XXXXX-XXXXX”. The platform specifier is optional and, if omitted, means that the message will be sent to all platforms available for this app.\n\n`T(\"age\", BETWEEN, [17,20])`\n\nDefines the set of the devices which have the “age” tag set to one of the values: 17, 18, 19, 20.\n\n`G(\"11111-11111\", [\"iOS\",\"Android\"])`\n\nSame as “A” but applicable to the app groups.\n\n`AT(“XXXXX-XXXXX”, “TagName”, EQ, “VALUE”)`\n\nApplicable to Application-specific Tags only.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Tags\"\n}\n[/block]\nThe very important thing to understand is that tags are shared between the apps, and it presents a very powerful instrument for segmenting and filtering your target users without binding yourself to a particular app.\n\nThe tag could be one of the three different types: **String, Integer, List**. This defines different operators you can use for a particular tag.\n\n**String: EQ, IN, NOTIN, NOTEQ**\n\nExample: `T(\"username\", EQ, \"my_username\"), T(\"favorite_color\", IN, [\"red\",\"green\",\"blue\"])`.\n\nYou can use numeric values with the string tags but such values will be converted to a string.\n\n**Integer: GTE, LTE, EQ, BETWEEN, NOTIN, IN, NOTEQ**\n\nGTE – Greater than or equal to\n\nLTE – Less than or equal to\n\nBETWEEN – `T(\"age\", BETWEEN, [min_value,max_value])`. ‘min_value’ and ‘max_value’ must be integer numbers. ‘min_value ‘must be less than ‘max_value’.\n\nIN - `T(\"age\", IN, [value1, value2])`. The tag value should be one of the following values. \n\nNOTIN - `T(\"age\", NOTIN, [value1, value2])`. The tag value should NOT be one of the following values.\n\n**List: IN** only. \n\nExample: `T(\"Category\", IN, [\"breaking_news\",\"business\",\"politics\"])`.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Operations\"\n}\n[/block]\n* “+” – joins two sets\n* “*” – intersects two sets\n* “\\” – subtracts one set from another\nAll the operations are left associative. “+” and “*” have the same priority. “\\” has greater priority. You can use brackets to define priorities of the calculations.\n\nNote that “\\” operation is not commutative. `A(\"12345-12345\") \\ A(\"67890-67890\")` is not the same as `A(\"67890-67890\") \\ A(\"12345-12345\")`.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Examples\"\n}\n[/block]\n**Easy:**\n\n`A(\"00000-00000\", [\"iOS\"])` – all iOS devices subscribed to the app 00000-00000\n\n`A(\"00000-00000\") * T(\"gender\", EQ, \"F\")` – all devices subscribed to the app 00000-00000, which have the gender tag set to “female”.\n\n`A(\"00000-00000\") * T(\"username\", EQ, \"myuser\")` – all devices subscribed to the app 00000-00000 which have the “myuser” username .\n\n**Hard:**\n\n`( A(\"00000-00000\") + A(\"11111-11111\") ) \\ A(\"12345-12345\")` – all devices subscribed to the app 00000-00000 OR 11111-11111, which don’t have the app 12345-12345 installed\n\n**Hardcore:**\n\n`( A(\"00000-00000\") * T(\"gender\", EQ, \"M\") ) + ( A(\"12345-12345\") * T(\"gender\", EQ, \"F\") )` – Targets all men with the app 00000-00000 and all girls with the app 12345-12345\n\n**Fun:**\n\n`T(\"gender\", EQ, \"F\") * T(\"age\", BETWEEN, [18, 22])` – targets college-aged girls who have any of your apps installed.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Usage\"\n}\n[/block]\nService URL is `https://cp.pushwoosh.com/json/1.3/createTargetedMessage`\nSend POST request with the JSON data as shown below:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\\"request\\\":{\\n   \\\"auth\\\":\\\"PW AUTH TOKEN\\\",\\n   \\\"send_date\\\":\\\"now\\\",\\n   \\\"content\\\": \\\"Hello world\\\",\\n   \\\"devices_filter\\\":\\\"A(\\\\\\\"00000-00000\\\\\\\") * T(\\\\\\\"age\\\\\\\", BETWEEN, [17, 19])\\\"\\n}}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"body\": \"You cannot use any of the following targeting-related parameters in the /createTargetedMessage request:\\n* \\\"application\\\"\\n* \\\"applications_group\\\"\\n* \\\"platforms\\\"\\n* \\\"devices\\\"\\n* \\\"filter\\\"\\n* \\\"conditions\\\"\\n\\nAll the other parameters listed in [/createMessage](http://docs.pushwoosh.com/docs/createmessage) guide are supported.\",\n  \"title\": \"Note\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"There is a known issue with the createTargetedMessage method: if you don’t specify any applications in “devices_filter” section, Pushwoosh doesn’t display any applications in push details.\"\n}\n[/block]","excerpt":"","slug":"createtargetedmessage","type":"basic","title":"/createTargetedMessage"}

/createTargetedMessage


[block:callout] { "type": "danger", "title": "Hard mode", "body": "Should you be using [createMessage](http://docs.pushwoosh.com/docs/createmessage) instead?" } [/block] [block:callout] { "type": "warning", "body": "The method is intended for advanced targeting of your messages, and can be used for sending messages **across several or all of your apps**. If you do not include Application Code in your device filters, the message will be sent to any device registered in your account, that fits the Tag condition.\nPlease make sure that you target proper applications in order to avoid sending test pushes to the production application." } [/block] The basics are very simple – all filters are performed on the **sets** of entities. [block:api-header] { "type": "basic", "title": "Sets" } [/block] Sets are defined as: **1.** Devices subscribed to the particular app **2.** Devices that match the specific tag value **3.** Devices subscribed to one app of the app group [block:api-header] { "type": "basic", "title": "Syntax" } [/block] Let’s try with some samples according to the list above. `A("XXXXX-XXXXX", ["iOS", "Android", "Blackberry", "Windows_Phone”, "OsX", "Windows", "Amazon", "Safari", "Chrome", "Firefox"])` Defines the set of devices that are subscribed to the app with the App Code “XXXXX-XXXXX”. The platform specifier is optional and, if omitted, means that the message will be sent to all platforms available for this app. `T("age", BETWEEN, [17,20])` Defines the set of the devices which have the “age” tag set to one of the values: 17, 18, 19, 20. `G("11111-11111", ["iOS","Android"])` Same as “A” but applicable to the app groups. `AT(“XXXXX-XXXXX”, “TagName”, EQ, “VALUE”)` Applicable to Application-specific Tags only. [block:api-header] { "type": "basic", "title": "Tags" } [/block] The very important thing to understand is that tags are shared between the apps, and it presents a very powerful instrument for segmenting and filtering your target users without binding yourself to a particular app. The tag could be one of the three different types: **String, Integer, List**. This defines different operators you can use for a particular tag. **String: EQ, IN, NOTIN, NOTEQ** Example: `T("username", EQ, "my_username"), T("favorite_color", IN, ["red","green","blue"])`. You can use numeric values with the string tags but such values will be converted to a string. **Integer: GTE, LTE, EQ, BETWEEN, NOTIN, IN, NOTEQ** GTE – Greater than or equal to LTE – Less than or equal to BETWEEN – `T("age", BETWEEN, [min_value,max_value])`. ‘min_value’ and ‘max_value’ must be integer numbers. ‘min_value ‘must be less than ‘max_value’. IN - `T("age", IN, [value1, value2])`. The tag value should be one of the following values. NOTIN - `T("age", NOTIN, [value1, value2])`. The tag value should NOT be one of the following values. **List: IN** only. Example: `T("Category", IN, ["breaking_news","business","politics"])`. [block:api-header] { "type": "basic", "title": "Operations" } [/block] * “+” – joins two sets * “*” – intersects two sets * “\” – subtracts one set from another All the operations are left associative. “+” and “*” have the same priority. “\” has greater priority. You can use brackets to define priorities of the calculations. Note that “\” operation is not commutative. `A("12345-12345") \ A("67890-67890")` is not the same as `A("67890-67890") \ A("12345-12345")`. [block:api-header] { "type": "basic", "title": "Examples" } [/block] **Easy:** `A("00000-00000", ["iOS"])` – all iOS devices subscribed to the app 00000-00000 `A("00000-00000") * T("gender", EQ, "F")` – all devices subscribed to the app 00000-00000, which have the gender tag set to “female”. `A("00000-00000") * T("username", EQ, "myuser")` – all devices subscribed to the app 00000-00000 which have the “myuser” username . **Hard:** `( A("00000-00000") + A("11111-11111") ) \ A("12345-12345")` – all devices subscribed to the app 00000-00000 OR 11111-11111, which don’t have the app 12345-12345 installed **Hardcore:** `( A("00000-00000") * T("gender", EQ, "M") ) + ( A("12345-12345") * T("gender", EQ, "F") )` – Targets all men with the app 00000-00000 and all girls with the app 12345-12345 **Fun:** `T("gender", EQ, "F") * T("age", BETWEEN, [18, 22])` – targets college-aged girls who have any of your apps installed. [block:api-header] { "type": "basic", "title": "Usage" } [/block] Service URL is `https://cp.pushwoosh.com/json/1.3/createTargetedMessage` Send POST request with the JSON data as shown below: [block:code] { "codes": [ { "code": "{\"request\":{\n \"auth\":\"PW AUTH TOKEN\",\n \"send_date\":\"now\",\n \"content\": \"Hello world\",\n \"devices_filter\":\"A(\\\"00000-00000\\\") * T(\\\"age\\\", BETWEEN, [17, 19])\"\n}}", "language": "json" } ] } [/block] [block:callout] { "type": "danger", "body": "You cannot use any of the following targeting-related parameters in the /createTargetedMessage request:\n* \"application\"\n* \"applications_group\"\n* \"platforms\"\n* \"devices\"\n* \"filter\"\n* \"conditions\"\n\nAll the other parameters listed in [/createMessage](http://docs.pushwoosh.com/docs/createmessage) guide are supported.", "title": "Note" } [/block] [block:callout] { "type": "info", "body": "There is a known issue with the createTargetedMessage method: if you don’t specify any applications in “devices_filter” section, Pushwoosh doesn’t display any applications in push details." } [/block]