#Failed to send notification: ErrorDto: API Key not found

1 messages · Page 1 of 1 (latest)

red needle
#

lib/novu.ts

'server-only';

import { Novu } from '@novu/api';
import { env } from '~/env';

export const novu = new Novu({
  secretKey: env.NOVU_SECRET_KEY,
  serverURL: 'https://eu.api.novu.co'
});

router/account-link.ts

sendLinkRequest: protectedProcedure
    .input(z.object({
      target_user_id: z.number(),
      message: z.string().optional(),
    }))
    .mutation(async ({ ctx, input }) => {
      ...
      // Send Novu notification
      try {
        await novu.trigger({
          workflowId: 'account-link-request',
          to: {
            subscriberId: targetUser.clerk_id,
            email: targetUser.email,
            firstName: targetUser.firstname,
            lastName: targetUser.lastname,
          },
          payload: {
            requesterName: `${currentUser.firstname} ${currentUser.lastname}`,
            requesterEmail: currentUser.email,
            requesterType: currentUser.account_type,
            targetType: targetUser.account_type,
            message: input.message || '',
            requestId: linkRequest[0]?.id,
            actionUrl: `${env.NEXT_PUBLIC_BASE_URL}/settings?request=${linkRequest[0]?.id}`,
          },
        });
      } catch (error) {
        console.error('Failed to send notification:', error);
        // Continue even if notification fails
      }

In Nextjs I get the following error:
'data$': {
statusCode: 401,
timestamp: '2025-06-10T11:06:55.596Z',
path: '/v1/events/trigger',
message: 'API Key not found',
ctx: { error: 'Unauthorized', statusCode: 401 }
},

Deps:
"next": "14.2.25",
"@novu/api": "^1.3.0",
"@novu/nextjs": "^3.5.0"

@chrome zealot

#

Full Log is below

Failed to send notification: ErrorDto: API Key not found
    at Object.transform (/var/task/.next/server/chunks/9786.js:13:456343)
    at ea._parse (/var/task/.next/server/chunks/9786.js:16:243839)
    at ea._parseSync (/var/task/.next/server/chunks/9786.js:16:195969)
    at ea.safeParse (/var/task/.next/server/chunks/9786.js:16:196397)
    at ea.parse (/var/task/.next/server/chunks/9786.js:16:196138)
    at /var/task/.next/server/chunks/9786.js:13:163583
    at t.safeParse (/var/task/.next/server/chunks/9786.js:13:167425)
    at /var/task/.next/server/chunks/9786.js:13:163568
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async f (/var/task/.next/server/chunks/9786.js:13:139668) {
  'data$': {
    statusCode: 401,
    timestamp: '2025-06-10T11:06:55.596Z',
    path: '/v1/events/trigger',
    message: 'API Key not found',
    ctx: { error: 'Unauthorized', statusCode: 401 }
  },
  statusCode: 401,
  timestamp: '2025-06-10T11:06:55.596Z',
  path: '/v1/events/trigger',
  ctx: { error: 'Unauthorized', statusCode: 401 }
}
chrome zealot
red needle
chrome zealot
#

@red needle

Yes, .co is the correct one

red needle
#

Thank you