Workflows
Generate a step preview
Generates a preview for a specific workflow step by its unique identifier stepId
POST
/
v2
/
workflows
/
{workflowId}
/
step
/
{stepId}
/
preview
TypeScript
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.workflows.steps.generatePreview({
workflowId: "<id>",
stepId: "<id>",
generatePreviewRequestDto: {
previewPayload: {
subscriber: {
channels: [
{
providerId: "novu-slack",
credentials: {
webhookUrl: "https://example.com/webhook",
channel: "general",
deviceTokens: [
"token1",
"token2",
"token3",
],
alertUid: "12345-abcde",
title: "Critical Alert",
imageUrl: "https://example.com/image.png",
state: "resolved",
externalUrl: "https://example.com/details",
},
integrationId: "<id>",
},
],
},
actor: {
channels: [
{
providerId: "telegram",
credentials: {
webhookUrl: "https://example.com/webhook",
channel: "general",
deviceTokens: [
"token1",
"token2",
"token3",
],
alertUid: "12345-abcde",
title: "Critical Alert",
imageUrl: "https://example.com/image.png",
state: "resolved",
externalUrl: "https://example.com/details",
},
integrationId: "<id>",
},
],
},
context: {
"key": "org-acme",
},
},
},
});
console.log(result);
}
run();using Novu;
using Novu.Models.Components;
using System.Collections.Generic;
var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");
var res = await sdk.Workflows.Steps.GeneratePreviewAsync(
workflowId: "<id>",
stepId: "<id>",
generatePreviewRequestDto: new GeneratePreviewRequestDto() {
PreviewPayload = new PreviewPayloadDto() {
Subscriber = new SubscriberResponseDtoOptional() {
Channels = new List<ChannelSettingsDto>() {
new ChannelSettingsDto() {
ProviderId = ChatOrPushProviderEnum.NovuSlack,
Credentials = new ChannelCredentials() {
WebhookUrl = "https://example.com/webhook",
Channel = "general",
DeviceTokens = new List<string>() {
"token1",
"token2",
"token3",
},
AlertUid = "12345-abcde",
Title = "Critical Alert",
ImageUrl = "https://example.com/image.png",
State = "resolved",
ExternalUrl = "https://example.com/details",
},
IntegrationId = "<id>",
},
},
},
Actor = new SubscriberResponseDtoOptional() {
Channels = new List<ChannelSettingsDto>() {
new ChannelSettingsDto() {
ProviderId = ChatOrPushProviderEnum.Telegram,
Credentials = new ChannelCredentials() {
WebhookUrl = "https://example.com/webhook",
Channel = "general",
DeviceTokens = new List<string>() {
"token1",
"token2",
"token3",
},
AlertUid = "12345-abcde",
Title = "Critical Alert",
ImageUrl = "https://example.com/image.png",
State = "resolved",
ExternalUrl = "https://example.com/details",
},
IntegrationId = "<id>",
},
},
},
Context = new Dictionary<string, PreviewPayloadDtoContext>() {
{ "key", PreviewPayloadDtoContext.CreateStr(
"org-acme"
) },
},
},
}
);
// handle responsedeclare(strict_types=1);
require 'vendor/autoload.php';
use novu;
use novu\Models\Components;
$sdk = novu\Novu::builder()
->setSecurity(
'YOUR_SECRET_KEY_HERE'
)
->build();
$generatePreviewRequestDto = new Components\GeneratePreviewRequestDto(
previewPayload: new Components\PreviewPayloadDto(
subscriber: new Components\SubscriberResponseDtoOptional(
channels: [
new Components\ChannelSettingsDto(
providerId: Components\ChatOrPushProviderEnum::NovuSlack,
credentials: new Components\ChannelCredentials(
webhookUrl: 'https://example.com/webhook',
channel: 'general',
deviceTokens: [
'token1',
'token2',
'token3',
],
alertUid: '12345-abcde',
title: 'Critical Alert',
imageUrl: 'https://example.com/image.png',
state: 'resolved',
externalUrl: 'https://example.com/details',
),
integrationId: '<id>',
),
],
),
actor: new Components\SubscriberResponseDtoOptional(
channels: [
new Components\ChannelSettingsDto(
providerId: Components\ChatOrPushProviderEnum::Telegram,
credentials: new Components\ChannelCredentials(
webhookUrl: 'https://example.com/webhook',
channel: 'general',
deviceTokens: [
'token1',
'token2',
'token3',
],
alertUid: '12345-abcde',
title: 'Critical Alert',
imageUrl: 'https://example.com/image.png',
state: 'resolved',
externalUrl: 'https://example.com/details',
),
integrationId: '<id>',
),
],
),
context: [
'key' => 'org-acme',
],
),
);
$response = $sdk->workflows->steps->generatePreview(
workflowId: '<id>',
stepId: '<id>',
generatePreviewRequestDto: $generatePreviewRequestDto
);
if ($response->generatePreviewResponseDto !== null) {
// handle response
}import novu_py
from novu_py import Novu
with Novu(
secret_key="YOUR_SECRET_KEY_HERE",
) as novu:
res = novu.workflows.steps.generate_preview(workflow_id="<id>", step_id="<id>", generate_preview_request_dto=novu_py.GeneratePreviewRequestDto(
preview_payload=novu_py.PreviewPayloadDto(
subscriber=novu_py.SubscriberResponseDtoOptional(
channels=[
novu_py.ChannelSettingsDto(
provider_id=novu_py.ChatOrPushProviderEnum.NOVU_SLACK,
credentials=novu_py.ChannelCredentials(
webhook_url="https://example.com/webhook",
channel="general",
device_tokens=[
"token1",
"token2",
"token3",
],
alert_uid="12345-abcde",
title="Critical Alert",
image_url="https://example.com/image.png",
state="resolved",
external_url="https://example.com/details",
),
integration_id="<id>",
),
],
),
actor=novu_py.SubscriberResponseDtoOptional(
channels=[
novu_py.ChannelSettingsDto(
provider_id=novu_py.ChatOrPushProviderEnum.TELEGRAM,
credentials=novu_py.ChannelCredentials(
webhook_url="https://example.com/webhook",
channel="general",
device_tokens=[
"token1",
"token2",
"token3",
],
alert_uid="12345-abcde",
title="Critical Alert",
image_url="https://example.com/image.png",
state="resolved",
external_url="https://example.com/details",
),
integration_id="<id>",
),
],
),
context={
"key": "org-acme",
},
),
))
# Handle response
print(res)package main
import(
"context"
"github.com/novuhq/novu-go/v3"
"github.com/novuhq/novu-go/v3/models/components"
"log"
)
func main() {
ctx := context.Background()
s := v3.New(
v3.WithSecurity("YOUR_SECRET_KEY_HERE"),
)
res, err := s.Workflows.Steps.GeneratePreview(ctx, "<id>", "<id>", components.GeneratePreviewRequestDto{
PreviewPayload: &components.PreviewPayloadDto{
Subscriber: &components.SubscriberResponseDtoOptional{
Channels: []components.ChannelSettingsDto{
components.ChannelSettingsDto{
ProviderID: components.ChatOrPushProviderEnumNovuSlack,
Credentials: components.ChannelCredentials{
WebhookURL: v3.Pointer("https://example.com/webhook"),
Channel: v3.Pointer("general"),
DeviceTokens: []string{
"token1",
"token2",
"token3",
},
AlertUID: v3.Pointer("12345-abcde"),
Title: v3.Pointer("Critical Alert"),
ImageURL: v3.Pointer("https://example.com/image.png"),
State: v3.Pointer("resolved"),
ExternalURL: v3.Pointer("https://example.com/details"),
},
IntegrationID: "<id>",
},
},
},
Actor: &components.SubscriberResponseDtoOptional{
Channels: []components.ChannelSettingsDto{
components.ChannelSettingsDto{
ProviderID: components.ChatOrPushProviderEnumTelegram,
Credentials: components.ChannelCredentials{
WebhookURL: v3.Pointer("https://example.com/webhook"),
Channel: v3.Pointer("general"),
DeviceTokens: []string{
"token1",
"token2",
"token3",
},
AlertUID: v3.Pointer("12345-abcde"),
Title: v3.Pointer("Critical Alert"),
ImageURL: v3.Pointer("https://example.com/image.png"),
State: v3.Pointer("resolved"),
ExternalURL: v3.Pointer("https://example.com/details"),
},
IntegrationID: "<id>",
},
},
},
Context: map[string]components.PreviewPayloadDtoContext{
"key": components.CreatePreviewPayloadDtoContextStr(
"org-acme",
),
},
},
}, nil)
if err != nil {
log.Fatal(err)
}
if res.GeneratePreviewResponseDto != nil {
switch res.GeneratePreviewResponseDto.Result.Type {
case components.GeneratePreviewResponseDtoResultUnionTypeMapOfAny:
// res.GeneratePreviewResponseDto.Result.MapOfAny is populated
case components.GeneratePreviewResponseDtoResultUnionTypeResult2:
// res.GeneratePreviewResponseDto.Result.Result2 is populated
case components.GeneratePreviewResponseDtoResultUnionTypeThree:
// res.GeneratePreviewResponseDto.Result.Three is populated
case components.GeneratePreviewResponseDtoResultUnionTypeResult4:
// res.GeneratePreviewResponseDto.Result.Result4 is populated
case components.GeneratePreviewResponseDtoResultUnionTypeResult5:
// res.GeneratePreviewResponseDto.Result.Result5 is populated
case components.GeneratePreviewResponseDtoResultUnionTypeSix:
// res.GeneratePreviewResponseDto.Result.Six is populated
case components.GeneratePreviewResponseDtoResultUnionTypeSeven:
// res.GeneratePreviewResponseDto.Result.Seven is populated
case components.GeneratePreviewResponseDtoResultUnionTypeEight:
// res.GeneratePreviewResponseDto.Result.Eight is populated
case components.GeneratePreviewResponseDtoResultUnionTypeNine:
// res.GeneratePreviewResponseDto.Result.Nine is populated
}
}
}curl --request POST \
--url https://api.novu.co/v2/workflows/{workflowId}/step/{stepId}/preview \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"controlValues": {},
"previewPayload": {
"subscriber": {
"_id": "<string>",
"firstName": "<string>",
"lastName": "<string>",
"email": "<string>",
"phone": "<string>",
"avatar": "<string>",
"locale": "<string>",
"channels": [
{
"credentials": {
"webhookUrl": "https://example.com/webhook",
"channel": "general",
"deviceTokens": [
"token1",
"token2",
"token3"
],
"alertUid": "12345-abcde",
"title": "Critical Alert",
"imageUrl": "https://example.com/image.png",
"state": "resolved",
"externalUrl": "https://example.com/details"
},
"_integrationId": "<string>",
"integrationIdentifier": "<string>"
}
],
"topics": [
"<string>"
],
"isOnline": true,
"lastOnlineAt": "<string>",
"__v": 123,
"data": {},
"timezone": "<string>"
},
"actor": {
"_id": "<string>",
"firstName": "<string>",
"lastName": "<string>",
"email": "<string>",
"phone": "<string>",
"avatar": "<string>",
"locale": "<string>",
"channels": [
{
"credentials": {
"webhookUrl": "https://example.com/webhook",
"channel": "general",
"deviceTokens": [
"token1",
"token2",
"token3"
],
"alertUid": "12345-abcde",
"title": "Critical Alert",
"imageUrl": "https://example.com/image.png",
"state": "resolved",
"externalUrl": "https://example.com/details"
},
"_integrationId": "<string>",
"integrationIdentifier": "<string>"
}
],
"topics": [
"<string>"
],
"isOnline": true,
"lastOnlineAt": "<string>",
"__v": 123,
"data": {},
"timezone": "<string>"
},
"payload": {},
"steps": {},
"context": {},
"env": {}
}
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
controlValues: {},
previewPayload: {
subscriber: {
_id: '<string>',
firstName: '<string>',
lastName: '<string>',
email: '<string>',
phone: '<string>',
avatar: '<string>',
locale: '<string>',
channels: [
{
credentials: {
webhookUrl: 'https://example.com/webhook',
channel: 'general',
deviceTokens: ['token1', 'token2', 'token3'],
alertUid: '12345-abcde',
title: 'Critical Alert',
imageUrl: 'https://example.com/image.png',
state: 'resolved',
externalUrl: 'https://example.com/details'
},
_integrationId: '<string>',
integrationIdentifier: '<string>'
}
],
topics: ['<string>'],
isOnline: true,
lastOnlineAt: '<string>',
__v: 123,
data: {},
timezone: '<string>'
},
actor: {
_id: '<string>',
firstName: '<string>',
lastName: '<string>',
email: '<string>',
phone: '<string>',
avatar: '<string>',
locale: '<string>',
channels: [
{
credentials: {
webhookUrl: 'https://example.com/webhook',
channel: 'general',
deviceTokens: ['token1', 'token2', 'token3'],
alertUid: '12345-abcde',
title: 'Critical Alert',
imageUrl: 'https://example.com/image.png',
state: 'resolved',
externalUrl: 'https://example.com/details'
},
_integrationId: '<string>',
integrationIdentifier: '<string>'
}
],
topics: ['<string>'],
isOnline: true,
lastOnlineAt: '<string>',
__v: 123,
data: {},
timezone: '<string>'
},
payload: {},
steps: {},
context: {},
env: {}
}
})
};
fetch('https://api.novu.co/v2/workflows/{workflowId}/step/{stepId}/preview', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://api.novu.co/v2/workflows/{workflowId}/step/{stepId}/preview")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"controlValues\": {},\n \"previewPayload\": {\n \"subscriber\": {\n \"_id\": \"<string>\",\n \"firstName\": \"<string>\",\n \"lastName\": \"<string>\",\n \"email\": \"<string>\",\n \"phone\": \"<string>\",\n \"avatar\": \"<string>\",\n \"locale\": \"<string>\",\n \"channels\": [\n {\n \"credentials\": {\n \"webhookUrl\": \"https://example.com/webhook\",\n \"channel\": \"general\",\n \"deviceTokens\": [\n \"token1\",\n \"token2\",\n \"token3\"\n ],\n \"alertUid\": \"12345-abcde\",\n \"title\": \"Critical Alert\",\n \"imageUrl\": \"https://example.com/image.png\",\n \"state\": \"resolved\",\n \"externalUrl\": \"https://example.com/details\"\n },\n \"_integrationId\": \"<string>\",\n \"integrationIdentifier\": \"<string>\"\n }\n ],\n \"topics\": [\n \"<string>\"\n ],\n \"isOnline\": true,\n \"lastOnlineAt\": \"<string>\",\n \"__v\": 123,\n \"data\": {},\n \"timezone\": \"<string>\"\n },\n \"actor\": {\n \"_id\": \"<string>\",\n \"firstName\": \"<string>\",\n \"lastName\": \"<string>\",\n \"email\": \"<string>\",\n \"phone\": \"<string>\",\n \"avatar\": \"<string>\",\n \"locale\": \"<string>\",\n \"channels\": [\n {\n \"credentials\": {\n \"webhookUrl\": \"https://example.com/webhook\",\n \"channel\": \"general\",\n \"deviceTokens\": [\n \"token1\",\n \"token2\",\n \"token3\"\n ],\n \"alertUid\": \"12345-abcde\",\n \"title\": \"Critical Alert\",\n \"imageUrl\": \"https://example.com/image.png\",\n \"state\": \"resolved\",\n \"externalUrl\": \"https://example.com/details\"\n },\n \"_integrationId\": \"<string>\",\n \"integrationIdentifier\": \"<string>\"\n }\n ],\n \"topics\": [\n \"<string>\"\n ],\n \"isOnline\": true,\n \"lastOnlineAt\": \"<string>\",\n \"__v\": 123,\n \"data\": {},\n \"timezone\": \"<string>\"\n },\n \"payload\": {},\n \"steps\": {},\n \"context\": {},\n \"env\": {}\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.novu.co/v2/workflows/{workflowId}/step/{stepId}/preview")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"controlValues\": {},\n \"previewPayload\": {\n \"subscriber\": {\n \"_id\": \"<string>\",\n \"firstName\": \"<string>\",\n \"lastName\": \"<string>\",\n \"email\": \"<string>\",\n \"phone\": \"<string>\",\n \"avatar\": \"<string>\",\n \"locale\": \"<string>\",\n \"channels\": [\n {\n \"credentials\": {\n \"webhookUrl\": \"https://example.com/webhook\",\n \"channel\": \"general\",\n \"deviceTokens\": [\n \"token1\",\n \"token2\",\n \"token3\"\n ],\n \"alertUid\": \"12345-abcde\",\n \"title\": \"Critical Alert\",\n \"imageUrl\": \"https://example.com/image.png\",\n \"state\": \"resolved\",\n \"externalUrl\": \"https://example.com/details\"\n },\n \"_integrationId\": \"<string>\",\n \"integrationIdentifier\": \"<string>\"\n }\n ],\n \"topics\": [\n \"<string>\"\n ],\n \"isOnline\": true,\n \"lastOnlineAt\": \"<string>\",\n \"__v\": 123,\n \"data\": {},\n \"timezone\": \"<string>\"\n },\n \"actor\": {\n \"_id\": \"<string>\",\n \"firstName\": \"<string>\",\n \"lastName\": \"<string>\",\n \"email\": \"<string>\",\n \"phone\": \"<string>\",\n \"avatar\": \"<string>\",\n \"locale\": \"<string>\",\n \"channels\": [\n {\n \"credentials\": {\n \"webhookUrl\": \"https://example.com/webhook\",\n \"channel\": \"general\",\n \"deviceTokens\": [\n \"token1\",\n \"token2\",\n \"token3\"\n ],\n \"alertUid\": \"12345-abcde\",\n \"title\": \"Critical Alert\",\n \"imageUrl\": \"https://example.com/image.png\",\n \"state\": \"resolved\",\n \"externalUrl\": \"https://example.com/details\"\n },\n \"_integrationId\": \"<string>\",\n \"integrationIdentifier\": \"<string>\"\n }\n ],\n \"topics\": [\n \"<string>\"\n ],\n \"isOnline\": true,\n \"lastOnlineAt\": \"<string>\",\n \"__v\": 123,\n \"data\": {},\n \"timezone\": \"<string>\"\n },\n \"payload\": {},\n \"steps\": {},\n \"context\": {},\n \"env\": {}\n }\n}"
response = http.request(request)
puts response.read_body{
"previewPayloadExample": {
"subscriber": {
"_id": "<string>",
"firstName": "<string>",
"lastName": "<string>",
"email": "<string>",
"phone": "<string>",
"avatar": "<string>",
"locale": "<string>",
"channels": [
{
"credentials": {
"webhookUrl": "https://example.com/webhook",
"channel": "general",
"deviceTokens": [
"token1",
"token2",
"token3"
],
"alertUid": "12345-abcde",
"title": "Critical Alert",
"imageUrl": "https://example.com/image.png",
"state": "resolved",
"externalUrl": "https://example.com/details"
},
"_integrationId": "<string>",
"integrationIdentifier": "<string>"
}
],
"topics": [
"<string>"
],
"isOnline": true,
"lastOnlineAt": "<string>",
"__v": 123,
"data": {},
"timezone": "<string>"
},
"actor": {
"_id": "<string>",
"firstName": "<string>",
"lastName": "<string>",
"email": "<string>",
"phone": "<string>",
"avatar": "<string>",
"locale": "<string>",
"channels": [
{
"credentials": {
"webhookUrl": "https://example.com/webhook",
"channel": "general",
"deviceTokens": [
"token1",
"token2",
"token3"
],
"alertUid": "12345-abcde",
"title": "Critical Alert",
"imageUrl": "https://example.com/image.png",
"state": "resolved",
"externalUrl": "https://example.com/details"
},
"_integrationId": "<string>",
"integrationIdentifier": "<string>"
}
],
"topics": [
"<string>"
],
"isOnline": true,
"lastOnlineAt": "<string>",
"__v": 123,
"data": {},
"timezone": "<string>"
},
"payload": {},
"steps": {},
"context": {},
"env": {}
},
"result": {},
"schema": {},
"novuSignature": "<string>"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"errors": {
"fieldName1": {
"messages": [
"Field is required",
"Must be a valid email address"
],
"value": "invalidEmail"
},
"fieldName2": {
"messages": [
"Must be at least 18 years old"
],
"value": 17
},
"fieldName3": {
"messages": [
"Must be a boolean value"
],
"value": true
},
"fieldName4": {
"messages": [
"Must be a valid object"
],
"value": {
"key": "value"
}
},
"fieldName5": {
"messages": [
"Field is missing"
],
"value": null
},
"fieldName6": {
"messages": [
"Undefined value"
]
}
},
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}"API rate limit exceeded"{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}"Please wait some time, then try again."Authorizations
API key authentication. Allowed headers-- "Authorization: ApiKey <novu_secret_key>".
Headers
A header for idempotency purposes
Body
application/json
Preview generation details
Response
Created
Preview payload example
Show child attributes
Show child attributes
Preview result
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- Option 6
- Option 7
- Option 8
- Option 9
The payload schema that was used to generate the preview payload example
Sample novu-signature header value for HTTP request steps
Was this page helpful?
⌘I
TypeScript
import { Novu } from "@novu/api";
const novu = new Novu({
secretKey: "YOUR_SECRET_KEY_HERE",
});
async function run() {
const result = await novu.workflows.steps.generatePreview({
workflowId: "<id>",
stepId: "<id>",
generatePreviewRequestDto: {
previewPayload: {
subscriber: {
channels: [
{
providerId: "novu-slack",
credentials: {
webhookUrl: "https://example.com/webhook",
channel: "general",
deviceTokens: [
"token1",
"token2",
"token3",
],
alertUid: "12345-abcde",
title: "Critical Alert",
imageUrl: "https://example.com/image.png",
state: "resolved",
externalUrl: "https://example.com/details",
},
integrationId: "<id>",
},
],
},
actor: {
channels: [
{
providerId: "telegram",
credentials: {
webhookUrl: "https://example.com/webhook",
channel: "general",
deviceTokens: [
"token1",
"token2",
"token3",
],
alertUid: "12345-abcde",
title: "Critical Alert",
imageUrl: "https://example.com/image.png",
state: "resolved",
externalUrl: "https://example.com/details",
},
integrationId: "<id>",
},
],
},
context: {
"key": "org-acme",
},
},
},
});
console.log(result);
}
run();using Novu;
using Novu.Models.Components;
using System.Collections.Generic;
var sdk = new NovuSDK(secretKey: "YOUR_SECRET_KEY_HERE");
var res = await sdk.Workflows.Steps.GeneratePreviewAsync(
workflowId: "<id>",
stepId: "<id>",
generatePreviewRequestDto: new GeneratePreviewRequestDto() {
PreviewPayload = new PreviewPayloadDto() {
Subscriber = new SubscriberResponseDtoOptional() {
Channels = new List<ChannelSettingsDto>() {
new ChannelSettingsDto() {
ProviderId = ChatOrPushProviderEnum.NovuSlack,
Credentials = new ChannelCredentials() {
WebhookUrl = "https://example.com/webhook",
Channel = "general",
DeviceTokens = new List<string>() {
"token1",
"token2",
"token3",
},
AlertUid = "12345-abcde",
Title = "Critical Alert",
ImageUrl = "https://example.com/image.png",
State = "resolved",
ExternalUrl = "https://example.com/details",
},
IntegrationId = "<id>",
},
},
},
Actor = new SubscriberResponseDtoOptional() {
Channels = new List<ChannelSettingsDto>() {
new ChannelSettingsDto() {
ProviderId = ChatOrPushProviderEnum.Telegram,
Credentials = new ChannelCredentials() {
WebhookUrl = "https://example.com/webhook",
Channel = "general",
DeviceTokens = new List<string>() {
"token1",
"token2",
"token3",
},
AlertUid = "12345-abcde",
Title = "Critical Alert",
ImageUrl = "https://example.com/image.png",
State = "resolved",
ExternalUrl = "https://example.com/details",
},
IntegrationId = "<id>",
},
},
},
Context = new Dictionary<string, PreviewPayloadDtoContext>() {
{ "key", PreviewPayloadDtoContext.CreateStr(
"org-acme"
) },
},
},
}
);
// handle responsedeclare(strict_types=1);
require 'vendor/autoload.php';
use novu;
use novu\Models\Components;
$sdk = novu\Novu::builder()
->setSecurity(
'YOUR_SECRET_KEY_HERE'
)
->build();
$generatePreviewRequestDto = new Components\GeneratePreviewRequestDto(
previewPayload: new Components\PreviewPayloadDto(
subscriber: new Components\SubscriberResponseDtoOptional(
channels: [
new Components\ChannelSettingsDto(
providerId: Components\ChatOrPushProviderEnum::NovuSlack,
credentials: new Components\ChannelCredentials(
webhookUrl: 'https://example.com/webhook',
channel: 'general',
deviceTokens: [
'token1',
'token2',
'token3',
],
alertUid: '12345-abcde',
title: 'Critical Alert',
imageUrl: 'https://example.com/image.png',
state: 'resolved',
externalUrl: 'https://example.com/details',
),
integrationId: '<id>',
),
],
),
actor: new Components\SubscriberResponseDtoOptional(
channels: [
new Components\ChannelSettingsDto(
providerId: Components\ChatOrPushProviderEnum::Telegram,
credentials: new Components\ChannelCredentials(
webhookUrl: 'https://example.com/webhook',
channel: 'general',
deviceTokens: [
'token1',
'token2',
'token3',
],
alertUid: '12345-abcde',
title: 'Critical Alert',
imageUrl: 'https://example.com/image.png',
state: 'resolved',
externalUrl: 'https://example.com/details',
),
integrationId: '<id>',
),
],
),
context: [
'key' => 'org-acme',
],
),
);
$response = $sdk->workflows->steps->generatePreview(
workflowId: '<id>',
stepId: '<id>',
generatePreviewRequestDto: $generatePreviewRequestDto
);
if ($response->generatePreviewResponseDto !== null) {
// handle response
}import novu_py
from novu_py import Novu
with Novu(
secret_key="YOUR_SECRET_KEY_HERE",
) as novu:
res = novu.workflows.steps.generate_preview(workflow_id="<id>", step_id="<id>", generate_preview_request_dto=novu_py.GeneratePreviewRequestDto(
preview_payload=novu_py.PreviewPayloadDto(
subscriber=novu_py.SubscriberResponseDtoOptional(
channels=[
novu_py.ChannelSettingsDto(
provider_id=novu_py.ChatOrPushProviderEnum.NOVU_SLACK,
credentials=novu_py.ChannelCredentials(
webhook_url="https://example.com/webhook",
channel="general",
device_tokens=[
"token1",
"token2",
"token3",
],
alert_uid="12345-abcde",
title="Critical Alert",
image_url="https://example.com/image.png",
state="resolved",
external_url="https://example.com/details",
),
integration_id="<id>",
),
],
),
actor=novu_py.SubscriberResponseDtoOptional(
channels=[
novu_py.ChannelSettingsDto(
provider_id=novu_py.ChatOrPushProviderEnum.TELEGRAM,
credentials=novu_py.ChannelCredentials(
webhook_url="https://example.com/webhook",
channel="general",
device_tokens=[
"token1",
"token2",
"token3",
],
alert_uid="12345-abcde",
title="Critical Alert",
image_url="https://example.com/image.png",
state="resolved",
external_url="https://example.com/details",
),
integration_id="<id>",
),
],
),
context={
"key": "org-acme",
},
),
))
# Handle response
print(res)package main
import(
"context"
"github.com/novuhq/novu-go/v3"
"github.com/novuhq/novu-go/v3/models/components"
"log"
)
func main() {
ctx := context.Background()
s := v3.New(
v3.WithSecurity("YOUR_SECRET_KEY_HERE"),
)
res, err := s.Workflows.Steps.GeneratePreview(ctx, "<id>", "<id>", components.GeneratePreviewRequestDto{
PreviewPayload: &components.PreviewPayloadDto{
Subscriber: &components.SubscriberResponseDtoOptional{
Channels: []components.ChannelSettingsDto{
components.ChannelSettingsDto{
ProviderID: components.ChatOrPushProviderEnumNovuSlack,
Credentials: components.ChannelCredentials{
WebhookURL: v3.Pointer("https://example.com/webhook"),
Channel: v3.Pointer("general"),
DeviceTokens: []string{
"token1",
"token2",
"token3",
},
AlertUID: v3.Pointer("12345-abcde"),
Title: v3.Pointer("Critical Alert"),
ImageURL: v3.Pointer("https://example.com/image.png"),
State: v3.Pointer("resolved"),
ExternalURL: v3.Pointer("https://example.com/details"),
},
IntegrationID: "<id>",
},
},
},
Actor: &components.SubscriberResponseDtoOptional{
Channels: []components.ChannelSettingsDto{
components.ChannelSettingsDto{
ProviderID: components.ChatOrPushProviderEnumTelegram,
Credentials: components.ChannelCredentials{
WebhookURL: v3.Pointer("https://example.com/webhook"),
Channel: v3.Pointer("general"),
DeviceTokens: []string{
"token1",
"token2",
"token3",
},
AlertUID: v3.Pointer("12345-abcde"),
Title: v3.Pointer("Critical Alert"),
ImageURL: v3.Pointer("https://example.com/image.png"),
State: v3.Pointer("resolved"),
ExternalURL: v3.Pointer("https://example.com/details"),
},
IntegrationID: "<id>",
},
},
},
Context: map[string]components.PreviewPayloadDtoContext{
"key": components.CreatePreviewPayloadDtoContextStr(
"org-acme",
),
},
},
}, nil)
if err != nil {
log.Fatal(err)
}
if res.GeneratePreviewResponseDto != nil {
switch res.GeneratePreviewResponseDto.Result.Type {
case components.GeneratePreviewResponseDtoResultUnionTypeMapOfAny:
// res.GeneratePreviewResponseDto.Result.MapOfAny is populated
case components.GeneratePreviewResponseDtoResultUnionTypeResult2:
// res.GeneratePreviewResponseDto.Result.Result2 is populated
case components.GeneratePreviewResponseDtoResultUnionTypeThree:
// res.GeneratePreviewResponseDto.Result.Three is populated
case components.GeneratePreviewResponseDtoResultUnionTypeResult4:
// res.GeneratePreviewResponseDto.Result.Result4 is populated
case components.GeneratePreviewResponseDtoResultUnionTypeResult5:
// res.GeneratePreviewResponseDto.Result.Result5 is populated
case components.GeneratePreviewResponseDtoResultUnionTypeSix:
// res.GeneratePreviewResponseDto.Result.Six is populated
case components.GeneratePreviewResponseDtoResultUnionTypeSeven:
// res.GeneratePreviewResponseDto.Result.Seven is populated
case components.GeneratePreviewResponseDtoResultUnionTypeEight:
// res.GeneratePreviewResponseDto.Result.Eight is populated
case components.GeneratePreviewResponseDtoResultUnionTypeNine:
// res.GeneratePreviewResponseDto.Result.Nine is populated
}
}
}curl --request POST \
--url https://api.novu.co/v2/workflows/{workflowId}/step/{stepId}/preview \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"controlValues": {},
"previewPayload": {
"subscriber": {
"_id": "<string>",
"firstName": "<string>",
"lastName": "<string>",
"email": "<string>",
"phone": "<string>",
"avatar": "<string>",
"locale": "<string>",
"channels": [
{
"credentials": {
"webhookUrl": "https://example.com/webhook",
"channel": "general",
"deviceTokens": [
"token1",
"token2",
"token3"
],
"alertUid": "12345-abcde",
"title": "Critical Alert",
"imageUrl": "https://example.com/image.png",
"state": "resolved",
"externalUrl": "https://example.com/details"
},
"_integrationId": "<string>",
"integrationIdentifier": "<string>"
}
],
"topics": [
"<string>"
],
"isOnline": true,
"lastOnlineAt": "<string>",
"__v": 123,
"data": {},
"timezone": "<string>"
},
"actor": {
"_id": "<string>",
"firstName": "<string>",
"lastName": "<string>",
"email": "<string>",
"phone": "<string>",
"avatar": "<string>",
"locale": "<string>",
"channels": [
{
"credentials": {
"webhookUrl": "https://example.com/webhook",
"channel": "general",
"deviceTokens": [
"token1",
"token2",
"token3"
],
"alertUid": "12345-abcde",
"title": "Critical Alert",
"imageUrl": "https://example.com/image.png",
"state": "resolved",
"externalUrl": "https://example.com/details"
},
"_integrationId": "<string>",
"integrationIdentifier": "<string>"
}
],
"topics": [
"<string>"
],
"isOnline": true,
"lastOnlineAt": "<string>",
"__v": 123,
"data": {},
"timezone": "<string>"
},
"payload": {},
"steps": {},
"context": {},
"env": {}
}
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
controlValues: {},
previewPayload: {
subscriber: {
_id: '<string>',
firstName: '<string>',
lastName: '<string>',
email: '<string>',
phone: '<string>',
avatar: '<string>',
locale: '<string>',
channels: [
{
credentials: {
webhookUrl: 'https://example.com/webhook',
channel: 'general',
deviceTokens: ['token1', 'token2', 'token3'],
alertUid: '12345-abcde',
title: 'Critical Alert',
imageUrl: 'https://example.com/image.png',
state: 'resolved',
externalUrl: 'https://example.com/details'
},
_integrationId: '<string>',
integrationIdentifier: '<string>'
}
],
topics: ['<string>'],
isOnline: true,
lastOnlineAt: '<string>',
__v: 123,
data: {},
timezone: '<string>'
},
actor: {
_id: '<string>',
firstName: '<string>',
lastName: '<string>',
email: '<string>',
phone: '<string>',
avatar: '<string>',
locale: '<string>',
channels: [
{
credentials: {
webhookUrl: 'https://example.com/webhook',
channel: 'general',
deviceTokens: ['token1', 'token2', 'token3'],
alertUid: '12345-abcde',
title: 'Critical Alert',
imageUrl: 'https://example.com/image.png',
state: 'resolved',
externalUrl: 'https://example.com/details'
},
_integrationId: '<string>',
integrationIdentifier: '<string>'
}
],
topics: ['<string>'],
isOnline: true,
lastOnlineAt: '<string>',
__v: 123,
data: {},
timezone: '<string>'
},
payload: {},
steps: {},
context: {},
env: {}
}
})
};
fetch('https://api.novu.co/v2/workflows/{workflowId}/step/{stepId}/preview', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://api.novu.co/v2/workflows/{workflowId}/step/{stepId}/preview")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"controlValues\": {},\n \"previewPayload\": {\n \"subscriber\": {\n \"_id\": \"<string>\",\n \"firstName\": \"<string>\",\n \"lastName\": \"<string>\",\n \"email\": \"<string>\",\n \"phone\": \"<string>\",\n \"avatar\": \"<string>\",\n \"locale\": \"<string>\",\n \"channels\": [\n {\n \"credentials\": {\n \"webhookUrl\": \"https://example.com/webhook\",\n \"channel\": \"general\",\n \"deviceTokens\": [\n \"token1\",\n \"token2\",\n \"token3\"\n ],\n \"alertUid\": \"12345-abcde\",\n \"title\": \"Critical Alert\",\n \"imageUrl\": \"https://example.com/image.png\",\n \"state\": \"resolved\",\n \"externalUrl\": \"https://example.com/details\"\n },\n \"_integrationId\": \"<string>\",\n \"integrationIdentifier\": \"<string>\"\n }\n ],\n \"topics\": [\n \"<string>\"\n ],\n \"isOnline\": true,\n \"lastOnlineAt\": \"<string>\",\n \"__v\": 123,\n \"data\": {},\n \"timezone\": \"<string>\"\n },\n \"actor\": {\n \"_id\": \"<string>\",\n \"firstName\": \"<string>\",\n \"lastName\": \"<string>\",\n \"email\": \"<string>\",\n \"phone\": \"<string>\",\n \"avatar\": \"<string>\",\n \"locale\": \"<string>\",\n \"channels\": [\n {\n \"credentials\": {\n \"webhookUrl\": \"https://example.com/webhook\",\n \"channel\": \"general\",\n \"deviceTokens\": [\n \"token1\",\n \"token2\",\n \"token3\"\n ],\n \"alertUid\": \"12345-abcde\",\n \"title\": \"Critical Alert\",\n \"imageUrl\": \"https://example.com/image.png\",\n \"state\": \"resolved\",\n \"externalUrl\": \"https://example.com/details\"\n },\n \"_integrationId\": \"<string>\",\n \"integrationIdentifier\": \"<string>\"\n }\n ],\n \"topics\": [\n \"<string>\"\n ],\n \"isOnline\": true,\n \"lastOnlineAt\": \"<string>\",\n \"__v\": 123,\n \"data\": {},\n \"timezone\": \"<string>\"\n },\n \"payload\": {},\n \"steps\": {},\n \"context\": {},\n \"env\": {}\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.novu.co/v2/workflows/{workflowId}/step/{stepId}/preview")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"controlValues\": {},\n \"previewPayload\": {\n \"subscriber\": {\n \"_id\": \"<string>\",\n \"firstName\": \"<string>\",\n \"lastName\": \"<string>\",\n \"email\": \"<string>\",\n \"phone\": \"<string>\",\n \"avatar\": \"<string>\",\n \"locale\": \"<string>\",\n \"channels\": [\n {\n \"credentials\": {\n \"webhookUrl\": \"https://example.com/webhook\",\n \"channel\": \"general\",\n \"deviceTokens\": [\n \"token1\",\n \"token2\",\n \"token3\"\n ],\n \"alertUid\": \"12345-abcde\",\n \"title\": \"Critical Alert\",\n \"imageUrl\": \"https://example.com/image.png\",\n \"state\": \"resolved\",\n \"externalUrl\": \"https://example.com/details\"\n },\n \"_integrationId\": \"<string>\",\n \"integrationIdentifier\": \"<string>\"\n }\n ],\n \"topics\": [\n \"<string>\"\n ],\n \"isOnline\": true,\n \"lastOnlineAt\": \"<string>\",\n \"__v\": 123,\n \"data\": {},\n \"timezone\": \"<string>\"\n },\n \"actor\": {\n \"_id\": \"<string>\",\n \"firstName\": \"<string>\",\n \"lastName\": \"<string>\",\n \"email\": \"<string>\",\n \"phone\": \"<string>\",\n \"avatar\": \"<string>\",\n \"locale\": \"<string>\",\n \"channels\": [\n {\n \"credentials\": {\n \"webhookUrl\": \"https://example.com/webhook\",\n \"channel\": \"general\",\n \"deviceTokens\": [\n \"token1\",\n \"token2\",\n \"token3\"\n ],\n \"alertUid\": \"12345-abcde\",\n \"title\": \"Critical Alert\",\n \"imageUrl\": \"https://example.com/image.png\",\n \"state\": \"resolved\",\n \"externalUrl\": \"https://example.com/details\"\n },\n \"_integrationId\": \"<string>\",\n \"integrationIdentifier\": \"<string>\"\n }\n ],\n \"topics\": [\n \"<string>\"\n ],\n \"isOnline\": true,\n \"lastOnlineAt\": \"<string>\",\n \"__v\": 123,\n \"data\": {},\n \"timezone\": \"<string>\"\n },\n \"payload\": {},\n \"steps\": {},\n \"context\": {},\n \"env\": {}\n }\n}"
response = http.request(request)
puts response.read_body{
"previewPayloadExample": {
"subscriber": {
"_id": "<string>",
"firstName": "<string>",
"lastName": "<string>",
"email": "<string>",
"phone": "<string>",
"avatar": "<string>",
"locale": "<string>",
"channels": [
{
"credentials": {
"webhookUrl": "https://example.com/webhook",
"channel": "general",
"deviceTokens": [
"token1",
"token2",
"token3"
],
"alertUid": "12345-abcde",
"title": "Critical Alert",
"imageUrl": "https://example.com/image.png",
"state": "resolved",
"externalUrl": "https://example.com/details"
},
"_integrationId": "<string>",
"integrationIdentifier": "<string>"
}
],
"topics": [
"<string>"
],
"isOnline": true,
"lastOnlineAt": "<string>",
"__v": 123,
"data": {},
"timezone": "<string>"
},
"actor": {
"_id": "<string>",
"firstName": "<string>",
"lastName": "<string>",
"email": "<string>",
"phone": "<string>",
"avatar": "<string>",
"locale": "<string>",
"channels": [
{
"credentials": {
"webhookUrl": "https://example.com/webhook",
"channel": "general",
"deviceTokens": [
"token1",
"token2",
"token3"
],
"alertUid": "12345-abcde",
"title": "Critical Alert",
"imageUrl": "https://example.com/image.png",
"state": "resolved",
"externalUrl": "https://example.com/details"
},
"_integrationId": "<string>",
"integrationIdentifier": "<string>"
}
],
"topics": [
"<string>"
],
"isOnline": true,
"lastOnlineAt": "<string>",
"__v": 123,
"data": {},
"timezone": "<string>"
},
"payload": {},
"steps": {},
"context": {},
"env": {}
},
"result": {},
"schema": {},
"novuSignature": "<string>"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"errors": {
"fieldName1": {
"messages": [
"Field is required",
"Must be a valid email address"
],
"value": "invalidEmail"
},
"fieldName2": {
"messages": [
"Must be at least 18 years old"
],
"value": 17
},
"fieldName3": {
"messages": [
"Must be a boolean value"
],
"value": true
},
"fieldName4": {
"messages": [
"Must be a valid object"
],
"value": {
"key": "value"
}
},
"fieldName5": {
"messages": [
"Field is missing"
],
"value": null
},
"fieldName6": {
"messages": [
"Undefined value"
]
}
},
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}"API rate limit exceeded"{
"statusCode": 404,
"timestamp": "2024-12-12T13:00:00Z",
"path": "/api/v1/resource",
"message": "xx xx xx ",
"ctx": {
"workflowId": "some_wf_id",
"stepId": "some_wf_id"
},
"errorId": "abc123"
}"Please wait some time, then try again."