N
Novu•5d ago
Dara

TypeError: Converting circular structure to JSON

Hi There, I'm trying to test an endpoint for a TypeScript Express app using the Novu framework and I am encountering a TypeError that I don't understand. I don't know if this is a bug or if I have made a mistake implementing Novu. Details: I'm running my server locally and exposing the /api/novu bridge endpoint using ngrok. I'm using macOS 15.3.1 with 24GB of RAM. My npm version is 10.9.0 and running on Node 23.3.0 Here is the endpoint I have been trying to trigger in Postman:
// Middleware to parse JSON
app.use(express.json());

// Initialize Novu
const novu = new Novu(process.env.NOVU_SECRET_KEY || '')

app.use( "/api/novu", serve({ workflows: [testWorkflow] }) );


// POST Send notification
app.post('/api/trigger-workflow', async (req, res): Promise<any> => {
const { workflowName, payload, user } = req.body;

if (!workflowName || !payload || !user) {
return res.status(400).json({ message: 'Missing required fields' });
}

try {
const result = await novu.trigger(workflowName, {
to: {
subscriberId: user.userId,
email: user.email,
},
payload
});

res.status(200).json({success: true, result});
} catch (err) {
console.error('Error triggering Novu workflow', err);
res.status(500).send('Server error');
}
});
// Middleware to parse JSON
app.use(express.json());

// Initialize Novu
const novu = new Novu(process.env.NOVU_SECRET_KEY || '')

app.use( "/api/novu", serve({ workflows: [testWorkflow] }) );


// POST Send notification
app.post('/api/trigger-workflow', async (req, res): Promise<any> => {
const { workflowName, payload, user } = req.body;

if (!workflowName || !payload || !user) {
return res.status(400).json({ message: 'Missing required fields' });
}

try {
const result = await novu.trigger(workflowName, {
to: {
subscriberId: user.userId,
email: user.email,
},
payload
});

res.status(200).json({success: true, result});
} catch (err) {
console.error('Error triggering Novu workflow', err);
res.status(500).send('Server error');
}
});
I attached a screenshot of the error as well as the request I am trying to make in Postman. Here is the workflow in my code:
export const testWorkflow = workflow('test-workflow', async ({ step, payload }) => {
await step.inApp('Send in-app message', async () => {
return {
subject: `Hello, ${payload.recipient}`,
body: `This is your first Novu message from ${payload.userName}`,
};
});
}, {
payloadSchema: z.object({
userName: z.string().default('Jimmy Doe'),
recipient: z.string().default('Recipient')
}),
});
export const testWorkflow = workflow('test-workflow', async ({ step, payload }) => {
await step.inApp('Send in-app message', async () => {
return {
subject: `Hello, ${payload.recipient}`,
body: `This is your first Novu message from ${payload.userName}`,
};
});
}, {
payloadSchema: z.object({
userName: z.string().default('Jimmy Doe'),
recipient: z.string().default('Recipient')
}),
});
Thanks so much for your help. I hope I'm not making a stupid mistake 😅
No description
No description
3 Replies
Pawan Jain
Pawan Jain•5d ago
@Dara In this line
res.status(200).json({success: true, result});
res.status(200).json({success: true, result});
Instead of sending the entire result, carefully select the properties you need create a new object, and then send
Dara
DaraOP•5d ago
Thanks @Pawan Jain ! I missed that line! I was able to send the data I needed from the result object instead of the whole result. Thanks for your swift help!
Novu_Bot
Novu_Bot•5d ago
@Dara, you just advanced to level 1!

Did you find this page helpful?