T
tRPC

❓-help

Why webhooks does not work with TRPC?

Kkstulgys10/20/2023
I have a what suppose to be a webhook:
deposit: publicProcedure.input(z.any()).mutation(async ({ ctx, input }) => {
console.log(input);
return { input };
}),
deposit: publicProcedure.input(z.any()).mutation(async ({ ctx, input }) => {
console.log(input);
return { input };
}),
When I POST to this endpoint it responds with:
{
"result": {
"data": {
"json": {
"input": null
},
"meta": {
"values": {
"input": [
"undefined"
]
}
}
}
}
}
{
"result": {
"data": {
"json": {
"input": null
},
"meta": {
"values": {
"input": [
"undefined"
]
}
}
}
}
}
Why? console logs undefined on the server.
Nnlucas10/20/2023
It’s because you have a transformer set up, that’s the transformer format
Kkstulgys10/20/2023
well, same thing without transformer:
{
"result": {
"data": {}
}
}
{
"result": {
"data": {}
}
}
NNEO10/20/2023
import { buffer } from "micro";

const stripeWebhook = publicProcedure
.meta({
openapi: {
method: "POST",
path: "/stripe-webhook",
},
})
.input(z.void())
.output(
z.object({
status: z.string(),
})
)
.mutation(async ({ ctx }) => {
const buf = await buffer(ctx.req);
const request = buf.toString("utf8");
});
import { buffer } from "micro";

const stripeWebhook = publicProcedure
.meta({
openapi: {
method: "POST",
path: "/stripe-webhook",
},
})
.input(z.void())
.output(
z.object({
status: z.string(),
})
)
.mutation(async ({ ctx }) => {
const buf = await buffer(ctx.req);
const request = buf.toString("utf8");
});
this is how I handle my stripe webhook, the body is somewhere is request you'll have to figure it out
Nnlucas10/20/2023
Undefined keys get dropped from normal JSON serialisation, so that also looks correct You haven’t said if you’re posting any body to the mutation, so I have to assume it’s just a straight post
Kkstulgys10/21/2023
actually it's working, all good
deposit: publicProcedure.input(z.any()).mutation(({ ctx, input }) => {
console.log(input);
return { input };
}),
deposit: publicProcedure.input(z.any()).mutation(({ ctx, input }) => {
console.log(input);
return { input };
}),
{
"result": {
"data": {
"input": {
"hello": "world"
}
}
}
}
{
"result": {
"data": {
"input": {
"hello": "world"
}
}
}
}
I've been posting to this endpoint without content-type: application/json header before.

Looking for more? Join the community!

Recommended Posts
tRPC set up errorHey guys, I've been trying to set up tRPC, but unfortunatyy getting this error and it is really unclVercel maxDuration with tRPCHow do you extend extend tRPC timeouts on Vercel? I tried this in `vercel.json`: ```json { "functWhere is client side error handling documented?In the docs, I can only find error handling for the backend. But I want to get the TRPCError code indoes api.myQuery.invalidate() works if the query is not made at the first place?from testing, the invalidate runs the query, but it shouldn't because there is no cache? how do i iworking with custom errors and trpc errorFormatterHey guys. I'm trying to refactor my app so that all errors extend a BaseError class to make dealing tRPC and OpenTelemetryDoes anyone have experience with instrumenting tRPC with OTEL for tracing? It would be pretty neat Multiple TRPC endpoints on same API, with discrete clients? Any gotchas?I'm building a Sveltekit app that has several pages that will need to behave like SPA's. Rather thanProper way to revalidate SSR but from Client Side, ie. after a success Mutation.This question has been also posted on an specific thread but posting this here will allow people to How to implement tRPC auth ?Do you have any article/github links for how can i create auth in tRPC ?tRPC middleware infer type from another protectedProcedureHello, `protectedProcedure` check and adds a not nullable user to the ctx. However the `studyMiddlewtRPC requests on client vs server for NextJsHello, I'm new to tRPC, and am confused on one thing. I have watched videos of some using a server cpassing user input state variable to all api callsI have a multi organization app and need a way of passing the current organizationId on all requestsIs there a way to extract a procedure signature?I'm looking into extracting certain handlers into functions to keep certain procedures more manageabIs there a pattern for omitting certain types of errors from being returned in the API responseI'd prefer not to expose the ORM queries being used in my resolver. I'm already providing an `onErroDynamic input not leading to changes on the front endI'm building a dynamic procedure to access my database via Drizzle ORM. Ideally a developer would btRPC with with react-query prefetching in Next.js app directory.Hi. What is currently the best way to do prefetching in Next.js app directory when using @tanstack/rHello, is there any way to create a base router with common procedures? like an interfaceI want all routers that use it have the state procedure (subscriptions), so I can create a common hHelp Retrieving req.url from opts in useMutation from tRPCHello, i'm trying to essentially send a magiclink email using supabase client libraries, however, i'Express tRPC NextJSI've custom expressjs server with Nextjs + im using internal package for handling OneLogin (OIDC) hoDynamic links url dependent on next headers?Hi, We're currently explore if we can use trpc on a multi tenant next.js 13 application. But we can