{"_id":"5a0e04b644969800124f4879","project":"55e67aaa9cc7c62b00c4a1ea","version":{"_id":"55e67aab9cc7c62b00c4a1ed","project":"55e67aaa9cc7c62b00c4a1ea","__v":10,"createdAt":"2015-09-02T04:27:23.612Z","releaseDate":"2015-09-02T04:27:23.612Z","categories":["55e67aac9cc7c62b00c4a1ee","55e67b5556007d23005fee7d","55e67b5dde6fef23009480ca","55e680efde6fef23009480db","55e6829485a9741900314e99","561c61b4ad272c0d00a892df","586c014c0abf1d0f000d04d4","58991d2ad207df0f0002186b","589b8e1fdbb7cd190026732c","58b8ca5e3265d70f001788d4"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"category":{"_id":"589b8e1fdbb7cd190026732c","project":"55e67aaa9cc7c62b00c4a1ea","__v":0,"version":"55e67aab9cc7c62b00c4a1ed","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-02-08T21:31:11.878Z","from_sync":false,"order":6,"slug":"advanced-techniques","title":"Advanced Techniques"},"user":"587fed3d9efedf3b00200366","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-11-16T21:35:50.427Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":999,"body":"In current Carnival 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.","excerpt":"","slug":"updating-pushes","type":"basic","title":"Updating Pushes"}
In current Carnival 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.