Back to Blog

Laravel | Facebook Instagram Lead | Import

To Import Facebook/Instagram leads into the Laravel CRM Web Application One of my client wants to get all the leads that were generated on the Facebook/Instagram campaign on their page that must be also imported or added to their CRM web portal automatically so their staff can manage it easily with other data. So, to […]

Laravel | Facebook Instagram Lead | Import

To Import Facebook/Instagram leads into the Laravel CRM Web Application

One of my client wants to get all the leads that were generated on the Facebook/Instagram campaign on their page that must be also imported or added to their CRM web portal automatically so their staff can manage it easily with other data.

So, to achieve this thing first we need to create a Business account in the Meta Business Suite if not exist.

Then we need a Facebook app in the Facebook developer portal. And for that, you must have developer access using your Facebook account, if not you have to get the developer access. Before creating the developer account I would like to suggest that you to visit the below Github repo and set up your code to read the Facebook payload for the lead form data.

Github Repo for Code Integration

Once a developer account is created, you have to create an app for business or business app.

Link To Facebook for Developers

Steps to create an app under a Business account:

 
  1. Visit the developer for Facebook from the above link
  2. Click on the "Create App" button
  3. Select the "Other" Option
  4. Then on the next screen, select the "Business" option
  5. Now fill up the app name and contact email address.
  6. And your app has been created. 
Then once you re-visit the Facebook Developers page you will see the last created app. Click on the app.
  1. On the left side, Expand "App Settings" and under that select "Basic" option
  2. You will get the "App id" and "App Secret" values for the development

Now on the same screen, You will see the "Add Product" option on the left side menu, besides the  "Products" 
Then you will see the different products, but we have to choose the "Webhook"     and click on "Setup" and then you have to choose the "Page" option as our campaign or ads will be run on the "Page" and subscribe to that.

Then you have to add the Live URL that points to your web application and where you put the code to read the lead data and verify token is the random string or encrypted string that you have added inside your code to match the "hub_verify_token" from the request.

and click on the "verify and save" button and it will send a request to your portal URL and match the verify token you will return the "hub_token" in the request and Facebook will match it with their system and add the URL as the webhook URL.

Now our code and Facebook developer account and our Facebook app have been created and set up.

Now as the owner of the Facebook account, we have to give access to our Facebook app from our Facebook account.

So you have to visit the below link:

Facebook Tool - Graph API Explorer

 
Where in the side, you will see the "Generate Access Token" button. But before that, you have to choose the app from the "Meta App" labeled dropdown that we created last so we can give access to that app and our code will work.And need to add the below permission in the "permissions":

  1. pages_show_list
  2. ads_management
  3. ads_read
  4. leads_retrieval
  5. pages_read_engagement
  6. pages_manage_metadata
  7. pages_manage_ads
Now you have to click on the "Generate Token" and it will confirm the permissions to give access to the App and then you will get the access token that you have to add inside the code.By default, this token will expire in 60 minutes.

You can check the token expiry from the link, click here and click on the token that matches your token, and click on the "Debug" button to get the full information about the token.

You can also get the long-lived token but for that you have to reasearch on that on different search engines.

 
Then you need to test the sample lead data to confirm if it works or not whenever Facebook sends the data to your portal via webhook.Link to Facebook Leads Testing Tool


You have to choose the page, and then in the below dropdown you will see your current form that ran inside the Ads Campaign and you can send the test request to the portal.
If you do not have any ads campaign run then you have to create an ad and inside that app, you have to create a form for that, you have to read the steps to create an Ads Campaign on Facebook or Meta Business from the search engines or Facebook Documentation.

And now all the setup is done and working.

Thanks for the reading.