How to create lead/opportunity from external contact form?

I’m facing the following scenario.

We have a WordPress website with a contact form that collects the following data from a lead:

  • Name
  • Address
  • Phone number
  • Email address
  • Source of the lead (Google, Facebook, referral, newspaper, etc.)
  • Comment (is optional)

We now receive an e-mail within ERPNext, sent by the WordPress form, that contains the above data.
Then we make an opportunity from this e-mail. The issue is that we have to enter all the above information manual into ERPNext.

Is there any way to extract this data from the email or contact form and use is to create a lead and opportunity automatic?

(We can format the email sent by the contact form in any way we want, if that helps)

Unfortunately, there are no reaction yet.

I doubt it that I’m the only one that is not using ERPNext for his website but is using an external CMS and would like to automatically collect leads through a contact form?

After some more searching, it seems that the easiest way to have the leads added to ERPNext automatically, is to make a webform in ERPNext and load that into the WordPress website with something like an Iframe. However, it seems that this is not allowed by ERPNext. Is there any way to have a webform embedded into an external website as WordPress in this example? Any suggestion how to deal with this?

Hi @Bas_de_Reus:

There are many ways to approach it.

Probably, easier one maybe define a webhook on Wordpress side pointing to REST API on ERPNext side. A webhook “trigger” an action after some event happened. In your case, apply webhook to your form, and call REST API to create the lead in ERPNext.

Other option is using some automation middleware like N8N , Zapier, Pipedream, Tray …

Some related projects:

Plugin to connect WP to ERPNext

Integration with Zapier

Some interesting info:

https://frappeframework.com/docs/user/en/api/rest

Hope this helps.

Thank you @AVC,

After looking into the REST API I agree that this looks like the way to go.

As a first step, I’ve created a PHP file that creates a Lead and an Address through the REST API. The only issue I have is that I’m unable to link the two together. I presume that I have to add a record to the Dynamic Link doctype, but maybe I’m wrong.

Can anybody tel me how to link the lead to the address through the REST API?

EDIT: I found the solution. I had to add the link information directly to the child table of the Address record. like:

$address_data = array(
        'address_title' => $address_title,
        'address_line1' => $address_line1,
        'pincode' => $postalcode,
        'city' => $city,
        'country' => $country,
        'links' => array(
            array(
                'link_doctype' => 'Lead',
                'link_name' => $lead_name
            )
        )
    );
1 Like