Subscribers
In Novu, we call the entities designed to receive notifications as Subscribers
. Each subscriber is unique and identified by a unique subscriberId.
subscriberId
is a unique identifier used by Novu to keep track of a specific subscriber.
We recommend using the internal unique id your application uses for a specific user.
Each subscriber has the following data points:
- User Data - Data stored in the subscriber object that you can easily access in your notification templates. This contains basic info such as first name, last name, avatar, locale, email, and phone. This data is fixed and structured.
- Custom Data - Apart from the above fixed structured user data, any unstructured custom data such as user’s address, nationality, height, etc can also be stored in the
data
field using key-value pairs. - Channel Specific Credentials -
deviceTokens
required to send push notifications andwebhookUrl
for chat channel providers can also be stored.
Subscriber attributes
Field | Type | Required | Example |
---|---|---|---|
subscriberId | string | true | b0bea066-f5fe-11ed-b67e-0242ac120002 |
firstName | string | false | John |
lastName | string | false | Doe |
string | false | john.doe@domain.org. | |
phone | string | false | +13603963366 |
locale | string | false | en |
avatar | string | false | https://example.com/images/avatar.jpg |
data | object | false | {"key": "value"} |
Subscriber response schema
Novu subscriber object
Create a subscriber
You can create a subscriber in Novu using the identify
method provided in Novu’s SDK.
identify
method serves the purpose of handling existing “subscriberId” providers within the database.
When a provider with the same subscriberId already exists, this method performs an update operation using the data present in the payload.
In cases where there is no pre-existing entry, the method generates a new one, thus exhibiting an
behavior.It is possible for two subscribers to have the same email address in our system. This is because the subscriberId
is the unique identifier that distinguishes one subscriber from another.
phone
parameter must be parsed as a string.You should now be able to see your new subscriber on the Novu dashboard.
You can also add additional fields such as phone
, avatar
, and data
.
If you face issues with the subscriber creation only taking the user ID and omitting other fields such as firstName, lastName, etc., you could consider updating the subscriber after creation.
Please also be aware that although it’s currently possible to create a subscriber with an empty subscriberId
, this subscriber cannot be deleted later.
We support creating new subscriber using two ways, Ahead of Trigger
means adding subscribers before triggering notification or Inline of Trigger
means sending complete subscriber data in to
field while triggering.
1. Ahead of Trigger
Create the subscriber and then trigger the notification to this subscriber. Here subscriberId
is the required field and other fields are optional.
Novu will create a subscriber if one does not exist and will update the existing subscriber based on the identify
payload. You can call this function during registration or signup to make sure the subscriber data is up-to-date, if you wish to save additional attributes with a subscriber, you can pass additional custom data in the data field as key-value pairs.
2. Inline of Trigger
A non-existing subscriber can be added by sending subscriber data in to
field of the trigger method. If any subscriber with provided subscriberId
does not exists, a new subscriber will be created. In this case, subscriber will be created first and then the trigger will be executed synchronously.
Bulk Subscriber Creation
You can create subscribers in bulk (up to 500 at once) via the SDKs or API.
Import subscribers
Here, mock_data.csv
file is a CSV file having mock data. The below script will read this CSV file and create a new subscriber in Novu. Change example variables values like API_KEY
value with your valid values. Download mock_data.csv
file from here.
mock_data.csv
file should be in the same directory of script Steps:
- Export your user details in CSV format.
- Clean this exported CSV file. Keep only relevant fields.
- Move this CSV file to the script directory.
- Change the file name in the script with your file name.
- Run the script. (Make script.sh executable before using)
Delete a subscriber
To stop a subscriber from receiving notifications, you can delete the subscriber. This will hard delete the subscriber and means you will not be able to access this subscriber later. You will have to create this subscriber again.
Update a subscriber
In some cases, you want to access a subscriber to update a specific user data field or custom data field. For example, when the users change their email address or personal details.
Find a subscriber
Any subscriber can be retrieved using a unique subscriber identifier subscriberId
. Check the returned subscriber schema here.
Was this page helpful?