docs/.mintlify/skills/trigger-notification/references/single-trigger-examples.md
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: process.env.NOVU_SECRET_KEY,
});
const result = await novu.trigger({
workflowId: "welcome-email",
to: "subscriber-123",
payload: {
userName: "Jane",
companyName: "Acme Inc",
},
});
console.log(result);
from novu_py import Novu
from novu_py.models import TriggerEventRequestDto
novu = Novu(security=Security(secret_key=os.environ["NOVU_SECRET_KEY"]))
result = novu.trigger(request=TriggerEventRequestDto(
workflow_id="welcome-email",
to="subscriber-123",
payload={
"userName": "Jane",
"companyName": "Acme Inc",
},
))
print(result)
curl -X POST https://api.novu.co/v1/events/trigger \
-H "Authorization: ApiKey $NOVU_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "welcome-email",
"to": "subscriber-123",
"payload": {
"userName": "Jane",
"companyName": "Acme Inc"
}
}'
Auto-create or update the subscriber during trigger:
const result = await novu.trigger({
workflowId: "welcome-email",
to: {
subscriberId: "user-456",
email: "[email protected]",
firstName: "Jane",
lastName: "Doe",
phone: "+15551234567",
avatar: "https://example.com/avatars/jane.jpg",
locale: "en-US",
data: {
plan: "pro",
signupSource: "landing-page",
},
},
payload: { userName: "Jane" },
});
Include the actor (who triggered the action) for use in templates:
const result = await novu.trigger({
workflowId: "comment-notification",
to: "post-author-123",
payload: {
commentText: "Great post!",
postTitle: "Getting Started with Novu",
},
actor: "commenter-456",
});
For idempotency and cancellation support:
import { randomUUID } from "crypto";
const transactionId = randomUUID();
const result = await novu.trigger({
workflowId: "order-confirmation",
to: "customer-789",
payload: { orderId: "order-001", total: "$99.99" },
transactionId,
});
// Later, cancel if needed (only works for delayed/digested notifications)
await novu.cancel(transactionId);
Override provider-specific settings:
const result = await novu.trigger({
workflowId: "alert-notification",
to: "admin-001",
payload: { message: "CPU usage above 90%" },
overrides: {
"providers": {
"sendgrid": {
from: "[email protected]",
cc: ["[email protected]", "[email protected]"],
replyTo: "[email protected]",
}
}
},
});
Pass organizational context for multi-tenant applications:
const result = await novu.trigger({
workflowId: "invoice-created",
to: "user-123",
payload: { invoiceId: "INV-001" },
context: {
organizationId: "org-acme",
},
});