Installation
- NPM
- PNPM
- Yarn
- Bun
Usage
- US Region
- EU Region
Sending custom header
To send custom headers, you can use theHTTPClient class. Read more on how to configure custom http client.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Connect a TS/JS application to Novu
npm add @novu/api
pnpm add @novu/api
yarn add @novu/api zod@^3
## Note that Yarn does not install peer dependencies automatically. You will need
## to install zod as shown above.
bun add @novu/api
import { Novu } from "@novu/api";
const novu = new Novu({ secretKey: "<YOUR_SECRET_KEY_HERE>", });
async function run() {
const result = await novu.trigger({
to: {
subscriberId: "subscriber_unique_identifier",
firstName: "Albert",
lastName: "Einstein",
email: "[email protected]",
phone: "+1234567890",
},
workflowId: "workflow_identifier",
payload: {
comment_id: "string",
post: {
text: "string",
},
},
overrides: {
email: {
bcc: "[email protected]",
},
},
});
}
run();
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "<YOUR_SECRET_KEY_HERE>",
serverUrl: "https://eu.api.novu.co",
});
async function run() {
const result = await novu.trigger({
to: {
"subscriberId": "subscriber_unique_identifier",
"firstName": "Albert",
"lastName": "Einstein",
"email": "[email protected]",
"phone": "+1234567890",
},
workflowId: "workflow_identifier",
payload: {
"comment_id": "string",
"post": {
"text": "string",
},
},
overrides: {
"email": {
"bcc": "[email protected]"
},
},
});
// Handle the result
console.log(result);
}
run();
HTTPClient class. Read more on how to configure custom http client.
import { Novu } from "@novu/api";
import { HTTPClient } from "@novu/api/lib/http";
const httpClient = new HTTPClient();
httpClient.addHook("beforeRequest", (request) => {
const nextRequest = new Request(request);
nextRequest.headers.set("x-custom-header", "custom-header-value");
return nextRequest;
});
const novu = new Novu({
httpClient,
secretKey: "SECRET_KEY_VALUE",
serverURL: "https://eu.api.novu.co",
});
novu.trigger({
workflowId: "WORKFLOW_ID_VALUE",
to: {
subscriberId: "subscriberId",
},
payload: {
message: "Hello, world!",
},
});
Was this page helpful?