Adding HubSpot Leads to Dynamics 365 CE with Power Automate

I was recently asked to about a solution to move leads from HubSpot to our Dynamics Dataverse as an alternative to HubSpot's fine sync product, PieSync. Using a combination of HubSpot's workflows, additional HubSpot API calls, and the HTTP request is received Power Automate trigger, you can transform the lead fields as necessary for your Dataverse Lead entity.

To start, you will need to create a HubSpot developer account. Once that account is created, have your HubSpot admin add the account to your HubSpot company. To start building the HubSpot workflow, you will need to create a new Power Automate with the When a HTTP request is received trigger. Add any simple action (like a Compose) so that you can save the flow and get the HTTP POST URL. Now, go to HubSpot Workflows and create a new workflow with following trigger and trigger webhook action:

brave_CPNylG7byW.png

You can now test with a test lead to enroll it in the workflow and make sure that the Power Automate run is being triggered. Remove the temporary action after the trigger and add a Parse JSON action with this schema. If you would like to get the HubSpot form UTM, you can see if a form page URL is attached to the lead:

brave_hQ2wFEsY6F.png

body('Parse_New_HubSpot_Lead_JSON')?['form-submissions'][0]?['page-url']

After removing the rest of the page URL so you have only the UTM, you can then match it to your campaigns entity (or equivalent):

image.png

It took me a while to realize while comparing this trigger response to the response of Contact Profile API that the trigger response does not have all the lead fields, specifically for my case the HubSpot owner to match in Dynamics.

body('Parse_Full_Contact_Fields')?['properties']?['hubspot_owner_id']?['value']

Send a HTTP Get to Owners so that you can match the systemuser email:

image.png

image.png

You now have more than enough fields to match to an existing Dataverse lead or create a new Dataverse record:

image.png