Skip to content

Latest commit

 

History

History
386 lines (263 loc) · 28.2 KB

README.md

File metadata and controls

386 lines (263 loc) · 28.2 KB

Topics

(topics)

Overview

Topics are a way to group subscribers together so that they can be notified of events at once. A topic is identified by a custom key. This can be helpful for things like sending out marketing emails or notifying users of new features. Topics can also be used to send notifications to the subscribers who have been grouped together based on their interests, location, activities and much more. https://docs.novu.co/subscribers/topics

Available Operations

create

Create a topic

Example Usage

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

const novu = new Novu({
  apiKey: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const result = await novu.topics.create({
    key: "<key>",
    name: "<value>",
  });
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { topicsCreate } from "@novu/api/funcs/topicsCreate.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 topicsCreate(novu, {
    key: "<key>",
    name: "<value>",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request components.CreateTopicRequestDto ✔️ 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<components.CreateTopicResponseDto>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

delete

Delete a topic by its topic key if it has no subscribers

Example Usage

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

const novu = new Novu({
  apiKey: "<YOUR_API_KEY_HERE>",
});

async function run() {
  await novu.topics.delete("<value>");
}

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { topicsDelete } from "@novu/api/funcs/topicsDelete.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 topicsDelete(novu, "<value>");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  
}

run();

Parameters

Parameter Type Required Description
topicKey string ✔️ The topic key
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<void>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

list

Returns a list of topics that can be paginated using the page query parameter and filtered by the topic key with the key query parameter

Example Usage

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

const novu = new Novu({
  apiKey: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const result = await novu.topics.list({});
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { topicsList } from "@novu/api/funcs/topicsList.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 topicsList(novu, {});

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
request operations.TopicsControllerListTopicsRequest ✔️ 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<components.FilterTopicsResponseDto>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

rename

Rename a topic by providing a new name

Example Usage

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

const novu = new Novu({
  apiKey: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const result = await novu.topics.rename("<value>", {
    name: "<value>",
  });
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { topicsRename } from "@novu/api/funcs/topicsRename.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 topicsRename(novu, "<value>", {
    name: "<value>",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
topicKey string ✔️ The topic key
renameTopicRequestDto components.RenameTopicRequestDto ✔️ 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.

Response

Promise<components.RenameTopicResponseDto>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /

retrieve

Get a topic by its topic key

Example Usage

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

const novu = new Novu({
  apiKey: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const result = await novu.topics.retrieve("<value>");
  
  // Handle the result
  console.log(result)
}

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { topicsRetrieve } from "@novu/api/funcs/topicsRetrieve.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 topicsRetrieve(novu, "<value>");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result)
}

run();

Parameters

Parameter Type Required Description
topicKey string ✔️ The topic key
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<components.GetTopicResponseDto>

Errors

Error Object Status Code Content Type
errors.SDKError 4xx-5xx /