rustclanR
tRPC3y ago
2 replies
rustclan

trpc receiving undefined

Hello, I am having a few problems with one of my TRPC endpoints not recieving the data sent through a webhook body
export const voteRouter = createTRPCRouter({
  voteCreate: publicProcedure
    .input(
      z.object({
        user: z.string(),
        type: z.string(),
        query: z.string(),
        isWeekend: z.boolean().nullable().optional(),
        bot: z.string(),
      })
    ).mutation(async ({ ctx, input }) => {
      console.log(input);
    }),
});

however, i get this error when trpc parses the data
site:dev: :x: tRPC failed on vote.voteCreate: [
site:dev:   {
site:dev:     "code": "invalid_type",
site:dev:     "expected": "object",
site:dev:     "received": "undefined",
site:dev:     "path": [],
site:dev:     "message": "Required"
site:dev:   }
site:dev: ]


I'm not entirely sure why this says
received
undefined, when the
request.body
outputs:
{
  user: '123',
  type: 'upvote',
  query: '',
  isWeekend: false,
  bot: '123'
}

export default createNextApiHandler({
  router: appRouter,
  createContext: createTRPCContext,
  onError: async (opts) => {
    const { error, path, req } = opts;
    console.log(req.body);

root:
export const appRouter = createTRPCRouter({
  vote: voteRouter,
});

insomnia request:
image.png
Was this page helpful?