> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lerix.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Push Notifications

> Send push notifications to devices, to your own users on every device they use, or to a topic through the Lerix REST API.

Send a push notification to one of three targets:

* **`deviceTokens`**: specific registered devices.
* **`externalUserIds`**: your own user IDs. Lerix delivers to every device each
  user signed in on (iOS, Android, web and macOS) in one request. Your apps
  link a device to a user with `setUser`; see [Identify users](https://docs.lerix.dev/modules/users-identity.md).
* **`topic`** (with `sendByTopic: true`): every device subscribed to a topic.

Use one target per request. `externalUserIds` can't be combined with
`deviceTokens` or `sendByTopic`: that request is rejected with
`NOTIFICATION_TARGET_INVALID`.

> [!NOTE]
>
> See the [API introduction](https://docs.lerix.dev/api-reference/introduction.md) to set up your base URL and private key before making requests.

## Parameters

**project-id** `string` *required*

Your project ID from **Project Settings** in the [dashboard](https://app.lerix.dev).

**title** `string` *required*

Notification title shown to the user.

**body** `string` *required*

Notification message body.

**deviceTokens** `string[]`

One or more device tokens to deliver the notification to. One of the three
targets: don't combine it with `externalUserIds` or `sendByTopic`.

**externalUserIds** `string[]`

Your own user IDs, the same values your apps pass to `setUser` after login.
Lerix finds every device currently linked to each ID, across all the
platforms in this project, and delivers to all of them. Up to 1000 IDs per
request, each 1 to 255 characters. One of the three targets: don't combine
it with `deviceTokens` or `sendByTopic`.

An ID with no linked device isn't an error (the user may not have installed
the app yet). It comes back in `unknownUserIds` in the response. When the
notification is scheduled with `sentAt`, devices are looked up again at send
time, so a device that signs in after you schedule still receives it.

**sendByTopic** `boolean` (default: false)

Set to `true` to deliver to every device subscribed to `topic`. One of the
three targets: don't combine it with `deviceTokens` or `externalUserIds`.
Devices subscribe to a topic from your app using the SDK. A topic is
created automatically the first time a device subscribes to it, or you can
create one manually from the **Topics** tab in the dashboard.

**topic** `string`

The topic key to broadcast to. Required when `sendByTopic` is `true`,
ignored otherwise.

**sound** `string`

Name of a custom notification sound. The file itself must already be
bundled inside your app project — Lerix only passes the filename
through to APNs/FCM, it doesn't host or upload sound files. Leave empty to
use the device's default notification sound.

**iOS**: the sound file's name with its extension (e.g. `sound.mp3`;
`.caf`/`.wav` also supported).

**Android**: the resource name **without** an extension, matching a file
under `res/raw/` (e.g. `sound` for a file at `res/raw/sound.mp3`).

* Supported formats: `.wav`, `.mp3`, `.ogg`.
* Keep the filename lowercase — some tooling/devices ignore uppercase
  letters in resource names.
* Keep the file small and under \~30 seconds; large files may not play on
  some devices.
* If the named file isn't found, the notification falls back to the
  device's default sound rather than failing.
* A given sound is locked in the first time it's used on a device — Android
  fixes a notification channel's sound at creation and never lets it
  change afterward, so switching to a different `sound` value later
  creates a new channel rather than updating the old one.

**Web**: not supported — the Web Notifications API has no cross-browser
way to set a custom sound, so this parameter is ignored for web
recipients.

**imageUrl** `string`

URL of an image to show as a rich image in the notification. Lerix
downloads it — this is a normal `https://` URL, not a file you need to
bundle in your app (unlike `sound`).

**Android**: works automatically, rendered as a `BigPictureStyle`
notification.

**iOS**: requires the app to have a Notification Service Extension
configured (a one-time setup step — see the
[Flutter push notifications guide](https://docs.lerix.dev/frameworks/flutter/push-notifications.md#sending-an-image)).
Without it, `imageUrl` is silently ignored on iOS; the notification still
sends and displays normally, just without the image. Sending this field
automatically sets APNs' `mutable-content` flag, which is what triggers the
extension to run.

**Web**: works automatically, no extra setup — the service worker renders
it as the notification's icon/image directly.

**metadata** `object`

Arbitrary custom data to attach to the notification. Any JSON object; omit
for no metadata. Delivered to the device alongside `title`/`body` and
readable from the SDK as `payload.metadata` in
`setOnNotificationReceived`/`setOnNotificationTapped`.

**projectSlug** `string`

Defaults to the project in the URL (`/v1/:project-id/...`); only needed for older integrations.

**apiKey** `string`

Deprecated alternative to the `lerix-key` header, still accepted.

**source** `string` (default: API)

Where the notification was sent from.

**sentAt** `string`

An ISO 8601 timestamp to schedule delivery for later instead of sending
immediately. Omit it (or pass a time in the past) to send right away. A
scheduled notification can be edited or canceled before it goes out — see
[Update a notification](https://docs.lerix.dev/api-reference/update-notification.md) and
[Cancel a scheduled notification](https://docs.lerix.dev/api-reference/cancel-notification.md).

> [!WARNING]
>
> Never expose your private key in client-side code or public repositories. Send API requests from a trusted backend only.

## Response

```json 201 Created theme={"dark"}
{
  "success": true,
  "message": "Notification sent successfully",
  "notificationId": "b6b1a2b0-9c3f-4b3e-9c3f-4b3e9c3f4b3e"
}
```

Save `notificationId`. It's what you pass to the other notification endpoints
(update, unsend, cancel, and delivery status).

When you send to `externalUserIds`, the response also says who was reached:

```json 201 Created theme={"dark"}
{
  "success": true,
  "message": "Notification sent successfully",
  "notificationId": "b6b1a2b0-9c3f-4b3e-9c3f-4b3e9c3f4b3e",
  "matchedUsers": 1,
  "matchedDevices": 3,
  "unknownUserIds": ["user_456"]
}
```

**matchedUsers** `number`

How many of the requested IDs have at least one linked device.

**matchedDevices** `number`

How many devices the notification was sent to, across every platform.

**unknownUserIds** `string[]`

Requested IDs with no linked device. Nothing was sent for them.

A device on a platform whose push keys aren't configured yet doesn't block
the others: it gets a failed delivery with the `PLATFORM_NOT_CONFIGURED` code,
visible in [Get delivery status](https://docs.lerix.dev/api-reference/notification-deliveries.md).

## Errors

| HTTP status | `error` | Meaning |
| - | - | - |
| 400 | `NOTIFICATION_TARGET_INVALID` | The request combined `externalUserIds` with `deviceTokens` or `sendByTopic` |

Every other failure follows the shape and codes documented in [Error & success codes](https://docs.lerix.dev/developers/errors-responses.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.