- A
notifications#createcall is made - OneSignal processes the request and begins sending the notification
- A network error occurs and no response is ever received by your client.
- If the notification did send and the request is sent again, your users will see duplicate notifications.
- If it did not send and the request is not retried, your users might miss important notifications.
idempotency_key field exists on notifications for precisely this reason.
A unique identifier used to prevent duplicate messages from repeat API calls. Keys must be unique RFC 9562 UUID format. Valid for 30 days.
- A
notifications#createcall is made withidempotency_key - OneSignal processes the request and begins sending the notification
- A network error occurs and no response is ever received by your client.
- A
notifications#createcall is made again with the sameidempotency_keyas the previous one. - OneSignal recognizes the notification has already begun sending, and returns the result of the previous operation.
idempotency_key is the same in each request, only 1 notification will be delivered to your users regardless of the number of times the request is sent to our api.
Because the api will not send a notification if the idempotency_key already exists in our database, it’s important to use a good source of randomness when generating the uuid passed.
It’s important to note this key is only idempotent for 30 days. After 30 days, the notification could be removed from our system and a notification with the same idempotency_key will be sent again.
This
idempotency_key property used to be called external_id but caused
confusion with our Users alias, so we have added this new
property name to reduce confusion. Both will work in this case.