{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","results":{"codes":[]},"settings":"","params":[],"apiSetting":null},"next":{"description":"","pages":[]},"title":"Updating Pushes","type":"basic","slug":"updating-pushes","excerpt":"","body":"In current Sailthru Mobile SDKs, `collapse_key` can be used to update pushes on the client side. For this to work, both the push to be updated and the push updating it must have the `collapse_key`.\n[block:api-header]\n{\n  \"title\": \"Example 1: Fixing a typo\"\n}\n[/block]\nIf we were to accidentally sent a push with a typo:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -X POST -u :API_KEY -H \\\"Content-type: application/json\\\" -H 'Accept: application/json' https://api.carnivalmobile.com/v5/notifications -d ' {\\n  \\\"notification\\\": {\\n    \\\"to\\\":  \\\"*\\\",\\n    \\\"payload\\\": {\\n      \\\"alert\\\": \\\"Greg deals on the new iPhone!\\\",\\n      \\\"collapse_key\\\": \\\"foobar\\\"\\n    }\\n  }\\n}'\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\nWe could then fix the typo by sending a new push to the same audience with the same `collapse_key`:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -X POST -u :API_KEY -H \\\"Content-type: application/json\\\" -H 'Accept: application/json' https://api.carnivalmobile.com/v5/notifications -d ' {\\n  \\\"notification\\\": {\\n    \\\"to\\\":  \\\"*\\\",\\n    \\\"payload\\\": {\\n      \\\"alert\\\": \\\"Great deals on the new iPhone!\\\",\\n      \\\"collapse_key\\\": \\\"foobar\\\"\\n    }\\n  }\\n}'\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\nThis new push would arrive at user's devices, and replace the existing one. It will, however, still alert the user in whatever ways it's set up to when it arrives - sounds, vibration, lights, etc.\n[block:api-header]\n{\n  \"title\": \"Example 2: Only ever showing one notification\"\n}\n[/block]\nIt can be all too easy to clutter your user's notification trays with alerts, so you might want to only ever show one notification in your users tray. .\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"A push with a `collapse_key` will only replace another notification if it's already in the tray - if there's nothing to replace, then the push will just show up like normal\"\n}\n[/block]\nTo make sure only one notification ever shows at a time, simply give every notification the same `collapse_key`. This means that if there's a notification in the tray, the incoming one will replace it. If there's no notification from your app in the tray, then it'll show up like normal.","updates":[],"order":6,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"5b1f2cbdfd653400031d8d9a","project":"55e67aaa9cc7c62b00c4a1ea","version":{"version":"1.3","version_clean":"1.3.0","codename":"rebrand","is_stable":false,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["5b1f2cbdfd653400031d8d42","5b1f2cbdfd653400031d8d43","5b1f2cbdfd653400031d8d44","5b1f2cbdfd653400031d8d45","5b1f2cbdfd653400031d8d46","561c61b4ad272c0d00a892df","586c014c0abf1d0f000d04d4","58991d2ad207df0f0002186b","5b1f2cbdfd653400031d8d47","5b1f2cbdfd653400031d8d48","5af0fe494ca2730003cbc98a","5af0fe55ec80af0003804ca2"],"_id":"5b1f2cbdfd653400031d8d9f","project":"55e67aaa9cc7c62b00c4a1ea","__v":0,"forked_from":"55e67aab9cc7c62b00c4a1ed","createdAt":"2015-09-02T04:27:23.612Z","releaseDate":"2015-09-02T04:27:23.612Z"},"category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Advanced Techniques","slug":"advanced-techniques","order":7,"from_sync":false,"reference":false,"_id":"5b1f2cbdfd653400031d8d47","project":"55e67aaa9cc7c62b00c4a1ea","createdAt":"2017-02-08T21:31:11.878Z","__v":0,"version":"5b1f2cbdfd653400031d8d9f"},"user":"587fed3d9efedf3b00200366","createdAt":"2017-11-16T21:35:50.427Z","githubsync":"","__v":0,"parentDoc":null}
In current Sailthru Mobile SDKs, `collapse_key` can be used to update pushes on the client side. For this to work, both the push to be updated and the push updating it must have the `collapse_key`. [block:api-header] { "title": "Example 1: Fixing a typo" } [/block] If we were to accidentally sent a push with a typo: [block:code] { "codes": [ { "code": "curl -X POST -u :API_KEY -H \"Content-type: application/json\" -H 'Accept: application/json' https://api.carnivalmobile.com/v5/notifications -d ' {\n \"notification\": {\n \"to\": \"*\",\n \"payload\": {\n \"alert\": \"Greg deals on the new iPhone!\",\n \"collapse_key\": \"foobar\"\n }\n }\n}'", "language": "curl" } ] } [/block] We could then fix the typo by sending a new push to the same audience with the same `collapse_key`: [block:code] { "codes": [ { "code": "curl -X POST -u :API_KEY -H \"Content-type: application/json\" -H 'Accept: application/json' https://api.carnivalmobile.com/v5/notifications -d ' {\n \"notification\": {\n \"to\": \"*\",\n \"payload\": {\n \"alert\": \"Great deals on the new iPhone!\",\n \"collapse_key\": \"foobar\"\n }\n }\n}'", "language": "curl" } ] } [/block] This new push would arrive at user's devices, and replace the existing one. It will, however, still alert the user in whatever ways it's set up to when it arrives - sounds, vibration, lights, etc. [block:api-header] { "title": "Example 2: Only ever showing one notification" } [/block] It can be all too easy to clutter your user's notification trays with alerts, so you might want to only ever show one notification in your users tray. . [block:callout] { "type": "info", "body": "A push with a `collapse_key` will only replace another notification if it's already in the tray - if there's nothing to replace, then the push will just show up like normal" } [/block] To make sure only one notification ever shows at a time, simply give every notification the same `collapse_key`. This means that if there's a notification in the tray, the incoming one will replace it. If there's no notification from your app in the tray, then it'll show up like normal.