What is the best way to remove a single deviceToken from a subscriber that has several deviceTokens
Hi, I just want to confirm what is the current best way to delete only specific tokens from the array of multiple deviceTokens of a subscriber (I'm using
fcm
).
So far I've only tried using the REST API for updating the subscriber's credentials(https://docs.novu.co/api-reference/subscribers/update-subscriber-credentials)
From my observation on how the updating the credentials work, I found that the provided deviceTokens
in the requests always get added to the current list of the subscriber's deviceTokens
(i.e. if the current deviceTokens
is ["1","2","3"]
, sending a request with deviceTokens: ["4"]
will make it deviceTokens: ["1","2","3","4"]
), that part is actually well and good for me. (It might be worth mentioning that it conflicts with a solution that was provided on an older thread: https://discord.com/channels/895029566685462578/1073310233750933565/1073312550600577145)
However, now I'm wondering what if I want to do the opposite where I want to delete specific tokens from the deviceTokens
array? I observed that updating with deviceTokens: []
indeed clears out all the deviceTokens
. So I'm wondering if the current best way to delete specific tokens is clearing it out first to deviceTokens: []
then doing another update credentials request to set the filtered out deviceTokens
? (2 requests)
(Actually my plan is eventually using the SDK instead of the REST API, but I'm assuming their behaviors should be the same, right? Let me know if otherwise.)
Thanks in advance!5 Replies
It might be worth mentioning that it conflicts with a solution that was provided on an older threadHi @cmendoza As linked post with this line is an old post. We updated this flow as you mentioned yes API and node sdk will behave same I see the particular issue here in deleting the token Currently, this is the only option as you mentioned
So I'm wondering if the current best way to delete specific tokens is clearing it out first to deviceTokens: [] then doing another update credentials request to set the filtered out deviceTokens?let me share it with team to look into this
Okay understood. Our app involves managing
deviceTokens
(adding/deleting) so just wanted to make sure I'm not missing anything regarding moving around deviceTokens
. (I'm still hoping there could be some sort of atomic operation for deleting specific deviceTokens
though)
Thanks!Hi @cmendoza
We have an internal ticket to manage the removal of credentials.
The challenge in push based providers that they can have multiple tokens, other providers like slack, discord all have one webhookurl which is easy to remove.
We are thinking to add a single api which works with all providers.
Would love to know your thoughts
The challenge in push based providers that they can have multiple tokensYeah i hear you on that ππ½ Hmm, my thinking is a feature on the api where I can just feed the specific token that I want to delete from the array (just for context: our app keeps track of the different devices that each user uses, so it's possible to modify/delete them individually). I'm thinking maybe
deviceTokens
(and other array types) can have an alternate form (when updating), something like
Just giving an idea of what I'm wishing for π
Let me check with team, if we can proceed with above approach