Facebook leads in erpnext

The time required for something like this depends entirely on how familiar you already are with the platforms involved. If you have a good grip on the Facebook API and how to build Frappe endpoints, it’s an afternoon’s project to get something usable up and running. If you don’t, the sky is the limit. It’s tough working for bosses who assume you already know everything.

The hard part here is setting up the facebook side. I’ve always found the Facebook APIs to be a complete disaster, with extremely confusing authentication requirements and an utterly opaque app review process. As a rule, I get my data out of facebook as fast as possible because it’s a mess over there.

The easiest way to do that is with realtime webhook notifications. To configure those notifications, you need to create a new facebook app and then designate it on your facebook page as your CRM manager. Follow the instructions here to get your facebook app set up: Retrieving - Marketing API - Documentation - Meta for Developers

Once facebook is configured to notify on new leads, the workflow is straightforward:

  • On each new lead, your webhook will get sent a json payload including a property called leadgen_id.
  • Then, request the Facebook API endpoint for that lead (something like https://graph.facebook.com/v11.0/{leadgen_id}) with an appropriate access token.
  • That endpoint will return a json object with all of your lead data. From there, you can submit it as a new lead in ERPNext.

You could do this all on the frappe side, though I personally prefer to use a middleware layer to orchestrate the transaction. Either way works, but I find the middleware encapsulates things a bit better and makes debugging easier. I really like n8n.io for this kind of thing. Huginn is another option.

If you want to do it purely in Frappe, the easiest way would probably be to create a new Server Script. From there, it’s probably only a dozen lines of python to turn the json object that facebook sends into a new Lead document.

3 Likes