#ugudango_webhooks

1 messages ยท Page 1 of 1 (latest)

signal gazelleBOT
#

๐Ÿ‘‹ 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.

somber dragonBOT
#

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.

modern vapor
#

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?

digital falcon
#

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

#

?

modern vapor
#

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.

digital falcon
#

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

modern vapor
#

No, 400s are unexpected. You should put some logs in your application to figure out why it returns 400 instead of 200.

digital falcon
#

again, we process only some events

#

and the 400s are not handled

modern vapor
#

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

digital falcon
#

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

modern vapor
#

Can you share with me the code?

digital falcon
#

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?

modern vapor
#

It depends, if you are running a local webhook endpoint (i.e., through stripe listen, you should use the webhook secret generated by CLI

digital falcon
#

yeah i am using stripe listen

modern vapor
#

Ok, so are you using the correct webhook secret?

digital falcon
#

yeah, even after logging it it's correct

modern vapor
#

at which line did you get the Webhook Error: Unexpected end of JSON input error?

digital falcon
#

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

somber dragonBOT
wanton spoke
#

what's the event ID evt_xxx where that happens?

digital falcon
#

evt_1P3CtpFQ18ENc13dtOOuPyhS

#

or evt_3P3CneFQ18ENc13d0SV6sIvo

wanton spoke
#

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.

digital falcon
#

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?

wanton spoke
#

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.

digital falcon
digital falcon
#

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

digital falcon
#

@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.

lethal lintel
#

hi! I'm taking over this thread.

#

can you share a new Event ID with the issue?

digital falcon
#

hi soma, sure thing

#

evt_1P3F0gFQ18ENc13dsCz9KxTP

lethal lintel
#

thanks. can you confirm that the webhook secret you are using looks like this: whsec_...nrW6

digital falcon
#

I'm using a local listener secret right now actually ๐Ÿค”

#

from the CLI

lethal lintel
#

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?

digital falcon
#

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

lethal lintel
#

that's a common mistake. but did it solve the issue?

digital falcon
#

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

lethal lintel
#

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.

digital falcon
#

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

lethal lintel
#

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.

digital falcon
#

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?

lethal lintel
#

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

digital falcon
#

sorry had a call, but it seems the same error is happening :/ evt_1P3FiFFQ18ENc13dAH9pZnuY

#

secret ends with "nrW6"

lethal lintel
#

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.

digital falcon
#

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

lethal lintel
#

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

signal gazelleBOT
digital falcon
#

okay, i'll try that

digital falcon
#

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

coarse mauve
#

Is this a Next.js app by any chance?

digital falcon
#

yeah it is

coarse mauve
#

Are you using API Routes (Pages Router) or Route Handlers (App Router)?

digital falcon
#

App router

#

or sorry, pages router*

coarse mauve
#

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
digital falcon
#

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

coarse mauve
#

What's the evt_xxx ID?

digital falcon
#

evt_1P3GKjFQ18ENc13dpYudE2eP

coarse mauve
#

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

digital falcon
#

that line has been removed

coarse mauve
#

Can you share the actual code then you're using now then

digital falcon
coarse mauve
signal gazelleBOT