Migrating push tokens
A push token is a unique anonymous identifier that specifies where to send an app’s notifications. Braze connects with push service providers like Firebase Cloud Messaging Service (FCMs) for Android and Apple Push Notification Service (APNs) for iOS, and those providers send unique device tokens that identify your app. If you were sending push notifications prior to integrating Braze, either on your own or through another provider, push token migration allows you to continue sending push notifications to your users with registered push tokens.
Automatic migration via SDK
After you integrate the Braze SDK, push tokens for your opted-in users will be automatically migrated the next time they open your app. Until then, you won’t be able to send those users push notifications through Braze.
Alternatively, you can migrate your push tokens manually, allowing you to re-engage your users more promptly.
Web token considerations
Due to the nature of web push tokens, be sure you consider the following when implementing push for web:
Consideration | Details |
---|---|
Service workers | By default, the Web SDK will look for a service worker at ./service-worker unless another option is specified, such as manageServiceWorkerExternally or serviceWorkerLocation . If your service worker isn’t set up properly, it may lead to expired push tokens for your users. |
Expired tokens | If a user hasn’t started a web session within 60 days, their push token will expire. Since Braze can’t migrate expired push tokens, you’ll need to send a push primer to re-engage them. |
Manual migration via API
Manual push token migration is the process of importing these previously-created keys into your Braze platform through the API.
Programmatically migrate iOS (APNs) and Android (FCM) tokens to your platform by using the users/track
endpoint. You can migrate both identified users (users with an associated external ID) and anonymous users (users without an external ID).
Specify your app’s app_id
during push token migration to associate the appropriate push token with the appropriate app. Each app (iOS, Android, etc.) has its own app_id
, which can be found in the Identification section of the API Keys page. Be sure to use the correct platform’s app_id
.
It is not possible to migrate web push tokens through the API. This is because web push tokens do not conform to the same schema as other platforms.
If you are attempting to migrate web push tokens programmatically, you might see an error like the following: Received '400: Invalid subscription auth' sending to 'https://fcm.googleapis.com/fcm/send
As an alternative to API migration, we recommend that you integrate the SDK and allow your token base to repopulate naturally.
For identified users, set the push_token_import
flag to false
(or omit the parameter) and specify the external_id
, app_id
, and token
values in the user attributes
object.
For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
curl --location --request POST 'https://rest.iad-01.braze.com/users/track' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR-API-KEY-HERE' \
--data-raw '{
"attributes" : [
{
"push_token_import" : false,
"external_id": "example_external_id",
"country": "US",
"language": "en",
"YOUR_CUSTOM_ATTRIBUTE": "YOUR_VALUE",
"push_tokens": [
{"app_id": "APP_ID_OF_OS", "token": "PUSH_TOKEN_STRING"}
]
}
]
}'
When importing push tokens from other systems, an external_id
is not always available. In this circumstance, set your push_token_import
flag as true
and specify the app_id
and token
values. Braze will create a temporary, anonymous user profile for each token to enable you to continue to message these individuals. If the token already exists in Braze, the request is ignored.
For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
curl --location --request POST 'https://rest.iad-01.braze.com/users/track' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR-API-KEY-HERE' \
--data-raw '{
"attributes": [
{
"push_token_import" : true,
"email": "[email protected]",
"country": "US",
"language": "en",
"YOUR_CUSTOM_ATTRIBUTE": "YOUR_VALUE",
"push_tokens": [
{"app_id": "APP_ID_OF_OS", "token": "PUSH_TOKEN_STRING", "device_id": "DEVICE_ID"}
]
},
{
"push_token_import" : true,
"email": "[email protected]",
"country": "US",
"language": "en",
"YOUR_CUSTOM_ATTRIBUTE_1": "YOUR_VALUE",
"YOUR_CUSTOM_ATTRIBUTE_2": "YOUR_VALUE",
"push_tokens": [
{"app_id": "APP_ID_OF_OS", "token": "PUSH_TOKEN_STRING", "device_id": "DEVICE_ID"}
]
}
]
}'
After import, when the anonymous user launches the Braze-enabled version of your app, Braze will automatically move their imported push token to their Braze user profile and clean up the temporary profile.
Braze will check once a month to find any anonymous profile with the push_token_import
flag that doesn’t have a push token. If the anonymous profile no longer has a push token, we will delete the profile. However, if the anonymous profile still has a push token, suggesting that the actual user has yet to log in to the device with said push token, we will do nothing.
Importing Android push tokens
The following consideration only applies for Android apps. iOS apps will not require these steps because that platform has only one framework for displaying push, and push notifications will render immediately as long as Braze has the necessary push tokens and certificates.
If you must send Android push notifications to your users before the Braze SDK integration is complete, use key-value pairs to validate push notifications.
You must have a receiver to handle and display push payloads. To notify the receiver of the push payload, add the necessary key-value pairs to the push campaign. The values of these pairs are contingent on the specific push partner you used before Braze.
For some push notification providers, Braze will need to flatten the key-value pairs so that they can be properly interpreted. To flatten key-value pairs for a specific Android app, contact your Customer Onboarding or Success Manager.
Last updated on December 5, 2022