https://supabase.com/ logo
Hi all, with a supabase function hook, how would y...
# help
h
Hi all, with a supabase function hook, how would you send record data with the httprequest? eg:
Copy code
{
  "record": {
    "email": "asd@gmail.com",
    "id": "16c34376-54ff-49dc-a374-f32b063ef5da"
  }
}
n
Hello @HEAVYPOLY! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
g
function hooks send the entire row in a predefined format to the http endpoint. You can't change the format and info from the row.
If you need to call and endpoint with specific data then you need to have a trigger function and use the http extension.
h
ok, thanks for the info, I was able to get the row info over to the endpoint, I think the problem was a json typo.
Works now! :
Copy code
const handler = async(req, res) => {
    const stripe = initStripe(process.env.STRIPE_SECRET);
    
    const customer = await stripe.customers.create({
        name: req.body.record.id,
        email: req.body.record.email
    });
    // res.send({ message: `stripe customer created: ${JSON.stringify(req.body.record)}` });
    res.send({ message: `stripe customer created: ${customer.id} ${req.body.record.email} ${req.body.record.id}` });
Now this second part (await supabase) is not working, does anything look wrong here?
Copy code
await supabase
        .from('user_data')
        .update({ stripe_customer: customer.id})
        .eq('id', req.body.record.id);

};

export default handler;
hmm, it seems that the await supabase only works in the customer email and customer id match, is this normal? I thought eq('id', req.body.record.id); means only id needs to match