Novu API: Novu REST API. Please see https://docs.novu.co/api-reference for more details.
Novu Documentation https://docs.novu.co
- trigger - Trigger event
- cancel - Cancel triggered event
- triggerBroadcast - Broadcast event to all
- triggerBulk - Bulk trigger event
Trigger event is the main (and only) way to send notifications to subscribers. The trigger identifier is used to match the particular workflow associated with it. Maximum number of recipients can be 100. Additional information can be passed according the body interface below.
To prevent duplicate triggers, you can optionally pass a **transactionId** in the request body. If the same **transactionId** is used again, the trigger will be ignored. The retention period depends on your billing tier.
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.trigger({
workflowId: "workflow_identifier",
payload: {
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides: {},
to: "SUBSCRIBER_ID",
actor: "<value>",
context: {
"key": "org-acme",
},
});
console.log(result);
}
run();The standalone function version of this method:
import { NovuCore } from "@novu/api/core.js";
import { trigger } from "@novu/api/funcs/trigger.js";
// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const res = await trigger(novu, {
workflowId: "workflow_identifier",
payload: {
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides: {},
to: "SUBSCRIBER_ID",
actor: "<value>",
context: {
"key": "org-acme",
},
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("trigger failed:", res.error);
}
}
run();| Parameter | Type | Required | Description |
|---|---|---|---|
triggerEventRequestDto |
components.TriggerEventRequestDto | ✔️ | 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.EventsControllerTriggerResponse>
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.PayloadValidationExceptionDto | 400 | application/json |
| errors.ErrorDto | 414 | application/json |
| errors.ErrorDto | 401, 403, 404, 405, 409, 413, 415 | application/json |
| errors.ValidationErrorDto | 422 | application/json |
| errors.ErrorDto | 500 | application/json |
| errors.SDKError | 4XX, 5XX | */* |
Using a previously generated transactionId during the event trigger,
will cancel any active or pending workflows. This is useful to cancel active digests, delays etc...
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.cancel("<id>");
console.log(result);
}
run();The standalone function version of this method:
import { NovuCore } from "@novu/api/core.js";
import { cancel } from "@novu/api/funcs/cancel.js";
// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const res = await cancel(novu, "<id>");
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("cancel failed:", res.error);
}
}
run();| Parameter | Type | Required | Description |
|---|---|---|---|
transactionId |
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.EventsControllerCancelResponse>
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.ErrorDto | 414 | application/json |
| errors.ErrorDto | 400, 401, 403, 404, 405, 409, 413, 415 | application/json |
| errors.ValidationErrorDto | 422 | application/json |
| errors.ErrorDto | 500 | application/json |
| errors.SDKError | 4XX, 5XX | */* |
Trigger a broadcast event to all existing subscribers, could be used to send announcements, etc. In the future could be used to trigger events to a subset of subscribers based on defined filters.
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.triggerBroadcast({
name: "<value>",
payload: {
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides: {
additionalProperties: {
"fcm": {
"data": {
"key": "value",
},
},
},
},
actor: {
firstName: "John",
lastName: "Doe",
email: "john.doe@example.com",
phone: "+1234567890",
avatar: "https://example.com/avatar.jpg",
locale: "en-US",
timezone: "America/New_York",
subscriberId: "<id>",
},
context: {
"key": "org-acme",
},
});
console.log(result);
}
run();The standalone function version of this method:
import { NovuCore } from "@novu/api/core.js";
import { triggerBroadcast } from "@novu/api/funcs/triggerBroadcast.js";
// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const res = await triggerBroadcast(novu, {
name: "<value>",
payload: {
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides: {
additionalProperties: {
"fcm": {
"data": {
"key": "value",
},
},
},
},
actor: {
firstName: "John",
lastName: "Doe",
email: "john.doe@example.com",
phone: "+1234567890",
avatar: "https://example.com/avatar.jpg",
locale: "en-US",
timezone: "America/New_York",
subscriberId: "<id>",
},
context: {
"key": "org-acme",
},
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("triggerBroadcast failed:", res.error);
}
}
run();| Parameter | Type | Required | Description |
|---|---|---|---|
triggerEventToAllRequestDto |
components.TriggerEventToAllRequestDto | ✔️ | 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.EventsControllerBroadcastEventToAllResponse>
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.PayloadValidationExceptionDto | 400 | application/json |
| errors.ErrorDto | 414 | application/json |
| errors.ErrorDto | 401, 403, 404, 405, 409, 413, 415 | application/json |
| errors.ValidationErrorDto | 422 | application/json |
| errors.ErrorDto | 500 | application/json |
| errors.SDKError | 4XX, 5XX | */* |
Using this endpoint you can trigger multiple events at once, to avoid multiple calls to the API.
The bulk API is limited to 100 events per request.
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.triggerBulk({
events: [
{
workflowId: "workflow_identifier",
payload: {
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides: {},
to: "SUBSCRIBER_ID",
},
{
workflowId: "workflow_identifier",
payload: {
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides: {},
to: "SUBSCRIBER_ID",
},
{
workflowId: "workflow_identifier",
payload: {
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides: {},
to: "SUBSCRIBER_ID",
},
],
});
console.log(result);
}
run();The standalone function version of this method:
import { NovuCore } from "@novu/api/core.js";
import { triggerBulk } from "@novu/api/funcs/triggerBulk.js";
// Use `NovuCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const novu = new NovuCore({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const res = await triggerBulk(novu, {
events: [
{
workflowId: "workflow_identifier",
payload: {
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides: {},
to: "SUBSCRIBER_ID",
},
{
workflowId: "workflow_identifier",
payload: {
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides: {},
to: "SUBSCRIBER_ID",
},
{
workflowId: "workflow_identifier",
payload: {
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides: {},
to: "SUBSCRIBER_ID",
},
],
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("triggerBulk failed:", res.error);
}
}
run();| Parameter | Type | Required | Description |
|---|---|---|---|
bulkTriggerEventDto |
components.BulkTriggerEventDto | ✔️ | 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.EventsControllerTriggerBulkResponse>
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.PayloadValidationExceptionDto | 400 | application/json |
| errors.ErrorDto | 414 | application/json |
| errors.ErrorDto | 401, 403, 404, 405, 409, 413, 415 | application/json |
| errors.ValidationErrorDto | 422 | application/json |
| errors.ErrorDto | 500 | application/json |
| errors.SDKError | 4XX, 5XX | */* |