Skip to content

Latest commit

 

History

History
675 lines (531 loc) · 53.5 KB

File metadata and controls

675 lines (531 loc) · 53.5 KB

Workflows

Overview

All notifications are sent via a workflow. Each workflow acts as a container for the logic and blueprint that are associated with a type of notification in your system. https://docs.novu.co/workflows

Available Operations

  • create - Create a workflow
  • list - List all workflows
  • update - Update a workflow
  • get - Retrieve a workflow
  • delete - Delete a workflow
  • patch - Update a workflow
  • sync - Sync a workflow

create

Creates a new workflow in the Novu Cloud environment

Example Usage

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

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

async function run() {
  const result = await novu.workflows.create({
    name: "<value>",
    workflowId: "<id>",
    steps: [],
    preferences: {
      user: {
        all: {
          enabled: true,
          readOnly: false,
        },
        channels: {
          "email": {
            enabled: true,
          },
          "sms": {
            enabled: false,
          },
        },
      },
      workflow: {
        all: {
          enabled: true,
          readOnly: false,
        },
        channels: {
          "email": {},
          "sms": {
            enabled: false,
          },
        },
      },
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { workflowsCreate } from "@novu/api/funcs/workflowsCreate.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 workflowsCreate(novu, {
    name: "<value>",
    workflowId: "<id>",
    steps: [],
    preferences: {
      user: {
        all: {
          enabled: true,
          readOnly: false,
        },
        channels: {
          "email": {
            enabled: true,
          },
          "sms": {
            enabled: false,
          },
        },
      },
      workflow: {
        all: {
          enabled: true,
          readOnly: false,
        },
        channels: {
          "email": {},
          "sms": {
            enabled: false,
          },
        },
      },
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("workflowsCreate failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
createWorkflowDto components.CreateWorkflowDto ✔️ Workflow creation details
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.WorkflowControllerCreateResponse>

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

list

Retrieves a list of workflows with optional filtering and pagination

Example Usage

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

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

async function run() {
  const result = await novu.workflows.list({
    limit: 10,
    offset: 0,
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

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

run();

Parameters

Parameter Type Required Description
request operations.WorkflowControllerSearchWorkflowsRequest ✔️ 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.WorkflowControllerSearchWorkflowsResponse>

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

update

Updates the details of an existing workflow, here workflowId is the identifier of the workflow

Example Usage

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

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

async function run() {
  const result = await novu.workflows.update({
    name: "<value>",
    steps: [],
    preferences: {
      user: {
        all: {
          enabled: true,
          readOnly: false,
        },
        channels: {
          "email": {
            enabled: true,
          },
          "sms": {
            enabled: false,
          },
        },
      },
      workflow: {
        all: {
          enabled: true,
          readOnly: false,
        },
        channels: {
          "email": {},
          "sms": {
            enabled: false,
          },
        },
      },
    },
    origin: "external",
  }, "<id>");

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { NovuCore } from "@novu/api/core.js";
import { workflowsUpdate } from "@novu/api/funcs/workflowsUpdate.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 workflowsUpdate(novu, {
    name: "<value>",
    steps: [],
    preferences: {
      user: {
        all: {
          enabled: true,
          readOnly: false,
        },
        channels: {
          "email": {
            enabled: true,
          },
          "sms": {
            enabled: false,
          },
        },
      },
      workflow: {
        all: {
          enabled: true,
          readOnly: false,
        },
        channels: {
          "email": {},
          "sms": {
            enabled: false,
          },
        },
      },
    },
    origin: "external",
  }, "<id>");
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("workflowsUpdate failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
workflowId string ✔️ N/A
updateWorkflowDto components.UpdateWorkflowDto ✔️ Workflow update details
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.WorkflowControllerUpdateResponse>

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

get

Fetches details of a specific workflow by its unique identifier workflowId

Example Usage

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

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

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

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

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

run();

Parameters

Parameter Type Required Description
workflowId string ✔️ N/A
environmentId 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.WorkflowControllerGetWorkflowResponse>

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

Removes a specific workflow by its unique identifier workflowId

Example Usage

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

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

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

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

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

run();

Parameters

Parameter Type Required Description
workflowId 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.WorkflowControllerRemoveWorkflowResponse>

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

Partially updates a workflow by its unique identifier workflowId

Example Usage

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

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

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

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

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

run();

Parameters

Parameter Type Required Description
workflowId string ✔️ N/A
patchWorkflowDto components.PatchWorkflowDto ✔️ Workflow patch details
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.WorkflowControllerPatchWorkflowResponse>

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

sync

Synchronizes a workflow to the target environment

Example Usage

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

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

async function run() {
  const result = await novu.workflows.sync({
    targetEnvironmentId: "<id>",
  }, "<id>");

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

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

run();

Parameters

Parameter Type Required Description
workflowId string ✔️ N/A
syncWorkflowDto components.SyncWorkflowDto ✔️ Sync workflow details
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.WorkflowControllerSyncResponse>

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