# Groups

Subscribe subscribers or devices to a keyed group, read its members, and send to everyone in it with one call.

## Subscribe

A member is a **subscriber id**, which reaches every device registered under it now and later, or a **device key**, one registered `deviceId`, for anonymous devices such as browsers. An unknown key creates the group. Subscribing again is a no-op (`joined: false`), so you can subscribe on every launch.

> **Not Classic topic groups:**
>
> Groups are separate from the [topic groups](/docs/topic-push-notifications) of Expo Push (Classic): a different audience and send pipeline, and they don't interact.

```text
POST https://app.nativenotify.com/api/universal/groups/subscribe
```

```json
{
  "appId": 123,
  "appToken": "yourAppToken",
  "key": "weekly-news",
  "name": "Weekly News",
  "subscriberId": "user_8241"
}
```

| Field                 | Required   | Notes                                                                                                                                           |
| --------------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| `appId`, `appToken`   | yes        | Your app's pair.                                                                                                                                |
| `key`                 | yes        | 1–64 characters: lowercase letters, digits, dashes and underscores, starting with a letter or digit. Aliases: `groupKey`, `group_key`, `group`. |
| `subscriberId`        | one member | One subscriber id (max 256 chars). Aliases: `subscriber_id`, `subId`, `sub_id`.                                                                 |
| `deviceId`            | one member | One registered device key (max 200 chars). Alias: `device_id`.                                                                                  |
| `subscribers`         | one member | Bulk subscriber ids, up to 500 per call. Aliases: `subscriberIds`, `subscriber_ids`.                                                            |
| `devices`             | one member | Bulk device keys, up to 500 per call. Aliases: `deviceIds`, `device_ids`.                                                                       |
| `name`, `description` | no         | Used only when this call creates the group (max 120 and 500 chars). `name` defaults to the key.                                                 |
| `create`              | no         | Default `true`. `false` answers `404 group_not_found` for an unknown key.                                                                       |

Send at least one member; the four member fields can be mixed. More than 500 ids of one kind is `400 too_many_members`: the batch is rejected, never truncated. The response is `201`:

```json
{
  "ok": true,
  "group": { "id": 17, "key": "weekly-news", "name": "Weekly News", "created": true },
  "results": { "subscribers": [{ "subscriberId": "user_8241", "joined": true }], "devices": [] },
  "counts": { "subscribers": 1, "devices": 0, "resolvableDevices": 2, "prunableDevices": 0 }
}
```

## Unsubscribe

```text
POST https://app.nativenotify.com/api/universal/groups/unsubscribe
```

Same body as subscribe. It answers `200` with `removed` per member (`false` if it wasn't in the group) and the new counts. An unknown key is `404 group_not_found`.

## Read groups and members

```text
GET https://app.nativenotify.com/api/universal/groups/:appId/:appToken
GET https://app.nativenotify.com/api/universal/groups/:appId/:appToken/:key
GET https://app.nativenotify.com/api/universal/groups/:appId/:appToken/:key/members?take=100&skip=0
```

The list returns every group, oldest first, each with `id`, `key`, `name`, `description`, `kind` (`manual` or `auto`), `rule`, `createdBy`, `createdAt`, `updatedAt` and `counts`. One group is looked up by key, or by numeric `id` when no group has that key.

Members returns a page of `{ memberId, subscriberId, deviceId, source, joinedAt, resolvedDevices }` rows with `total` (the full membership count), `take` and `skip`. `take` defaults to 100 and must be 1 to 200 (`400 invalid_take`). Page with `skip` until you've read every row.

| Count                    | Meaning                                                                                                                                                                                                                           |
| ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `subscribers`, `devices` | Membership rows of each kind.                                                                                                                                                                                                     |
| `resolvableDevices`      | Distinct registered devices with a live token that the memberships reach now, across all [environments](/docs/push/environments). A send reaches only those in its own environment.                                               |
| `prunableDevices`        | Device memberships whose device isn't registered. Never removed automatically; the **Prune** action in Native Notify's **Push notifications → Groups** tab removes exactly those rows. Subscriber memberships are never prunable. |

## Send to a group

A group is one audience of the ordinary [send](/docs/push/sending):

```json
{
  "appId": 123,
  "appToken": "yourAppToken",
  "title": "This week's newsletter",
  "message": "New recipes from the bakery and the library's reading list.",
  "audience": { "type": "group", "key": "weekly-news" }
}
```

Memberships resolve to live tokens in the send's `environment` (production when omitted). A device reached by both a subscriber and a device membership gets the push once. An unknown or empty group reports `devices: 0`, so check it.

On Premium, sending to a group answers `403 plan_upgrade_required` and nothing is sent. Subscribing, unsubscribing and reading groups work on every plan.

## Always-on groups

Every app has three, with nothing to create or turn on.

| Key      | Members                           | `rule`       |
| -------- | --------------------------------- | ------------ |
| `lapsed` | No app open in the last 30 days   | `lapsed_30d` |
| `active` | Opened the app in the last 7 days | `active_7d`  |
| `new`    | First app open in the last 7 days | `new_7d`     |

Members are subscriber ids computed live from app opens, so a device registered without a `subscriberId` is never in one. Activity is a device's last registration, so register on every launch. Every member holds a live token, so the counts are what a send reaches.

They're read-only: you can't subscribe to, edit or delete them, and their keys are reserved. Send to them like any group, with `{ "type": "group", "key": "lapsed" }`, or [schedule](/docs/push/scheduling) against them. In `counts`, `subscribers` and `resolvableDevices` hold the member count and `devices` is `0`. Their members page shows `source: "auto"` and `memberId: null`, ordered by subscriber id.

## Errors

| Status | Code                                                     | Meaning                                                                                                 |
| ------ | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `400`  | `invalid_body`, `missing_field`, `invalid_field`         | Bad body, no `key`, a bad `appId`, or a `name` or `description` that's too long.                        |
| `400`  | `invalid_group_key`                                      | The key breaks the rules above.                                                                         |
| `400`  | `invalid_subscriber_id`, `invalid_device_id`             | An empty or too-long member id, or a member list that isn't an array.                                   |
| `400`  | `no_members`, `too_many_members`                         | No member, or more than 500 of one kind.                                                                |
| `400`  | `auto_group`                                             | A subscribe or unsubscribe named an always-on group.                                                    |
| `400`  | `invalid_take`, `invalid_skip`                           | Bad member-page parameters.                                                                             |
| `400`  | `bad_app_id`, `bad_group_id`                             | Dashboard and MCP calls: a malformed id.                                                                |
| `404`  | `app_not_found`, `group_not_found`                       | The app isn't accessible to this caller, or the key doesn't exist.                                      |
| `409`  | `key_taken`, `key_reserved`, `system_group`              | Dashboard and MCP calls: the key is used or reserved, or an edit or delete targeted an always-on group. |
| `502`  | `subscribe_failed`, `unsubscribe_failed`, `write_failed` | The change couldn't be saved. Retry.                                                                    |

In [Native Notify](https://dashboard.nativenotify.com), the **Push notifications → Groups** tab lists every group, always-on ones first, and creates, edits and prunes manual groups. The [MCP server](/docs/mcp-server) has the same tools: `list_universal_groups`, `subscribe_to_universal_group`, `send_notification_to_universal_group` and more.
