Skip to content

Latest commit

 

History

History
442 lines (337 loc) · 29.8 KB

README.md

File metadata and controls

442 lines (337 loc) · 29.8 KB

Novu SDK

Overview

Novu API: Novu REST API. Please see https://docs.novu.co/api-reference for more details.

Novu Documentation https://docs.novu.co

Available Operations

trigger

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. 
Additional information can be passed according the body interface below.

Example Usage

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

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

async function run() {
  const result = await novu.trigger({
    name: "workflow_identifier",
    to: [
      {
        topicKey: "<value>",
        type: "Topic",
      },
      {
        topicKey: "<value>",
        type: "Topic",
      },
    ],
  });

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

run();

Standalone function

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

async function run() {
  const res = await trigger(novu, {
    name: "workflow_identifier",
    to: [
      {
        topicKey: "<value>",
        type: "Topic",
      },
      {
        topicKey: "<value>",
        type: "Topic",
      },
    ],
  });

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

  const { value: result } = res;

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

run();

Parameters

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.

Response

Promise<operations.EventsControllerTriggerResponse>

Errors

Error Type Status Code Content Type
errors.ErrorDto 400, 401, 403, 404, 405, 409, 413, 415 application/json
errors.ErrorDto 414 application/json
errors.ValidationErrorDto 422 application/json
errors.ErrorDto 500 application/json
errors.SDKError 4XX, 5XX */*

triggerBulk

  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.

Example Usage

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

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

async function run() {
  const result = await novu.triggerBulk({
    events: [
      {
        name: "workflow_identifier",
        to: [
          {
            topicKey: "<value>",
            type: "Topic",
          },
          {
            subscriberId: "<id>",
          },
        ],
      },
      {
        name: "workflow_identifier",
        to: [

        ],
      },
      {
        name: "workflow_identifier",
        to: [
          {
            topicKey: "<value>",
            type: "Topic",
          },
          {
            topicKey: "<value>",
            type: "Topic",
          },
        ],
      },
    ],
  });

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

run();

Standalone function

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

async function run() {
  const res = await triggerBulk(novu, {
    events: [
      {
        name: "workflow_identifier",
        to: [
          {
            topicKey: "<value>",
            type: "Topic",
          },
          {
            subscriberId: "<id>",
          },
        ],
      },
      {
        name: "workflow_identifier",
        to: [
  
        ],
      },
      {
        name: "workflow_identifier",
        to: [
          {
            topicKey: "<value>",
            type: "Topic",
          },
          {
            topicKey: "<value>",
            type: "Topic",
          },
        ],
      },
    ],
  });

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

  const { value: result } = res;

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

run();

Parameters

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.

Response

Promise<operations.EventsControllerTriggerBulkResponse>

Errors

Error Type Status Code Content Type
errors.ErrorDto 400, 401, 403, 404, 405, 409, 413, 415 application/json
errors.ErrorDto 414 application/json
errors.ValidationErrorDto 422 application/json
errors.ErrorDto 500 application/json
errors.SDKError 4XX, 5XX */*

triggerBroadcast

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.

Example Usage

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

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

async function run() {
  const result = await novu.triggerBroadcast({
    name: "<value>",
    payload: {
      "comment_id": "string",
      "post": {
        "text": "string",
      },
    },
  });

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

run();

Standalone function

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

async function run() {
  const res = await triggerBroadcast(novu, {
    name: "<value>",
    payload: {
      "comment_id": "string",
      "post": {
        "text": "string",
      },
    },
  });

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

  const { value: result } = res;

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

run();

Parameters

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.

Response

Promise<operations.EventsControllerBroadcastEventToAllResponse>

Errors

Error Type Status Code Content Type
errors.ErrorDto 400, 401, 403, 404, 405, 409, 413, 415 application/json
errors.ErrorDto 414 application/json
errors.ValidationErrorDto 422 application/json
errors.ErrorDto 500 application/json
errors.SDKError 4XX, 5XX */*

cancel

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...

Example Usage

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

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

async function run() {
  const result = await novu.cancel("<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 { 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({
  apiKey: "<YOUR_API_KEY_HERE>",
});

async function run() {
  const res = await cancel(novu, "<id>");

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

  const { value: result } = res;

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

run();

Parameters

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.

Response

Promise<operations.EventsControllerCancelResponse>

Errors

Error Type Status Code Content Type
errors.ErrorDto 400, 401, 403, 404, 405, 409, 413, 415 application/json
errors.ErrorDto 414 application/json
errors.ValidationErrorDto 422 application/json
errors.ErrorDto 500 application/json
errors.SDKError 4XX, 5XX */*