Passing data from a webhook to a 3rd external endpoint
Unanswered
Philippine Crocodile posted this in #help-forum
Philippine CrocodileOP
I am having trouble with consuming data from a webhook from a CRM. I am receiving data from the CRM webhook and then I am trying to post that data to a facebook endpoint but in production when that API function is called it shows as a GET request instead of a POST request
import type { NextApiRequest, NextApiResponse } from 'next'
const pipedrive = require('pipedrive');
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const {v, matches_filters, meta, event } = req.body
console.log({v, matches_filters, meta, event })
const url = new URL(`https://graph.facebook.com/v17.0/${process.env.FB_PIXEL_ID}/events?access_token=${process.env.FB_ACCESS_TOKEN}`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
"data": [
{
"event_name": "Lead",
"event_time": Date.now(),
"action_source": "system_generated",
"user_data": {
"lead_id": meta.id,
"client_ip_address": meta.remote_ip,
},
"custom_data": {
"lead_event_source": "Pipedrive",
"event_source": "crm",
"event": event
},
}
],
})
} )
const leadResponse = await response.json()
res.status(200).json({message: 'Done', lead: leadResponse})
}