1. What is webhook?

A webhook is simply a user-defined callback in the form of an HTTP POST, which is invoked when something happens. In LeadSquared, Webhook provide the ability to receive real-time data updates about your Leads & activities performed.


2.  How to create a webhook

Please navigate to ‘Settings-> API and Webhooks -> Webhooks -> Click on create & Choose respective event type.

  • Event: Trigger type on which Webhook needs to executed.
  • Webhook URL: Webhook URL will be your server URL i.e. “End Point URL’ to which the data needs to be posted on specific event is triggered.

            Please find the sample example of Webhook URL: http://yourdomain.com/webhooks/actions.php
            Where :
                        • yourdomain.com is the domain name.
                        • webhooks is the folder which is created in your server.
                        • actions.php is file where you can use to write any script to read and process the data

  • Execution Delay: We can specify the delay in the execution of Webhook when event is triggered.
  • Content-type: Content type will specifies the data format.


3. How to process the data

In the above example, whenever the lead is created in LeadSquared system will post all the lead fields which are mandatory in the system and along with the fields which have values at the time creation.

Sample format for Lead Creation event:

{

  "ProspectID": "a311900c-0e56-4601-b580-f931645e7b32",

  "ProspectAutoId": "3142",

  "FirstName": "Sachin",

  "LastName": "One",

  "EmailAddress": "Sachinone@yopmail.com",

  "Origin": "API",

  "Phone": null,

  "Mobile": null,

  "Source": "Direct Traffic",

  "SourceMedium": "",

  "SourceCampaign": "",

  "DoNotEmail": "0",

  "DoNotCall": "0",

  "ProspectStage": "Initial",

  "Score": "0",

  "EngagementScore": "0",

  "TotalVisits": "0",

  "PageViewsPerVisit": "0",

  "AvgTimePerVisit": "0",

  "ProspectActivityId_Min": "79c45ef2-0b27-11e8-8dc3-22000aa8e760",

  "ProspectActivityDate_Min": "2018-02-06 10:21:20",

  "ProspectActivityId_Max": "79c45ef2-0b27-11e8-8dc3-22000aa8e760",

  "ProspectActivityName_Max": "Page Visited on Website",

  "ProspectActivityDate_Max": "2018-02-06 10:21:20",

  "FirstLandingPageSubmissionDate": null,

  "OwnerId": "7ffbe05e-3974-11e6-8091-02b01d637af7",

  "CreatedBy": "7ffbe05e-3974-11e6-8091-02b01d637af7",

  "CreatedOn": "2018-02-06 10:21:20",

  "ModifiedBy": "7ffbe03b-3974-11e6-8091-02b01d637af7",

  "ModifiedOn": "2018-02-06 12:12:57",

  "LeadConversionDate": "2018-02-06 12:12:57",

  "StatusCode": "0",

  "StatusReason": "0",

  "IsLead": "1",

  "mx_Street1": null,

  "mx_Street2": null,

  "LastModifiedOn": "2018-02-06 12:12:57",

  "mx_Previous_College": null,

  "mx_cities": null,

  "mx_first_dropdown": null,

  "mx_Choose_Coucellor": null,

  "mx_Domain_Name": null,

  "mx_Sub_Source": null,

  "mx_Lead_Type": null,

  "NotableEvent": "Modified",

  "NotableEventdate": "2018-02-06 12:12:57",

  "SourceReferrer": "",

  "LastVisitDate": "2018-02-06 10:21:20",

  "ConversionReferrerURL": null,

  "SourceReferrerURL": "",

  "SourceIPAddress": "106.51.74.214",

  "QualityScore01": null,

  "StageRottingFlagStatus": null,

  "StageRottingFlagMessage": null,

  "StageRottingFlagModifiedOn": null,

  "StageRottingFlagLevel": null,

  "OwnerIdName": "System",

  "OwnerIdEmailAddress": "t20160623185751@leadsquared.com",

  "CreatedByName": "System",

  "ModifiedByName": "Prathap J",

  "CanUpdate": "true"

}


Now, Any programming language can be used to read webhook data, which comes across as "post" data to any URL.

Sample Ex in PHP language.

<?php

//Reading the Webhook Data and Storing into Specific variable

$Lead_Details                           = file_get_contents('php://input'); 

$Lead_Details_Decodeed          = json_decode($Lead_Details, true);

// Processing the required field values and storing into a new varibales

$Lead_Phone                                        = $Lead_Details_Decodeed['Phone'];

$Lead_Name                                        = $Lead_Details_Decodeed['FirstName'];

$Lead_Source                                       = $Lead_Details_Decodeed['Source'];

$Lead_Stage                                         = $Lead_Details_Decodeed['ProspectStage'];

?>


Note: Please do not share this code with the customer without approval from Prashant/Sam


Explanation of the code:

PHP supports standard function called ‘file_get_contents’ to read the contents/data to a string.


In above example, Whatever the data posted to webhook URL, I am reading the data using this function and storing into a variable called ‘$Lead_Details’.

By default, it will store the data in the format which posted by the Server side [In our case it is JSON], So I am decoding it to read specific values.


JSON_DECODE -> will convert JSON object -> Array


After decoding the data reading the required details and storing into specific fields as mentioned above.

Now, you have the processed data, we can use this data to send it to external system/any API’s.


Hope it helped!

Thank you, LeadSquared Support