-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Summary
When using the Novu SDK (@novu/api) to create or update a workflow, I receive a ResponseValidationError related to the slug field. The API returns a string for slug, but the SDK expects an object, causing a Zod validation error.
Steps to Reproduce
- Use the following code to create or update a workflow (with or without steps):
import { Novu } from '@novu/api';
const novu = new Novu({
secretKey: 'YOUR_SECRET_KEY',
serverURL: 'YOUR_NOVU_API_URL',
});
const workflowId = 'test-workflow';
const workflowData = {
name: "Test Workflow",
workflowId,
steps: [],
preferences: {
user: {
all: { enabled: true, readOnly: false },
channels: {
email: { enabled: true },
sms: { enabled: false },
in_app: { enabled: true },
push: { enabled: false },
chat: { enabled: false },
},
},
workflow: {
all: { enabled: true, readOnly: false },
channels: {
email: { enabled: true },
sms: { enabled: false },
in_app: { enabled: true },
push: { enabled: false },
chat: { enabled: false },
},
},
},
origin: "external",
};
async function upsertWorkflow() {
try {
const workflow = await novu.workflows.get(workflowId);
await novu.workflows.update(workflowData, workflowId);
} catch (e) {
if (e?.status === 404) {
await novu.workflows.create(workflowData);
} else {
console.error('Error:', e);
}
}
}
upsertWorkflow();- Run the code.
Actual Result
- The workflow is created/updated in Novu, but the SDK throws the following error:
ResponseValidationError: Response validation failed
cause: ZodError: [
{
"code": "invalid_type",
"expected": "object",
"received": "string",
"path": [
"Result",
"slug"
],
"message": "Expected object, received string"
}
]
- The raw API response contains
"slug": "test-workflow-updated_wf_g1AKKbVFD5Mg6Kay"(a string), but the SDK expects an object.
Expected Result
- The SDK should accept the API response, or the API should return the correct type for
slugas expected by the SDK.
Additional Info
- Novu SDK version:
@novu/[email protected] - API response (truncated):
{
"_id": "...",
"slug": "test-workflow-updated_wf_g1AKKbVFD5Mg6Kay",
...
}This issue blocks any upsert/migration automation for workflows via code, as the SDK always throws on response validation.
Metadata
Metadata
Assignees
Labels
No labels