#ColonelBudinca

1 messages ยท Page 1 of 1 (latest)

cobalt kilnBOT
potent star
#

๐Ÿ‘‹ happy to help

stuck elm
#

hi

#

I am hosting a netlify function for the stripe webhook so i can not use express to get the raw body necesary for stripeAPI.webhooks.constructEvent

#

Before that i was using express server and it worked but i had to give up the server because it was hosted on heroku that now in not free anymore

potent star
#

instead of using body, you need to use rawBody

stuck elm
#

i know

#

But i dont know how to get it

potent star
#

no I meant in the request deconstructor

#

({ path, httpMethod, headers, queryStringParameters, rawBody }) {

#

you also need the response parameter

stuck elm
#

i had it but i was not using that so i removed it

potent star
#

so your code should be like

exports.handler = async function ({ path, httpMethod, headers, queryStringParameters, rawBody }, res) {

#

it's necessary to respond back with a status 200 so Stripe would know that you properly received the webhook event and wouldn't try to resend it to you later

stuck elm
#
return {
          statusCode: 200,
          headers: {
            "Content-Type": "application/json",
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "*",
            "Access-Control-Allow-Headers": "*",
          },
          body: JSON.stringify({
            path,
            httpMethod,
            queryStringParameters,
            headers,
            body: JSON.stringify({ message: "YES" }),
          }),
        };

like this?

#

i got the same error using the rawBody

#

it is always 200 but i am getting that error because of the rawbody

potent star
#

I'm taking a look

stuck elm
#

OK. i see the problem . i can not do this {rawBody} = event
i tried to send the rawbody to see if it exists and it doesnt

} catch(error){
      return {
        statusCode: 200,
        headers: {
          "Content-Type": "application/json",
          "Access-Control-Allow-Origin": "*",
          "Access-Control-Allow-Methods": "*",
          "Access-Control-Allow-Headers": "*",
        },
        body: JSON.stringify({
          path,
          httpMethod,
          queryStringParameters,
          headers,
          // something: JSON.stringify(body),
          rawBody : rawBody,
          body: JSON.stringify({error: `webhook error ${error.message}` }),
        }),
      };
#

I need to get the rawBody in other way than destructuring it from the event

potent star
#

I'm not familiar with netlify but looking into their docs

stuck elm
#

thank you

potent star
#

please give me a moment

potent star
#

would you mind taking a quick look?