- Why there is no plug and play connector
- The two routes that work
- Step by step: building the custom integration
- The MySQL table structure that holds up
- Why the webhook alone isn't enough
- What this costs to build
- What moves the needle after the data lands
- When to build it yourself versus bring someone in
- Frequently asked questions
- Useful references
There is no native button that pipes Facebook Lead Ads into MySQL, so you either pay a tool like Zapier or Make to bridge the two, or you build a webhook that catches the leadgen event, calls the Graph API for the full lead data, and writes it straight into a table. For the custom route, Meta's guide lists the permissions as ads_management, leads_retrieval, pages_show_list, pages_read_engagement and pages_manage_ads, plus pages_manage_metadata for the webhook. I have built both versions for clients, and I will show you the actual table structure, the exact steps, and the detail about webhooks quietly failing.
Why there is no plug and play connector
Meta's guide to retrieving leads describes the ways out: real-time webhooks, reading leads through the Graph API by form or by ad, a CSV download, and a list of CRM integrations. The forms live natively in the Facebook and Instagram apps so nobody has to leave to fill in a form, which is great for conversion rates and a bit of a headache for anyone who wants that data somewhere else fast. Meta gives you a Graph API and a webhooks system, not a database connector. That gap is where every "integrate Facebook Lead Ads" guide either sends you to a paid tool or leaves you stuck on page one.
I run into this constantly with clients who assume, reasonably, that because Facebook lets you export leads as a CSV from Ads Manager, there must be an equally simple live feed. There isn't. The CSV export is manual and it lags. If you want leads landing in a database the moment someone submits a form, you need either a middleware tool subscribed to the webhook, or your own script doing the same job.
The CSV route does have an API form, useful for a one-off backfill: /ads/lead_gen/export_csv/ with the form's id, type=form, and from_date and to_date as Unix timestamps. Don't be surprised when some rows come back without an ad ID. Meta's guide gives the reasons: the lead came in organically, it was submitted from an ad preview, or the person pulling the data doesn't have advertiser access to the ad.
The two routes that work
Route one: a middleware tool (fastest to set up)
Zapier, Make.com and n8n all offer a Facebook Lead Ads trigger that fires when someone submits a form. From there you add a MySQL step, and each tool's own integration page names it: Zapier pairs the New Lead trigger with MySQL's New Row action, Make pairs New Lead with Insert row into a table, and n8n's MySQL node has an Insert operation. All three connect to your database from their side, so it has to be reachable from the internet, and your host may need to allow the tool's connections before the first row lands.
- Zapier: the Facebook Lead Ads New Lead trigger, which Zapier lists as instant, plus the MySQL New Row action. The price depends on the plan and how many tasks you run, and it changes, so check Zapier's current pricing before you commit.
- Make.com: the New Lead trigger plus the MySQL module Insert row into a table, and the visual flow is easier to debug when a lead goes missing. Check its current plans for the number of operations you expect.
- n8n: its Facebook Lead Ads Trigger node fires on a new lead and its MySQL node has an Insert operation. You can self-host it free under n8n's Sustainable Use License, which allows use for your own internal business purposes (fine for wiring up your own forms, not for reselling it as a service), on your own server or on a paid cloud plan if you don't want to host it yourself; check current pricing.
This route takes an afternoon. It's the right call for a small business running one or two campaigns and fewer than a few hundred leads a month. It's the wrong call once you're past that, because you start hitting per-task limits and the monthly bill for a "simple" data pipe becomes an odd thing to be paying for.
There's a third route worth checking before either: Meta's guide to retrieving leads points to a list of available CRM integrations. If your leads are heading for a CRM anyway and MySQL was only ever a stopping point, start there.
Route two: a custom webhook into MySQL (the one I build for clients)
This is more setup work up front but it's free to run and you own it completely. It's also the version that survives when a client's lead volume goes from 20 a month to 400 a month, which happens more often than people expect once a campaign starts working.
Step by step: building the custom integration
- Create a Facebook App. Go to developers.facebook.com, create a new app under the "Business" type, and note your App ID and App Secret.
- Add the Webhooks product to the app and subscribe to the "leadgen" field under the Page object. Facebook will ask you to verify a callback URL with a token you set yourself, so you need your endpoint live before you can finish this step. Meta's Page webhooks guide adds two conditions that catch people out: the app has to be installed on the Page, and the Page must not have switched off the app platform. Miss either and nothing arrives.
- Get a long-lived Page access token for the Page that owns the forms, and keep it out of your code, in an environment variable or config file the web server can't serve. A short-lived token works in testing and then expires, which looks exactly like a broken webhook. If the Page uses Leads Access Manager, the user or app also has to be given access to leads there.
- Request the permissions. To read all lead and ad data, Meta's guide to retrieving leads lists ads_management, leads_retrieval, pages_show_list, pages_read_engagement and pages_manage_ads, and webhooks also need pages_manage_metadata. leads_retrieval is the one you can't do without. Submit for App Review if you're not just using this on your own page under your own admin account. That guide doesn't give a review time, and I've had it bounced on the first submission twice for vague use-case descriptions, so write the use case out plainly: "Retrieve lead data from Facebook Lead Ads forms and store it in our CRM/database for follow-up."
- Build the webhook receiver. A simple PHP endpoint works fine:
<?php
const GRAPH_VERSION = 'v27.0'; // the version in Meta's guide today; update it in one place
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if ($_GET['hub_verify_token'] === 'your_secret_token') {
echo $_GET['hub_challenge'];
exit;
}
}
$data = json_decode(file_get_contents('php://input'), true);
$value = $data['entry'][0]['changes'][0]['value'];
$leadgen_id = $value['leadgen_id'];
$access_token = getenv('FB_PAGE_TOKEN');
$url = "https://graph.facebook.com/" . GRAPH_VERSION . "/{$leadgen_id}?access_token={$access_token}";
$lead = json_decode(file_get_contents($url), true);
// field_data is a list of questions: each has a name and a list of values
$fields = [];
foreach ($lead['field_data'] as $f) {
$fields[$f['name']] = $f['values'][0] ?? null;
}
$pdo = new PDO('mysql:host=localhost;dbname=leads;charset=utf8mb4', 'db_user', 'db_pass');
$stmt = $pdo->prepare('INSERT IGNORE INTO fb_leads
(lead_id, form_id, full_name, email, raw_payload, created_time)
VALUES (?, ?, ?, ?, ?, ?)');
$stmt->execute([
$leadgen_id,
$value['form_id'],
$fields['full_name'] ?? null,
$fields['email'] ?? null, // add the other fields your own form asks for
json_encode($lead),
date('Y-m-d H:i:s', strtotime($lead['created_time'])),
]);
?>
One gap in that sample: it accepts any POST from anyone. Meta's webhooks guide says every notification is signed with a SHA256 signature made from the payload and your app's App Secret, sent in the X-Hub-Signature-256 header after the prefix sha256=, and that you don't have to validate it but you should. In PHP that means reading the raw body once, checking it, and only then decoding it:
$body = file_get_contents('php://input');
$expected = 'sha256=' . hash_hmac('sha256', $body, getenv('FB_APP_SECRET'));
if (!hash_equals($expected, $_SERVER['HTTP_X_HUB_SIGNATURE_256'] ?? '')) {
http_response_code(403);
exit;
}
$data = json_decode($body, true);
Swap that in for the json_decode line above. The same guide says your endpoint should answer every notification with 200 OK, so keep slow work such as the Graph API call fast or queue it.
The webhook tells you a lead exists, not what the person typed. Going by Meta's guide to retrieving leads, the change that reaches your endpoint looks like this:
{
"object": "page",
"entry": [{
"changes": [{
"field": "leadgen",
"value": {
"leadgen_id": "...",
"page_id": "...",
"form_id": "...",
"adgroup_id": "...",
"ad_id": "...",
"created_time": "..."
}
}]
}]
}
The answers come from the Graph API call on the leadgen_id. The response holds created_time, id, ad_id, form_id and a field_data array, where each question is a name with a list of values, for example full_name and email. The loop in the code above turns that array into columns. This two-step handshake trips up almost everyone the first time; it doesn't arrive in one hit.
Write to MySQL using a prepared statement, as above, and make lead_id a unique key so a duplicate webhook fire (which happens) doesn't create two rows. INSERT IGNORE skips the duplicate quietly; use ON DUPLICATE KEY UPDATE instead if you want a later copy to refresh the row.
The MySQL table structure that holds up
Here's the table I use as a starting point for most clients, adjusted for their form fields:
CREATE TABLE fb_leads ( id INT AUTO_INCREMENT PRIMARY KEY, lead_id VARCHAR(50) NOT NULL UNIQUE, form_id VARCHAR(50), campaign_id VARCHAR(50), full_name VARCHAR(150), email VARCHAR(150), phone VARCHAR(30), raw_payload TEXT, created_time DATETIME, processed TINYINT DEFAULT 0, inserted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
Two columns are doing more work than people expect. raw_payload stores the full JSON response from Facebook, even the fields you don't have named columns for, because custom questions get added to forms constantly and you don't want to lose data because your schema didn't have a column for "preferred callback time" that someone added to the form last Tuesday. And processed is there so your sales team's CRM sync or notification script can flag a row as handled without deleting it, which matters when someone inevitably asks "did we get a lead from that campaign on the 14th" three weeks later.
I've also covered sending Meta conversion leads data to a CRM without the technical headache. Planning a campaign there? Here are Facebook advertising rates in the Philippines from real campaigns.
Why the webhook alone isn't enough
Meta's guide to retrieving leads says real-time pings arrive with a delay of up to a few minutes, and it doesn't promise that every lead will produce one. Treat the webhook as fast, not complete. In my experience running this for a boiler and heating client in the Midlands, sending around 35 to 50 leads a day at peak, we found roughly 2 to 3 percent of leads never triggered a webhook at all. They existed in Ads Manager but never showed up in our database.
The fix is a cron job that reads leads straight from each form with Meta's bulk read call, GET /<FORM_ID>/leads with fields=created_time,id,ad_id,form_id,field_data, follows the paging cursors to the end, and inserts any that aren't already in the table (this is exactly why lead_id needs to be unique). Meta gives the rate limit as 200 multiplied by 24 multiplied by the number of leads created in the past 90 days for the Page, so a Page with 50 leads in that window gets 240,000 calls a day, and a poll every 15 minutes is 96 calls per form. It's not glamorous, it's a short scheduled script, but it's the difference between "we think we're getting all our leads" and knowing you are.
What this costs to build
For a custom build like the one above: 8 to 15 hours of developer time, depending on how many form variants and campaigns you're pulling from. At UK freelance rates of £50 to £120 an hour, that's roughly £400 to £1,800 as a one-off cost, versus an ongoing £20 to £70 a month for a middleware tool that starts to strain once you're past a few hundred leads a month. For most small businesses under that volume, paying monthly for Zapier or Make is the cheaper and less stressful option, and I tell clients this even when it means less billable work for the developer side of things.
Want AI doing the heavy lifting in your marketing?
I build the systems that handle the boring 80 percent, so you get your week back. Done properly, with the human kept in.
What moves the needle after the data lands
Here's the part most guides on this topic skip entirely. Getting Facebook Lead Ads into MySQL is a plumbing problem, and plumbing problems are satisfying to solve because they're finite and you know when you're done. But I've watched more than one client build a solid integration, get leads landing in the database within seconds of submission, and then still lose the deal because nobody looked at the table for six hours.
The Facebook lead form format makes this worse, not better. Because the form is pre-filled with the person's Facebook profile name, email and phone number, a huge share of these leads are low-intent taps, someone scrolling and hitting submit out of curiosity rather than genuine buying interest. That makes speed matter more here than with a lead who filled in a long form on your own site, so decide before the campaign goes live who gets the alert, by text or call task, and what they say in the first message.
So the database is step one, not the finish line. The moment a row is inserted, something needs to fire an SMS or a call task to a real person, not sit in a table waiting for someone to open a report. If you're building this integration to feed a CRM or a follow-up system rather than just archive data, that's the far more valuable half of the project, and it's the half people skip because it's harder than a webhook.
When to build it yourself versus bring someone in
If you're comfortable with PHP or Node and you've got one page, one or two forms, and a few hundred leads a month, the custom route above is a weekend project. If you're running Lead Ads across multiple pages, multiple business units, or you need this wired into a CRM with proper deduplication and lead scoring rather than a flat table, it's worth getting someone who's built this exact pipe before rather than debugging App Review rejections and silent webhook failures on your own time. That's a fair chunk of what I do when clients bring me in for AI and marketing systems work, joining up the ad platform, the database, and the follow-up automation so leads don't just get stored, they get worked.
If the ads behind these forms are billing you more often than you expected, see facebook keeps charging me for ads.
For the rest of the series, see the Facebook Help: 80 Guides to Pages, Groups, Ads, Stories and Fixes.
Frequently asked questions
Can I connect Facebook Lead Ads to MySQL without any coding?
Yes. Zapier connects the Facebook Lead Ads New Lead trigger to MySQL's New Row action, and Make connects New Lead to Insert row into a table, with no code. Your database has to accept connections from the tool, and the monthly cost rises with the number of leads you push through.
What permissions does a Facebook Lead Ads integration need?
For all lead and ad data, Meta lists ads_management, leads_retrieval, pages_show_list, pages_read_engagement and pages_manage_ads, plus pages_manage_metadata if you use webhooks. The webhook itself carries the leadgen_id, page_id, form_id, ad_id and created_time, and you fetch the answers with a separate Graph API call on that leadgen_id.
Do Facebook Lead Ads webhooks ever fail to fire?
Yes. In client accounts I've managed, roughly 2 to 3 percent of leads never triggered a webhook event despite existing in Ads Manager, which is why a scheduled polling script as a backup matters more than most setup guides suggest.
How fast do I need to follow up with a Facebook Lead Ads lead?
As fast as you can staff it. Because Lead Ads forms are pre-filled, many submissions come from low-intent taps that go cold quickly, so an alert to a named person the moment the row lands beats any report someone checks later.
How quickly do Lead Ads webhook pings arrive?
Meta says real-time pings arrive with a delay of up to a few minutes. If a lead is missing after that, the backup poll on the form's leads will pick it up.
Useful references
If you run a hosting company and want to write for the site about setups like this one, see the hosting write for us page.
Run a business, a brand or a blog? I feature tools, products and expert guest posts for an audience of 15,000. See how it works


