Skip to content

Latest commit

 

History

History
580 lines (413 loc) · 49.6 KB

README.md

File metadata and controls

580 lines (413 loc) · 49.6 KB

Subscribers

(subscribers)

Overview

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

Available Operations

list

Returns a list of subscribers, could paginated using the page and limit query parameter

Example Usage

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

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

async function run() {
  const result = await novu.subscribers.list();

  for await (const page of result) {
    // Handle the page
    console.log(page);
  }
}

run();

Standalone function

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({
  secretKey: "YOUR_SECRET_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();

Parameters

Parameter Type Required Description
page number N/A
limit number 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.

Response

Promise<operations.SubscribersV1ControllerListSubscribersResponse>

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

createBulk

  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.

Example Usage

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

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

async function run() {
  const result = await novu.subscribers.createBulk({
    subscribers: [
      {
        subscriberId: "<id>",
      },
    ],
  });

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

run();

Standalone function

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({
  secretKey: "YOUR_SECRET_KEY_HERE",
});

async function run() {
  const res = await subscribersCreateBulk(novu, {
    subscribers: [
      {
        subscriberId: "<id>",
      },
    ],
  });

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

  const { value: result } = res;

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

run();

Parameters

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.

Response

Promise<operations.SubscribersV1ControllerBulkCreateSubscribersResponse>

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

search

Search for subscribers

Example Usage

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

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

async function run() {
  const result = await novu.subscribers.search({});

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

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { subscribersSearch } from "@novu/api/funcs/subscribersSearch.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 subscribersSearch(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.SubscribersControllerSearchSubscribersRequest ✔️ 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.SubscribersControllerSearchSubscribersResponse>

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

create

Create subscriber with the given data

Example Usage

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

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

async function run() {
  const result = await novu.subscribers.create({
    subscriberId: "<id>",
  });

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

run();

Standalone function

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({
  secretKey: "YOUR_SECRET_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();

Parameters

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.

Response

Promise<operations.SubscribersControllerCreateSubscriberResponse>

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

retrieve

Get subscriber by your internal id used to identify the subscriber

Example Usage

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

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

async function run() {
  const result = await novu.subscribers.retrieve("<id>");

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

run();

Standalone function

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({
  secretKey: "YOUR_SECRET_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();

Parameters

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.

Response

Promise<operations.SubscribersControllerGetSubscriberResponse>

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

patch

Patch subscriber by your internal id used to identify the subscriber

Example Usage

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

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

async function run() {
  const result = await novu.subscribers.patch({}, "<id>");

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

run();

Standalone function

The standalone function version of this method:

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

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

  const { value: result } = res;

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

run();

Parameters

Parameter Type Required Description
subscriberId string ✔️ N/A
patchSubscriberRequestDto components.PatchSubscriberRequestDto ✔️ 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.

Response

Promise<operations.SubscribersControllerPatchSubscriberResponse>

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

Deletes a subscriber entity from the Novu platform

Example Usage

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

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

async function run() {
  const result = await novu.subscribers.delete("<id>");

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

run();

Standalone function

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({
  secretKey: "YOUR_SECRET_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();

Parameters

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.

Response

Promise<operations.SubscribersControllerRemoveSubscriberResponse>

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