> For the complete documentation index, see [llms.txt](https://codemash.gitbook.io/codemash/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codemash.gitbook.io/codemash/cloud/push/campaigns/new.md).

# Create a campaign and send it now

Create a push campaign — pick the audience, the template and the provider — and send it now.

**Where:** Push → Campaigns → **Create Campaign** · `/projects/<project>/push/campaigns/new`

You also land here from a template (**Actions → Create Campaign** in the [editor](/codemash/cloud/push/templates/editor.md)) or from a campaign (**Create new from this** on its [details page](/codemash/cloud/push/campaigns/details.md)); then the template is already picked (`…/campaigns/new?t=<template id>`).

## Before you start

* An enabled push [integration](/codemash/cloud/push/integrations.md). Right after you enable the module the [Fake Push (Test Me)](/codemash/cloud/push/integrations/providers/fake.md) is there and is the default, so nothing real is sent until you pick another one.
* A push [template](/codemash/cloud/push/templates.md) with a title and a body.
* Someone to send to: users with at least one [registered device](/codemash/cloud/push/devices.md). A user without a device is skipped, not counted as failed. The form counts the devices of the audience for you and keeps **Send** off while the audience reaches none.

## Steps

1. Press **Create Campaign**. The form **Add New Push Campaign** opens with **All users** selected and the count *This audience reaches 3 devices.*

   <figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-fa4f7bf35865c51d6ab6557bf19e7524adb9d863%2Fcampaigns-create-1.png?alt=media" alt="Add New Push Campaign: five recipient cards (All users selected, Collection greyed out with This project has no collections yet., Specified Users, Devices, Account users), Select role(s), Send to devices on All platforms and This audience reaches 3 devices."><figcaption><p>The recipient cards.</p></figcaption></figure>
2. Under *Please choose how you would like to select your recipients.* pick one card:

   | Card                | Who gets the push                                                                                                    | Fields                                                                                                                                                                  |
   | ------------------- | -------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
   | **All users**       | Every project user with a registered device.                                                                         | **Select role(s)** — optional; **Send to devices on** — **All platforms** or iOS, Android, Chrome, Safari (only the platforms your integrations can reach are offered). |
   | **Collection**      | The users named in the records of a database collection. Greyed out while Database is off or there is no collection. | **Collection**, **Recipient field(s), comma separated** (e.g. `userId`), **What the field holds**: **A user id**.                                                       |
   | **Specified Users** | The users you pick. The picker lists only users with a device.                                                       | **To:** — e.g. `ada.lovelace@example.com`.                                                                                                                              |
   | **Devices**         | The registered devices you pick, one by one.                                                                         | **Devices:** — a picker with a token / user id filter and a platform filter.                                                                                            |
   | **Account users**   | The account owner and team members you pick, through the devices they registered as project users.                   | **Account users:**, **Send to devices on**.                                                                                                                             |

   <figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-e95401867c26b3d64f5f427a28e7b47d28f027c1%2Fcampaigns-create-5.png?alt=media" alt="The device picker of the Devices card: a Token or user id (usr_…) filter, All platforms, and three devices: chrome, android and ios with their tokens"><figcaption><p>The Devices card opens a picker of the registered devices.</p></figcaption></figure>
3. Fill **Template Details**:

   | Field                     | Required  | What it does                                                                                                                                                      | Example                                        |
   | ------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- |
   | Select template           | yes       | The template to send; the type is shown next to the name.                                                                                                         | `Order shipped (Transactional)`                |
   | Send in specific language | no        | **Each recipient's language** (default): the recipient's language when it is a project language, else the project default. Or one project language for everyone.  | `Each recipient's language`                    |
   | Template Tokens           | yes, each | Every `@Model.…` token of the title and the body. Reserved tokens fill themselves; your own tokens need a value. **Send** turns on only when every token has one. | `FirstName` = `Ada`, `OrderNumber` = `A-10482` |

   <figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-c3ed25035108164fa0ff1c23626591eca35a29ec%2Fcampaigns-create-4.png?alt=media" alt="Specified Users with ada.lovelace@example.com, This audience reaches 1 device., template Order shipped, Each recipient&#x27;s language, and Template Tokens FirstName Ada and OrderNumber A-10482"><figcaption><p>A send to one user with both tokens filled.</p></figcaption></figure>
4. Check **Advanced settings** (*Optional fields to customize your push delivery.*):

   | Field                  | Required | What it does                                                                                                      | Example          |
   | ---------------------- | -------- | ----------------------------------------------------------------------------------------------------------------- | ---------------- |
   | Send push on behalf of | no       | The person whose details fill the `@Model.Initiator.User.…` tokens. Empty = you.                                  | empty            |
   | Select push provider   | yes      | The integration that delivers the campaign. The project default is picked for you.                                | `Test Me (Fake)` |
   | When to send           | yes      | **Send now** (default) or **Send later** — see [Schedule a campaign](/codemash/cloud/push/campaigns/schedule.md). | `Send now`       |

   <figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-36412785bdb38f56d7a0c26ee0da90d60b9cb3e5%2Fcampaigns-create-3.png?alt=media" alt="The whole form for All users and template Weekend sale: Template Details, Advanced settings with Send push on behalf of empty, Select push provider Test Me (Fake), When to send Send now, and the Cancel and Send buttons"><figcaption><p>The whole form with the default provider picked.</p></figcaption></figure>
5. Press **Send**. **Cancel** goes back to the list without creating anything.

## Result

Cloud returns to the [campaigns list](/codemash/cloud/push/campaigns.md). The new row appears within 15 seconds and moves Registered → Processing → **Completed**; its batches, statistics and messages are on the [details page](/codemash/cloud/push/campaigns/details.md). Through the Fake integration the messages are recorded as sent and nothing reaches a device.

<figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-0939e4ca438afbb51a351fdc69e955c6be8a9076%2Fcampaigns-create-7.png?alt=media" alt="Push Campaigns list with the new Specific devices campaign Completed at the top, sent through Test Me (Default)"><figcaption><p>The campaign has completed.</p></figcaption></figure>

## Change or remove it later

* **Edit** — a campaign cannot be changed after it is created. Use **Create new from this** on its [details page](/codemash/cloud/push/campaigns/details.md) to start a new one with the same template.
* **Stop** — a campaign that is still waiting or sending can be [stopped](/codemash/cloud/push/campaigns/stop.md).
* **Delete** — once it is Completed, Stopped or Failed, from the **Actions** menu of its [details page](/codemash/cloud/push/campaigns/details.md#change-or-remove-it-later).

## Do it from code

`source` names the audience (`AllUsers`, `SpecifiedUsers`, `AccountUsers`, `Collection`, `Devices`); the audience fields sit next to it in `campaign`.

```ts
const { id } = await norbix.hub.notifications.createPushCampaign({
  campaign: {
    source: 'SpecifiedUsers',
    templateId: 'tmpl_bp0fFX5IcoudBYiH6cwtJ', // Order shipped
    integrationId: 'int_5w5gi8BSgF9H7E76Ud6K7F', // Test Me (Fake)
    userRecipients: ['usr_5Us6T01VpYu3PgK6a1d4tv'], // Ada Lovelace
    mappedTokens: [
      { key: 'FirstName', value: 'Ada', resolver: 'Custom' },
      { key: 'OrderNumber', value: 'A-10483', resolver: 'Custom' },
    ],
  },
});
console.log(id); // cmp_7LX6kndj6fMBX3ZbsiATog
```

```sh
norbix hub notifications push campaign create --campaign '{"source":"Devices","templateId":"tmpl_5IStKcssvWDLtEJLJdFKvJ","integrationId":"int_5w5gi8BSgF9H7E76Ud6K7F","devices":[{"token":"fK3pZ8qLR0e1:APA91bH7xQ2vN5mT8wY1cE4rU6iO9pA3sD5fG7hJ9kL1zX3cV5bN7mQ9wE2rT4yU6iO8pA0sD2fG4hJ6kL8zX0cV2bN4mQ6w","deliveryFamily":"Android"}]}'
```

To count the devices an audience reaches before you send, call [Get Push Campaign Audience Count](/codemash/api-reference/notifications/push/get-push-campaign-audience-count.md) with the same `campaign` (it answered `{ devices: 3, recipients: 3 }` for All users here). The client setup is on the [Push page](/codemash/cloud/push.md#use-it-from-code). API: [Create Push Campaign](/codemash/api-reference/notifications/push/create-push-campaign.md)
