NovuN
Novu3y ago
cmendoza

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: How to remove deviceToken)

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!
Was this page helpful?