#rbole

1 messages · Page 1 of 1 (latest)

hot edgeBOT
amber pivot
#

👋 happy to help

#

would you mind sharing your code?

elder island
#

sharing the code is difficult, but on index.js I do:
app.use((req, res, next) => {
if (req.originalUrl === '/api/rt/swhabo') {
console.log(req.originalUrl)
express.raw();
console.log(req.rawBody)
next();
} else {
express.json({limit: '3mb'});
express.urlencoded({ extended: true });
next();
}
})

#

I have to switch between JSON and the raw body

amber pivot
#

/api/rt/swhabo' is this your webhook endpoint URL?

elder island
#

yes

#

the rawBody is always undefined

amber pivot
elder island
#

ok, thanks I know that typescript example.

amber pivot
#

your code needs to be the same as the one I shared

#

e.g.

      next();
    } else {
      express.json()(req, res, next);
    }```
elder island
#

app.use((req, res, next) => {
if (req.originalUrl === '/api/rt/swhabo') {
next();
} else {
express.json({limit: '3mb'});
express.urlencoded({ extended: true });
next();
}
})

#

I think that is the same

#

and on the endpoint I do:
router.route('/swhabo', express.raw({type: 'application/json'})).post(function(req, res){
console.log('RawBody',req.body)

process.exit(0);

});

amber pivot
#

how are you testing your webhook endpoint?

#

router.route('/swhabo') isn't that route /api/swhabo?

elder island
#

I change the customer name in the stripe platform and a request is send on my endpoint

#

it's the customer.updated event

#

Maybe it's because I use the express router object !

amber pivot
#

the express router isn't the problem

#

router.route('/swhabo') isn't that route /api/swhabo?
can you please confirm?

elder island
#

the correct endpoint is /api/rt/swhabo. I use the express router to split the endpoints to different folder and files. That's why the route /swhabo is correct. I receive the request on that endpoint in the JSON format as well, only the raw body is in this case undefined.

#

I express 4.17

amber pivot
#

req.body is undefined?

elder island
#

yes

amber pivot
#

what's your account ID?

elder island
#

acct_1JIrRcKxrILBeGDx

amber pivot
#

ok let's try something

#

and see whether this code also is getting you an empty req.body?

elder island
#

ok, I think that is no stripe problem, the problem is me, the app.use function seems the problem. let's close this thread.

amber pivot
elder island
#

yes that is working, but without signing.

#

now I would like to add the signing,
event = stripe.webhooks.constructEvent(request.body, sig, endpointSecret)

amber pivot
#

ok

#

it's better to build this incrementally

#

with the docs I'm providing

elder island
#

Error: Webhook Error: No webhook payload was provided.

amber pivot
elder island
#

I have to use my own one.

#

the problem is, that expressjs does not give my the raw body with express.raw()

#

it gives we undefined

amber pivot
hot edgeBOT