Channel Token
Channel Tokens are unique identifiers used to deliver notifications to specific users through certain channels. They ensure notification routing and act as a bridge between MagicBell and external platforms.
They can be strings or data structures, and are linked to a user. They enable MagicBell to deliver notifications to specific accounts and devices, or different devices with multiple tokens per channel.
Channels like email and SMS do not use tokens, relying instead on email addresses or phone numbers.
Managing Tokens
Tokens are managed via the API and can be inspected in the dashboard as part of user details. To register a token, send a POST
request. For example, to save an APNs token:
curl --request POST \
--url 'https://api.magicbell.com/v2/channels/mobile_push/apns/tokens' \
--header 'authorization: Bearer {token}' \
--data '{"device_token":"eH0fLhuiRj2Np7UQ-opXAm:APA91bGtC-wH4sgW1jWkMKIZf7FYkm_RTQb7Jid7DfSJnCgivGYoRzhLrGxpcIF6yPjmbzAr6CKF-6phZkBasFUUfZmfdgcqfA_ZlZdVk6pSnon3LGzMumCzEJE0zgWoo_RUmVUVJUAt","installation_id":"development"}'
Token Lifecycle
- Registration: Once a token is registered for a user, MagicBell uses it for the next notification (unless otherwise specified in the delivery planner).
- Rejection Handling: If a token is rejected by the external platform, MagicBell logs the error and marks the token as discarded.
- Reactivation: If the same token is re-registered, it will be reactivated and used for future deliveries.
Best Practices
-
Register on Sign-In: Register a token when a user signs in to your application. At this point, you can identify the user and access their token.
-
Unregister on Sign-Out: Discard tokens when a user signs out by sending a
DELETE
request to the token endpoint. For example:curl --request DELETE \ --url 'https://api.magicbell.com/v2/channels/mobile_push/apns/tokens/{token_id}' \ --header 'authorization: Bearer {token}' \ --data '{}'
-
Keep Tokens Updated: Re-register the token regularly, such as during every application launch or user sign-in. This ensures the latest token is always on file, enabling seamless notification delivery. Registering the same token multiple times won't cause any harm.