Differentiate tokens

Hello! Can you explain, please how we can differentiate between iOS, android and browser push tokens because we should use this information in our BE side. Thank you in advance for answer ☺️
5 Replies
Ask Inkeep
Ask Inkeep2mo ago
Hi @Sasha Trityak, I'm an AI assistant for Novu. While a team member reviews this question, I'll see if I can find relevant sources for your question. ----------------------------- While I generate an answer, here are some sources that might be helpful: * How to send push notifications to Flutter apps (Android & iOS) with FCM using Novu * How to send PUSH notifications to iOS devices with FCM using Novu * How to send push notifications in an Android app (react native) with FCM and Novu * Onesignal ----------------------------- Answer Hello! Differentiating between iOS, Android, and browser push tokens involves recognizing the specific format or source of these tokens, as they are generally unique to the platform or service generating them. Here’s how you can typically differentiate them: 1. iOS (APNs) Tokens: These tokens are provided by Apple Push Notification service (APNs). They are typically in a specific format that looks like a 64 hexadecimal character string. 2. Android (FCM) Tokens: These tokens are provided by Firebase Cloud Messaging (FCM). They are also in a unique format, usually a long string of alphanumeric characters including colon and possibly underscore characters. 3. Browser Push Tokens: For web applications, the push tokens depend on the browser's push service (like Firebase Cloud Messaging for Chrome). They can look similar to Android tokens but are used in the context of web browsers. On the backend side, your system can inspect the token format to infer the platform type or maintain a mapping of token types when tokens are registered or updated in your system. Each notification service provides specific guidelines and utilities to validate the token's format. For your implementation in Novu, when you manage these tokens via the API, ensure they are correctly associated with the appropriate subscriber and provider. Here’s an example of how you might update a subscriber's credentials in Novu for different platforms using the API:
curl --request PUT \
--url https://api.novu.co/v1/subscribers/{subscriber_id}/credentials \
--header 'Content-Type: application/json' \
--header 'Authorization: ApiKey <YOUR_API_KEY>' \
--data '{
"credentials": {
"deviceTokens": ["<insert-token-here>"]
},
"integrationIdentifier": "<Provider_Identifier>",
"providerId": "<fcm_or_apns>"
}'
curl --request PUT \
--url https://api.novu.co/v1/subscribers/{subscriber_id}/credentials \
--header 'Content-Type: application/json' \
--header 'Authorization: ApiKey <YOUR_API_KEY>' \
--data '{
"credentials": {
"deviceTokens": ["<insert-token-here>"]
},
"integrationIdentifier": "<Provider_Identifier>",
"providerId": "<fcm_or_apns>"
}'
Ensure you replace <insert-token-here>, <Provider_Identifier>, and <fcm_or_apns> with actual values based on the token and platform. For iOS, use 'apns', and for Android or browsers using FCM, use 'fcm'. By maintaining clear distinctions and proper mappings in your backend, you can effectively manage and target notifications across different devices and platforms. Got it. Tagging @Support for additional help.
LUCKY
LUCKY2mo ago
Hey all, we have a similar request, also for browser tokens. We have browser, ios and android tokens for onesignal
Tomer Barnea
Tomer Barnea2mo ago
Hey @Pawan Jain @Moderator, can you help out here?
Pawan Jain
Pawan Jain2mo ago
@LUCKY @Sasha Trityak Thanks for sharing the request. Currently deviceTokens field is of array of strings type which can store only strings value. so it will not be possible to have this information there. What do you think, if we make this field array of objects
LUCKY
LUCKY2mo ago
@Pawan Jain thanks for your answer but then, we just put all iOS, Android, and Browser tokens there? will then Novu register the token correctly with OneSignal or other providers?