#ugudango_webhooks
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1226775314223599667
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- ugudango_webhooks, 2 days ago, 40 messages
Hi there, your endpoint returned an message that says "Webhook Error: Unexpected end of JSON input"
Have you checked your backend log to see if it contains any useful information to troubleshoot?
hey there, yeah my bad it seems I sent the wrong event, but I'm currently using the generateTestHeaderString method so the signature is techically okay
when I act upon webhooks through development using the CLI listener, should my webhook listener in the dashboard pick up on that?
i dont want to mess around in prod atm
?
Did you configure the webhook endpoint to listen to the same type of event?
Do you have the event ID?
You can configure a webhook endpoint in test mode, so you can conduct tests that are seperate from the live mode.
i'll try to recreate the issue
hmm it seems i'm still seeing Webhook Error: Unexpected end of JSON input
i'll try to look into this
can we leave this ticket open or does it automatically close?
i see no errors in my logs ๐
honestly I haven't got a clue what's happening, the app is working as if the webhooks are passing correctly but i still get the Webhook Error: Unexpected end of JSON input error
and I'm getting 200s, the 400s are expected since we're listening to all events but only handle a few
logs
No, 400s are unexpected. You should put some logs in your application to figure out why it returns 400 instead of 200.
You shouldn't do that. If you always return non-200 response to Stripe for a period of time, your endpoint will be disabled.
You should still return 200 even if you don't process events
oh i didn't know
thanks, let me try to adjust this
okay, I adjusted the code and now we're getting 200s
but there's still a problem with the response, Webhook Error: Unexpected end of JSON input
however i found something interesting
I'm printing out the request body
but it's undefined
however the events are still processed haha
the buffer seems to be okay, it's getting processed
Can you share with me the code?
sure thing
i tried to use the github next-node example and the same thing happens
dumb question, the webhook signing secret should be the one provided in the CLI or the one in stripe dashboard?
It depends, if you are running a local webhook endpoint (i.e., through stripe listen, you should use the webhook secret generated by CLI
yeah i am using stripe listen
Ok, so are you using the correct webhook secret?
yeah, even after logging it it's correct
at which line did you get the Webhook Error: Unexpected end of JSON input error?
well the issue is, I'm getting this only in the dashboard.. i don't get this in the backend logs nor do I send back errors like this
what's the event ID evt_xxx where that happens?
the response is served by something called "Google Frontend", maybe something in your production deployment of the app intercepts/does something with the incoming HTTP request of the webhook before your application sees it.
got it, currently I don't have access to that but I'll notify my cofounder
there's 1 thing however, we recently migrated Stripe accounts, and previously we had no trouble with webhooks, with the code I sent previously. What did change is the API version, since we used the 2020 version, now we use the newest one. I'm speculating this could also be an issue/cause?
could be but hard to say . None of the specific errors you're mentioning(signing error, whatever that end-of-JSON-input error is caused by) are related to API version changes though, I would say.
hmm okay, I'll take a look into this, even after using the code from https://github.com/stripe/stripe-node/blob/master/examples/webhook-signing/nextjs/pages/api/webhooks.ts I get the same error so there's high likelihood that the issue is not in the code
i got access to the google frontend platform, will check now
okay, I believe i know what's happening
I need to update my production handler
give me 10 minutes
@wanton spoke okay we're back to the signature problem
Error message: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?
If a webhook request is being forwarded by a third-party tool, ensure that the exact request body, including JSON formatting and new line style, is preserved.
thanks. can you confirm that the webhook secret you are using looks like this: whsec_...nrW6
oh, I assumed you were testing the real webhook endpoing, sorry.
can you triple check that the secret you are using in the code is the same one displayed in the Stripe CLI?
no worries, let me triple check
oh you were right to suggest to triple check as this git branch didn't have the cli secret haha
that's a common mistake. but did it solve the issue?
sadly it seems that it didn't.. here's the newest event ID: evt_1P3FGuFQ18ENc13dm0JY18kc
I'm getting 200s in the CLI, no errors in my logs, but in the dashboard it's a different story
if you want the dashboard events to work, then it means you are using the dashboard webhook endpoint, which has a different webhook secret that the CLI.
so is there a way to test out the development webhooks?
i've heard that if we want to work with webhooks in development, CLI is our only option
yes use the CLI for your tests. and once it works well, switch to a real webhook endpoint in test mode. finally switch to live mode once you are ready to accept live paymnets.
oh i get it, thanks!
let me try it out
i'll use the real webhook in test mode now
the CLI listener can be closed now correct?
i'll use the real webhook in test mode now
great! make sure you use the correct webhook secret that can be found in the Stripe dashboard
the CLI listener can be closed now correct?
correct
sorry had a call, but it seems the same error is happening :/ evt_1P3FiFFQ18ENc13dAH9pZnuY
secret ends with "nrW6"
if the webhook secret if correct, then another common issue for signature verification is this:
the payload you pass in the constructEvent function is not the raw payload. so you need to ensure that you get the raw body of the HTTP request that Stripe sent you, without any interference by your code or framework in the middle.
the thing is that we had no problems with this before changing our stripe account.. the setup was the same, route was the same and it was working
so I'm not sure what's the issue
to debug this you'll need to add logging to every value you pass to constructEvent (the payload, the secret, and the signature header) and then we can try to have a look at what part is wrong
okay, i'll try that
Webhook secret: whsec_LL1EDWbQrYcjFOurIyTHec6al5ZAnrW6 Signature: t=1712574774,v1=1330bd2537550ddf84d0083ca25b84aa9754ee9cf00b0c7da5fb68ee115190b9,v0=e83b8421ce0ca1af3354cdb096a8d8ae8d9503c55b604512a420edbbb3e7ec76 Buffer: <Buffer 7b 0a 20 20 22 69 64 22 3a 20 22 65 76 74 5f 33 50 33 47 38 37 46 51 31 38 45 4e 63 31 33 64 31 44 52 54 62 65 64 35 22 2c 0a 20 20 22 6f 62 6a 65 63 ... 3526 more bytes>
Error message: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?
If a webhook request is being forwarded by a third-party tool, ensure that the exact request body, including JSON formatting and new line style, is preserved.
Learn more about webhook signing and explore webhook integration examples for various frameworks at https://github.com/stripe/stripe-node#webhook-signing
Is this a Next.js app by any chance?
yeah it is
Are you using API Routes (Pages Router) or Route Handlers (App Router)?
In your buffer function, can you make this change please:
const chunks = [];
for await (const chunk of readable) {
chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk);
}
return chunks
sure, i actually think we had something like this at some point
same thing :/
Webhook secret: whsec_LL1EDWbQrYcjFOurIyTHec6al5ZAnrW6 Signature: t=1712575553,v1=bd3d7bf8fdd57fe3639b898d77a8b5d9ba843bc97076099342ee68b252c52033,v0=e32d6e0560e443ce46d5765c2ca0c8042667c3ed47259ccde4d67cf17ee15ac1 Buffer: <Buffer 7b 0a 20 20 22 69 64 22 3a 20 22 65 76 74 5f 31 50 33 47 4b 6a 46 51 31 38 45 4e 63 31 33 64 70 59 75 64 45 32 65 50 22 2c 0a 20 20 22 6f 62 6a 65 63 ... 2890 more bytes>
Error message: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?
If a webhook request is being forwarded by a third-party tool, ensure that the exact request body, including JSON formatting and new line style, is preserved.
Learn more about webhook signing and explore webhook integration examples for various frameworks at https://github.com/stripe/stripe-node#webhook-signing
What's the evt_xxx ID?
evt_1P3GKjFQ18ENc13dpYudE2eP
Wait, this log line is probably the issue:
console.log('Webhook received', req);
You can't log out the req object like that as it will malform it
that line has been removed
Can you share the actual code then you're using now then
Hmm, honestly I don't know. I have very similar (identical?) code here that works fine