If you chose Lead Ads Form as the communication channel, you can access Vehicles leads generated on Marketplace in different ways.
Depending on the size of your catalog, you can retrieve leads by these methods:
For catalogs larger than 100-200 listings, we strongly suggest to automate your leads retrieval flow using our APIs.
Learn more about how to Retrieve Leads, Marketing API.
As a Page admin, you can view and download leads from Marketplace (at the top of your page, you should see Publishing Tools).
To learn how to connect your CRM system to your Facebook page, see Connect Your CRM System to Facebook, Business Help Center.
Learn how you can set up your leads to be instantly updated into your CRM system.
Lead ads make forms simple for people and more valuable for businesses. Set up a Lead ad where prospective customers can sign up for what you're offering, and you'll get accurate contact information to follow up.
Learn more about how you can retrieve leads by setting up a webhook.
Before you begin your setup, ensure that you meet the following requirements:
Ensure that your Dealer pages have Admin access with the Manage Page role.
Permissions required:
pages_manage_ads
pages_manage_metadata
pages_read_engagement
leads_retrieval
business_management
(to request dealers' page permissions)ads_management
(to retrieve additional listing detail other than just the vehicle_id
)The App Review process can take up to 1-2 weeks including business verification. Please read this guide and prepare required documents in advance.
To receive webhook events from the Facebook Platform, your code must be hosted on a public HTTP server that meets has the following:
GET
and POST
requestsThe Facebook Platform supports versioning and each version is guaranteed to operate for at least 2 years. A version is no longer usable 2 years after the date that the subsequent version is released. We highly recommend developers to use the most recent API version.
Lead generation is language-agnostic. The examples in this guide are in PHP, but you can write your webhook in a preferred server-side language.
Before you begin, make sure your server meets all of the requirements listed above.
hub.challenge
and hub.verify_token
.$token
value. This is simply used to verify your endpoint.<?php $token = "<YOUR_VERIFY_TOKEN>"; $challenge = $_REQUEST['hub.challenge']; $verify_token = $_REQUEST['hub.verify_token']; if ($verify_token === $token) { echo $challenge; } ?>
https://yourdomain.com/facebook/webhook_verify.php
. Learn how to create an endpoint. leadgen
field and click Subscribe.leadgen
), click Test to test your webhooks. $request_body = file_get_contents('php://input')
business_management
manage_pages
leads_retrieval
BUSINESS_ID
of your system user with the following request:curl -X GET -G \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/{BUSINESS_ID}/system_users
GET /{BUSINESS_ID}/system_users HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get(
'/{BUSINESS_ID}/system_users',
'{access-token}'
);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
/* make the API call */
FB.api(
"/{BUSINESS_ID}/system_users",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
BUSINESS_ID
of your system user, you can run the following code to give the system user access to the page (PAGE_ID
):curl -X POST \
-F 'user={BUSINESS_SCOPED_USER_ID}' \
-F 'tasks=[
"CREATE_CONTENT",
"MODERATE",
"ADVERTISE",
"ANALYZE",
"MANAGE"
]' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/{PAGE_ID}/assigned_users
POST /{PAGE_ID}/assigned_users HTTP/1.1
Host: graph.facebook.com
user=%7BBUSINESS_SCOPED_USER_ID%7D&tasks%5B0%5D=CREATE_CONTENT&tasks%5B1%5D=MODERATE&tasks%5B2%5D=ADVERTISE&tasks%5B3%5D=ANALYZE&tasks%5B4%5D=MANAGE
/* PHP SDK v5.0.0 */
/* make the API call */
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->post(
'/{PAGE_ID}/assigned_users',
array (
'user' => '{BUSINESS_SCOPED_USER_ID}',
'tasks' =>
array (
0 => 'CREATE_CONTENT',
1 => 'MODERATE',
2 => 'ADVERTISE',
3 => 'ANALYZE',
4 => 'MANAGE',
),
),
'{access-token}'
);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
/* make the API call */
FB.api(
"/{PAGE_ID}/assigned_users",
"POST",
{
"user": "{BUSINESS_SCOPED_USER_ID}",
"tasks": [
"CREATE_CONTENT",
"MODERATE",
"ADVERTISE",
"ANALYZE",
"MANAGE"
]
},
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
By default, you will get all page access tokens assigned to the system admin.
Use the Business Manager System User token you saved before as access_token
.
curl -X GET -G \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/me/accounts
GET /me/accounts HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get(
'/me/accounts',
'{access-token}'
);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
/* make the API call */
FB.api(
"/me/accounts",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
Sample Response:
{ "data": [ { "access_token": "...", "category": "Automotive Dealership", "category_list": [ { "id": "123688294262123", "name": "Automotive Dealership" } ], "name": "Test dealer page", "id": "132337234248833", "tasks": [ "ANALYZE", "ADVERTISE", "MODERATE", "CREATE_CONTENT", "MANAGE" ] }, ] }
The access tokens in the response are long-lived page tokens that have no expiration date. You can hard-code the date in simple RTU integrations to get leads data.
Using the page access tokens, your app must subscribe pages so that Facebook can send webhooks to your webserver.
curl -X POST \
-F 'subscribed_fields="leadgen"' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/{PAGE_ID}/subscribed_apps
POST /{PAGE_ID}/subscribed_apps HTTP/1.1
Host: graph.facebook.com
subscribed_fields=leadgen
/* PHP SDK v5.0.0 */
/* make the API call */
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->post(
'/{PAGE_ID}/subscribed_apps',
array (
'subscribed_fields' => 'leadgen',
),
'{access-token}'
);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
/* make the API call */
FB.api(
"/{PAGE_ID}/subscribed_apps",
"POST",
{
"subscribed_fields": "leadgen"
},
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
If you are using Graph API v3.2 or higher, add the following parameter in the POST
request (read more):
subscribed_fields=leadgen
The Facebook app associated with your token is authenticated for page updates; you do not need to specify an app ID.
On success, real-time pings occur on events with a delay of up to a few minutes. If you need help with the integration, see Troubleshooting Real-time Integrations.
Test your webhook by sending leads from your Marketplace listings.
If you do not receive leads in your webhook:
The payload sent to the webhook has the following structure:
{ "changes": [{ "field": "leadgen", "value": { "created_time": 1540269154, "page_id": "1935718636547237", "form_id": "2217161425198865", "leadgen_id": "2219139835001024" } }], "id": "1935718636547237", "time": 1540269155 }
Use leadgen_id
to retrieve data associated with the lead.
Leads are available for 90 days. If you receive a non-existent lead response, the lead has been modified by the user, and has a new ID. You will be notified of the new lead ID.
Use the page access token of the page associated with the lead:
curl -X GET -G \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/{LEAD_ID}
GET /{LEAD_ID} HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get(
'/{LEAD_ID}',
'{access-token}'
);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
/* make the API call */
FB.api(
"/{LEAD_ID}",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
...to get the following response:
{ "created_time": "2018-10-23T04:32:34+0000", "id": "2219139835001024", "field_data": [{ "name": "email", "values": [ "joe@fbtest.com" ] }, { "name": "phone_number", "values": [ "12345678" ] }, { "name": "full_name", "values": [ "Joe" ] } ], "retailer_item_id": "Vehicle_id_4" }
In Business Manager, ensure that the system user who owns the access token is an admin of the catalog.
You can add vehicle
parameter in the request (see supported Vehicles fields).
curl -X GET -G \
-d 'fields="id,field_data,vehicle{id,vin,vehicle_registration_plate,title,price,address,mileage}"' \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/{LEAD_ID}
GET /{LEAD_ID}?fields=id%2Cfield_data%2Cvehicle%7Bid%2Cvin%2Cvehicle_registration_plate%2Ctitle%2Cprice%2Caddress%2Cmileage%7D HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get(
'/{LEAD_ID}?fields=id%2Cfield_data%2Cvehicle%7Bid%2Cvin%2Cvehicle_registration_plate%2Ctitle%2Cprice%2Caddress%2Cmileage%7D',
'{access-token}'
);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
/* make the API call */
FB.api(
"/{LEAD_ID}",
{
"fields": "id,field_data,vehicle{id,vin,vehicle_registration_plate,title,price,address,mileage}"
},
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
...to get the following response:
{ "id": "2219139835001024", "field_data": [{ "name": "email", "values": [ "joe@fbtest.com" ] }, { "name": "phone_number", "values": [ "12345678" ] }, { "name": "full_name", "values": [ "Joe" ] } ], "vehicle": { "id": "2561003667307302", "vin": "TEST1234453254321", "title": "Title1", "price": "$1,500.00", "mileage": { "value": 1000, "unit": "MILES" }, "address": { "city": "Menlo Park", "country": "US", "latitude": 37.4435997, "longitude": -122.1615219, "postal_code": "94025", "region": "Menlo Park, CA", "street_address": "1234 Example St" } } }
To use this option, you need an the catalog_management
permission.
You can also retrieve all leads you received by using {FORM_ID}
, which can be found using the Page Leadgen Forms API:
curl -X GET -G \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/{FORM_ID}/leads
GET /{FORM_ID}/leads HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get(
'/{FORM_ID}/leads',
'{access-token}'
);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
/* make the API call */
FB.api(
"/{FORM_ID}/leads",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
To delete a lead, you need to use a user token, not a page token. You can only delete leads that you own (for example, test).
curl -X DELETE -G \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/{LEAD_ID}
DELETE /{LEAD_ID} HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->delete(
'/{LEAD_ID}',
array (),
'{access-token}'
);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
/* make the API call */
FB.api(
"/{LEAD_ID}",
"DELETE",
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
Learn how to delete a UserLeadGenInfo by making a DELETE
request to /{user_lead_gen_info_id}
.