Skip to content

🐞 Bug: ResponseValidationError when using Novu SDK/API for workflows #77

@dacom-dark-sun

Description

@dacom-dark-sun

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

  1. 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();
  1. 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 slug as expected by the SDK.

Additional Info

{
  "_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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions