(subscribers)
A subscriber in Novu represents someone who should receive a message. A subscriber’s profile information contains important attributes about the subscriber that will be used in messages (name, email). The subscriber object can contain other key-value pairs that can be used to further personalize your messages. https://docs.novu.co/subscribers/subscribers
- list - Get subscribers
- create - Create subscriber
- retrieve - Get subscriber
- update - Update subscriber
- delete - Delete subscriber
- createBulk - Bulk create subscribers
Returns a list of subscribers, could paginated using the page
and limit
query parameter
import { Novu } from "@novu/api";
const novu = new Novu({
apiKey: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await novu.subscribers.list();
for await (const page of result) {
// Handle the page
console.log(page);
}
}
run();
The standalone function version of this method:
import { NovuCore } from "@novu/api/core.js";
import { subscribersList } from "@novu/api/funcs/subscribersList.js";
// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
apiKey: "<YOUR_API_KEY_HERE>",
});
async function run() {
const res = await subscribersList(novu);
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
for await (const page of result) {
// Handle the page
console.log(page);
}
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
idempotencyKey |
string | ➖ | A header for idempotency purposes |
page |
number | ➖ | N/A |
limit |
number | ➖ | N/A |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.SubscribersControllerListSubscribersResponse>
Error Type | Status Code | Content Type |
---|---|---|
errors.ErrorDto | 400, 404, 409 | application/json |
errors.ValidationErrorDto | 422 | application/json |
errors.SDKError | 4XX, 5XX | */* |
Creates a subscriber entity, in the Novu platform. The subscriber will be later used to receive notifications, and access notification feeds. Communication credentials such as email, phone number, and 3 rd party credentials i.e slack tokens could be later associated to this entity.
import { Novu } from "@novu/api";
const novu = new Novu({
apiKey: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await novu.subscribers.create({
subscriberId: "<id>",
});
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { NovuCore } from "@novu/api/core.js";
import { subscribersCreate } from "@novu/api/funcs/subscribersCreate.js";
// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
apiKey: "<YOUR_API_KEY_HERE>",
});
async function run() {
const res = await subscribersCreate(novu, {
subscriberId: "<id>",
});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
createSubscriberRequestDto |
components.CreateSubscriberRequestDto | ✔️ | N/A |
idempotencyKey |
string | ➖ | A header for idempotency purposes |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.SubscribersControllerCreateSubscriberResponse>
Error Type | Status Code | Content Type |
---|---|---|
errors.ErrorDto | 400, 404, 409 | application/json |
errors.ValidationErrorDto | 422 | application/json |
errors.SDKError | 4XX, 5XX | */* |
Get subscriber by your internal id used to identify the subscriber
import { Novu } from "@novu/api";
const novu = new Novu({
apiKey: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await novu.subscribers.retrieve("<id>");
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { NovuCore } from "@novu/api/core.js";
import { subscribersRetrieve } from "@novu/api/funcs/subscribersRetrieve.js";
// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
apiKey: "<YOUR_API_KEY_HERE>",
});
async function run() {
const res = await subscribersRetrieve(novu, "<id>");
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
subscriberId |
string | ✔️ | N/A |
idempotencyKey |
string | ➖ | A header for idempotency purposes |
includeTopics |
boolean | ➖ | Includes the topics associated with the subscriber |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.SubscribersControllerGetSubscriberResponse>
Error Type | Status Code | Content Type |
---|---|---|
errors.ErrorDto | 400, 404, 409 | application/json |
errors.ValidationErrorDto | 422 | application/json |
errors.SDKError | 4XX, 5XX | */* |
Used to update the subscriber entity with new information
import { Novu } from "@novu/api";
const novu = new Novu({
apiKey: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await novu.subscribers.update({
email: "[email protected]",
firstName: "John",
lastName: "Doe",
phone: "+1234567890",
avatar: "https://example.com/avatar.jpg",
locale: "en-US",
data: {
"preferences": {
"notifications": true,
"theme": "dark",
},
"tags": [
"premium",
"newsletter",
],
},
}, "<id>");
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { NovuCore } from "@novu/api/core.js";
import { subscribersUpdate } from "@novu/api/funcs/subscribersUpdate.js";
// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
apiKey: "<YOUR_API_KEY_HERE>",
});
async function run() {
const res = await subscribersUpdate(novu, {
email: "[email protected]",
firstName: "John",
lastName: "Doe",
phone: "+1234567890",
avatar: "https://example.com/avatar.jpg",
locale: "en-US",
data: {
"preferences": {
"notifications": true,
"theme": "dark",
},
"tags": [
"premium",
"newsletter",
],
},
}, "<id>");
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
subscriberId |
string | ✔️ | N/A |
updateSubscriberRequestDto |
components.UpdateSubscriberRequestDto | ✔️ | N/A |
idempotencyKey |
string | ➖ | A header for idempotency purposes |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.SubscribersControllerUpdateSubscriberResponse>
Error Type | Status Code | Content Type |
---|---|---|
errors.ErrorDto | 400, 404, 409 | application/json |
errors.ValidationErrorDto | 422 | application/json |
errors.SDKError | 4XX, 5XX | */* |
Deletes a subscriber entity from the Novu platform
import { Novu } from "@novu/api";
const novu = new Novu({
apiKey: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await novu.subscribers.delete("<id>");
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { NovuCore } from "@novu/api/core.js";
import { subscribersDelete } from "@novu/api/funcs/subscribersDelete.js";
// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
apiKey: "<YOUR_API_KEY_HERE>",
});
async function run() {
const res = await subscribersDelete(novu, "<id>");
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
subscriberId |
string | ✔️ | N/A |
idempotencyKey |
string | ➖ | A header for idempotency purposes |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.SubscribersControllerRemoveSubscriberResponse>
Error Type | Status Code | Content Type |
---|---|---|
errors.ErrorDto | 400, 404, 409 | application/json |
errors.ValidationErrorDto | 422 | application/json |
errors.SDKError | 4XX, 5XX | */* |
Using this endpoint you can create multiple subscribers at once, to avoid multiple calls to the API.
The bulk API is limited to 500 subscribers per request.
import { Novu } from "@novu/api";
const novu = new Novu({
apiKey: "<YOUR_API_KEY_HERE>",
});
async function run() {
const result = await novu.subscribers.createBulk({
subscribers: [
{
subscriberId: "<id>",
email: "[email protected]",
},
],
});
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { NovuCore } from "@novu/api/core.js";
import { subscribersCreateBulk } from "@novu/api/funcs/subscribersCreateBulk.js";
// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
apiKey: "<YOUR_API_KEY_HERE>",
});
async function run() {
const res = await subscribersCreateBulk(novu, {
subscribers: [
{
subscriberId: "<id>",
email: "[email protected]",
},
],
});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
bulkSubscriberCreateDto |
components.BulkSubscriberCreateDto | ✔️ | N/A |
idempotencyKey |
string | ➖ | A header for idempotency purposes |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.SubscribersControllerBulkCreateSubscribersResponse>
Error Type | Status Code | Content Type |
---|---|---|
errors.ErrorDto | 400, 404, 409 | application/json |
errors.ValidationErrorDto | 422 | application/json |
errors.SDKError | 4XX, 5XX | */* |