Facebook Lead Ad to Dynamics 365 via LeadsBridge and Flow

Sean Roque, 24 October 2019

Facebook is one of the largest social media platforms that offers high view rates and precision with the target audience. Combined with Microsoft Dynamics 365, a leading cloud-based business applications platform to store and manage this information, we end up with a powerful combination for enterprise productivity.

Retrieving information from Facebook and turning that into manageable data in Dynamics 365 can be done manually.
However, when this process is automated we are benefited with:

  • Real-time data transfer

  • No human error

  • Near limitless customization with Microsoft Flow

This blog contains a set of instructions to setup automated Lead generation from Facebook Lead Advertisements, all the way to Dynamics 365.

To do this, we utilized the Facebook integration software LeadsBridge to extract information from Facebook Lead Advertisements, and the constantly evolving Microsoft Flow to manage the information and facilitate record creation in Dynamics 365. 

Lead Advertisements can be setup in a Facebook page by navigating to the Ad Center tab > Create Ad > Get More Leads

Here you are provided a standard form where you can select the different fields you want Users to fill up when completing your form.

In this same instance you can configure how you would like Facebook to project your Advertisement to users along with the payment plan.

If your intention is to explore and test an integration like ours, then it is enough to simply save the form as draft and later run some test leads. This does not require payment.

There are many different available connectors that allow automatic lead generation to various CRMs from these Lead Ad forms. To set this up, navigate to the Publishing Tools tab and click Leads Setup at the sidebar.

In our case, we setup a Webhook via LeadsBridge. Type “Webhook” and select the first instance and click Connect. This will take you to LeadsBridge Setup

Connect the appropriate Facebook account which has administrator rights to the page where your Lead Ads are

Provide permissions

Select the page and the recently created Lead Ad form.

In this section we need to click Edit to the right of Destination. Here we will enter a URL generated from Microsoft Flow, which will be handling the Lead record creation in Dynamics, after receiving information from the Facebook Lead Ad via LeadsBridge.

Create a new Flow with a trigger of When a HTTP request is received

Temporarily add any action and save this to generate the URL and paste this onto the LeadsBridge webhook setup.

Now in LeadsBridge if you navigate onwards, you will be given the option to test and publish. In your flow, click Test > I will perform the trigger. Then click Test & Publish after entering test details like below.

We need to copy the contents of the Output body from the HTTP request triggerbody. You can do this by viewing the results in your flow after testing.

Edit your flow again and click Use sample payload to generate schema under the trigger, paste the content and confirm.

Now you can reference formdata as dynamic content, which will conveniently return an array of key-value pairs. You can now access the fields from your Lead Ad form.

We did this via first initiating a variable for each field.

Then looping through the array elements of formdata via an Apply to each action, and for each iteration test the Key if it matches each variable.

You can verify what the key/s will be from the initial test result that we used as a sample payload.

Now you can set the variable with the ‘value’ and use this later when using the Dynamics 365 or CDS connector for creating the record in CRM.

Do this for all the fields being passed from your Facebook Lead Ad, in our case it is Email, Phone and Full Name.

You can separate Full Name into First and Last Name via first(split(items(‘Apply_to_each’),’ ‘)) or last(split(items(‘Apply_to_each’),’ ‘)) which will split the Full Name via the empty space character, and take the first or last element of the newly created Array.

Then you can use these variables to populate the fields in your Create a Record action in Dynamics 365 or CDS

An alternative way to create test Leads is by following this Link and select create lead. Note that you will have to delete the lead each time if you are looking to create a new one

You will find that your flow has run successfully and that the record is created in CRM.

Despite the existence of Connectors such as Zapier that offers direct connection of Facebook lead ad submissions to Dynamics 365, using LeadsBridge and Microsoft Flow has its advantages. Notably Microsoft Flow with its constant addition of new connectors, this method offers much less restriction to customization.