# Importing push tokens and users

> How users, attributes, email addresses, phone numbers and push tokens get into Herald today, through the server API, the contacts API and the SDK, and what to do with the tokens Braze holds.

Before Herald can send to your existing users, it needs three things for each of them: a user record, the attributes agents target on, and the contact points it sends to (push tokens, email addresses, phone numbers). This page explains where each comes from today and the order to load them in.

## Where each kind of data comes from

| Data | Source | When it arrives |
|---|---|---|
| User records and attributes | Server API `/api/v1/users`, called by your warehouse tool or job | On the schedule you set |
| Segments | Built in the console from attributes and events | When you create them |
| Conversion events for agent goals | Server API `/api/v1/events`, or SDK `track` and `trackPurchase` | On your schedule, or when the app sends its batch |
| Push tokens, for users who already have the app | The contacts API, from a one-time export | When you run the import |
| Push tokens, from then on | The SDK, on first launch after the update | When the user opens the updated app |
| Email addresses and phone numbers | The contacts API, or `setEmail` and `setPhone` in the app | When you run the import, or when the app sends them |
| Device data, sessions, in-app events | The SDK | From the first launch with the SDK |

The External ID must be the same everywhere: the `userId` in your server API calls, the `userId` in contacts API calls, and the ID your app passes to `identify`. If your Braze `external_id` is that ID, you can reuse it as is.

## 1. Send users and attributes through the server API

Point your warehouse tool, or a job you write, at `POST /api/v1/users` with the connection's ingest token. Each call creates or updates users, merges their attributes, registers them as members of the app and saves their email address. Event calls to `POST /api/v1/events` feed the conversion events that agent goals measure, unless the app sends that event through the SDK instead. Build segments in the console from the attributes and events you sent.

Run these first, so every user exists in Herald before tokens and messages arrive. [Sync from your warehouse](/docs/migration/warehouse-sync) explains what to send from the warehouse and what moves to the SDK.

## 2. Import existing push tokens

Users who already have your app hold push tokens that Braze registered. Those tokens belong to your app, not to Braze, so Herald can send to them with the same credentials:

- **APNs.** A token works with any APNs auth key from the same Apple developer team, for the same bundle ID. Add your `.p8` key and bundle ID to the Herald connection.
- **FCM.** A token works only with the Firebase project that issued it. Add a service account from that project to the connection.

Export each user's tokens from Braze (its user export includes push tokens) or from your own backend, then send them to the contacts API with the connection's ingest token. Run the import from your servers, never from the app.

```sh
curl -X POST "https://YOUR_HERALD_HOST/api/v1/contacts" \
  -H "Authorization: Bearer $HERALD_INGEST_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "contacts": [
      { "userId": "u_123", "kind": "apns", "value": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
        "meta": { "bundleId": "com.lumen.app", "sandbox": false } },
      { "userId": "u_456", "kind": "fcm", "value": "FCM_REGISTRATION_TOKEN" }
    ]
  }'
```

- Send up to 1,000 contacts per request. The response reports how many were stored: `{ "data": { "upserted": 2 } }`.
- APNs tokens must be 64 or more hex characters. Set `meta.sandbox` to `true` only for tokens from development builds.
- Re-running the import is safe: contacts are matched on kind and value.
- A token that is no longer valid is marked invalid after the first send that APNs or FCM rejects, and is not used again.

When an imported user opens the updated app, the SDK registers the device's current token for the same user. If it is the same token, the record is updated in place and linked to the device. If the token changed, the device's new token is stored as well.

Field rules and errors are on [SDK REST endpoints](/docs/reference/server-api#post-and-delete-api-v1-contacts).

## 3. Import email addresses and phone numbers

Send them through the same contacts API, with `"kind": "email"` or `"kind": "phone"`. Phone numbers must be E.164. Alternatively, call `setEmail` and `setPhone` in the app after `identify`; the SDK checks the format on the device.

These matter for the mobile SDK in one case: an email or SMS unsubscribe recorded by the SDK applies only to addresses Herald already has for the user.

## 4. Carry over opt-outs

There is no bulk import for unsubscribes today. To carry them over:

- **Push.** The SDK records the device's notification permission with every batch and the push subscription when you call `requestPushAuthorization`. Users who turned notifications off in the system do not receive them.
- **Email and SMS.** For users who opted out in Braze, exclude them from agents with a segment synced from your warehouse. If the app knows the preference, it can call `setSubscription(.email, .unsubscribed)` (iOS) or `setSubscription(SubscriptionChannel.EMAIL, SubscriptionState.UNSUBSCRIBED)` (Android) after the address is set.

## What needs the SDK

Content cards and in-app messages are delivered only to users who have opened the app with the SDK. Herald suppresses a card or in-app send to a user with no SDK device on the connection, so it does not pile up for someone who will never see it. Imported tokens make push reachable before the app update; cards and in-app messages follow as users update.

## Verify it worked

1. Run the import for a few test users and check the `upserted` count.
2. Send a push from an agent to one of them through the Herald connection, before they install the update.
3. Install the update on that device, sign in, and confirm push still arrives once, not twice.

## Next

- [Running in parallel](/docs/migration/parallel-run)
- [Sync from your warehouse](/docs/migration/warehouse-sync)
