Skip to content

Latest commit

 

History

History
248 lines (184 loc) · 24.7 KB

File metadata and controls

248 lines (184 loc) · 24.7 KB

Messages

Overview

A message in Novu represents a notification delivered to a recipient on a particular channel. Messages contain information about the request that triggered its delivery, a view of the data sent to the recipient, and a timeline of its lifecycle events. Learn more about messages. https://docs.novu.co/workflows/messages

Available Operations

retrieve

List all messages for the current environment. This API supports filtering by channel, subscriberId, and transactionId. This API returns a paginated list of messages.

Example Usage

import { Novu } from "@novu/api";

const novu = new Novu({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const result = await novu.messages.retrieve({
    contextKeys: [
      "tenant:org-123",
      "region:us-east-1",
    ],
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { messagesRetrieve } from "@novu/api/funcs/messagesRetrieve.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 messagesRetrieve(novu, {
    contextKeys: [
      "tenant:org-123",
      "region:us-east-1",
    ],
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("messagesRetrieve failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.MessagesControllerGetMessagesRequest ✔️ The request object to use for the request.
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.

Response

Promise<operations.MessagesControllerGetMessagesResponse>

Errors

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 */*

delete

Delete a message entity from the Novu platform by messageId. This action is irreversible. messageId is required and of mongodbId type.

Example Usage

import { Novu } from "@novu/api";

const novu = new Novu({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const result = await novu.messages.delete("507f1f77bcf86cd799439011");

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { messagesDelete } from "@novu/api/funcs/messagesDelete.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 messagesDelete(novu, "507f1f77bcf86cd799439011");
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("messagesDelete failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description Example
messageId string ✔️ N/A 507f1f77bcf86cd799439011
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.

Response

Promise<operations.MessagesControllerDeleteMessageResponse>

Errors

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 */*

deleteByTransactionId

Delete multiple messages from the Novu platform using transactionId of triggered event. This API supports filtering by channel and delete all messages associated with the transactionId.

Example Usage

import { Novu } from "@novu/api";

const novu = new Novu({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const result = await novu.messages.deleteByTransactionId("507f1f77bcf86cd799439011");

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { messagesDeleteByTransactionId } from "@novu/api/funcs/messagesDeleteByTransactionId.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 messagesDeleteByTransactionId(novu, "507f1f77bcf86cd799439011");
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("messagesDeleteByTransactionId failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description Example
transactionId string ✔️ N/A 507f1f77bcf86cd799439011
channel operations.MessagesControllerDeleteMessagesByTransactionIdQueryParamChannel The channel of the message to be deleted
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.

Response

Promise<operations.MessagesControllerDeleteMessagesByTransactionIdResponse>

Errors

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 */*