### Generate Code Examples Source: https://apidocs.leadsquared.com/get-create-lead-and-activity-metrics Examples of how to call the 'Get Create Lead and Activity Metrics' endpoint using PHP cURL and jQuery AJAX. ```PHP 'https://{async-host}/activity/createcustom/metrics', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "cache-control: no-cache" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } ?> ``` ```jQuery var settings = { "async": true, "crossDomain": true, "url": 'https://{async-host}/activity/createcustom/metrics', "method": "GET", "headers": { "Cache-Control": "no-cache" } } $.ajax(settings).done(function (response) { console.log(response); }); ``` -------------------------------- ### jQuery Example for GET /Leads.GetById Source: https://apidocs.leadsquared.com/get-lead-by-id Example of how to call the Leads.GetById endpoint using jQuery AJAX. ```javascript var settings = { "async": true, "crossDomain": true, "url": 'https://api.leadsquared.com/v2/LeadManagement.svc/Leads.GetById?accessKey=YOUR_ACCESS_KEY&secretKey=YOUR_SECRET_KEY&id=LEAD_ID', "method": "GET", "headers": { "Cache-Control": "no-cache" } } $.ajax(settings).done(function (response) { console.log(response); }); ``` -------------------------------- ### PHP Example for GET /Leads.GetById Source: https://apidocs.leadsquared.com/get-lead-by-id Example of how to call the Leads.GetById endpoint using PHP cURL. ```PHP 'https://api.leadsquared.com/v2/LeadManagement.svc/Leads.GetById?accessKey=YOUR_ACCESS_KEY&secretKey=YOUR_SECRET_KEY&id=LEAD_ID', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "cache-control: no-cache" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } ?> ``` -------------------------------- ### GET Account Details Example Source: https://apidocs.leadsquared.com/authentication Example of how to retrieve account details using the API. This includes sample code in PHP and jQuery. ```APIDOC ## GET Account Details ### Description This endpoint retrieves account details. It requires the `accessKey` and `secretKey` to be provided either as URL parameters or HTTP headers. ### Method GET ### Endpoint `/{host}/v2/LeadManagement.svc/Lead.Capture` (Example endpoint, actual may vary) ### Parameters #### Query Parameters - **accessKey** (string) - Required - Your LeadSquared access key. - **secretKey** (string) - Required - Your LeadSquared secret key. #### Request Headers - **x-LSQ-AccessKey** (string) - Required - Your LeadSquared access key. - **x-LSQ-SecretKey** (string) - Required - Your LeadSquared secret key. ### Request Example (PHP - cURL) ```php '', // Replace with your actual endpoint URL CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "cache-control: no-cache" // Add your accessKey and secretKey here if using headers // "x-LSQ-AccessKey: YOUR_ACCESS_KEY", // "x-LSQ-SecretKey: YOUR_SECRET_KEY" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } ?> ``` ### Request Example (jQuery) ```javascript var settings = { "async": true, "crossDomain": true, "url": '', // Replace with your actual endpoint URL "method": "GET", "headers": { "Cache-Control": "no-cache", // Add your accessKey and secretKey here if using headers // "x-LSQ-AccessKey": "YOUR_ACCESS_KEY", // "x-LSQ-SecretKey": "YOUR_SECRET_KEY" } } $.ajax(settings).done(function (response) { console.log(response); }); ``` ### Response #### Success Response (200) - The response will contain account details in JSON format. Specific fields depend on the account configuration. ``` -------------------------------- ### Get Account Details (Example) Source: https://apidocs.leadsquared.com/invoking-lapp-apis Example endpoint for retrieving account details, likely requiring access and secret keys. ```APIDOC ## GET /api/account/details ### Description Retrieves account details. This is a placeholder example based on the provided UI elements. ### Method GET ### Endpoint `/api/account/details` (Assumed endpoint) ### Parameters #### Query Parameters - **accessKey** (string) - Required - Your account access key. - **secretKey** (string) - Required - Your account secret key. ### Request Example (No request body for GET method) ### Response #### Success Response (200) Returns account details. #### Response Example ``` You have not yet submited ``` ``` -------------------------------- ### PHP Example for Get Lead Details by Email Source: https://apidocs.leadsquared.com/get-a-lead-by-email-id A PHP code example demonstrating how to call the LeadSquared API to retrieve lead details using cURL. ```PHP 'https://api.leadsquared.com/v2/LeadManagement.svc/Leads.GetByEmailaddress?accessKey=YOUR_ACCESS_KEY&secretKey=YOUR_SECRET_KEY&emailaddress=example@example.com', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "cache-control: no-cache" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } ?> ``` -------------------------------- ### jQuery Example for Get Lead Details by Email Source: https://apidocs.leadsquared.com/get-a-lead-by-email-id A jQuery AJAX example demonstrating how to call the LeadSquared API to retrieve lead details. ```javascript var settings = { "async": true, "crossDomain": true, "url": 'https://api.leadsquared.com/v2/LeadManagement.svc/Leads.GetByEmailaddress?accessKey=YOUR_ACCESS_KEY&secretKey=YOUR_SECRET_KEY&emailaddress=example@example.com', "method": "GET", "headers": { "Cache-Control": "no-cache" } } $.ajax(settings).done(function (response) { console.log(response); }); ``` -------------------------------- ### Retrieve Prospect Activity Details Source: https://apidocs.leadsquared.com/get-activities-details-by-activity-id Examples for making a GET request to the ProspectActivity service. ```php 'https://api.leadsquared.com/v2/ProspectActivity.svc/GetActivityDetails?', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "cache-control: no-cache", ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } ?> ``` ```javascript var settings = { "async": true, "crossDomain": true, "url": 'https://api.leadsquared.com/v2/ProspectActivity.svc/GetActivityDetails?', "method": "GET", "headers": { "Cache-Control": "no-cache", } } $.ajax(settings).done(function (response) { console.log(response); }); ``` -------------------------------- ### Complete Sample Code: Callback and Promise Approaches Source: https://apidocs.leadsquared.com/connect-to-your-database-using-mysql-proxy-with-fixed-ip-address Full implementation examples showing both callback-based and Promise-based patterns for executing queries. ```javascript let connectionOptions = { "host" : *****************.ap-south-1.rds.amazonaws.com", "user" : ls.SETTINGS.DBUSER, "password": ls.SETTINGS.DBPASSWORD, "database" : "*****_mxradon" } let queryOptions = { "sql" : "select ?? from sampledb where ?? = ?, "values" : [["name","category"], "id", "07b7e7f0-520e-11e9-9b91-069b743e848f"] } ​ ls.lib.mysqlproxy.query(connectionOptions,queryOptions,(error,res)=>{ if(error){ //handle error here ls.log.Error("error occured",error) } else { // handle successful response here ls.log.Info("got data",res) } }); ``` ```javascript let connectionOptions = { "host" : *****************.ap-south-1.rds.amazonaws.com", "user" : ls.SETTINGS.DBUSER, "password": ls.SETTINGS.DBPASSWORD, "database" : "*****_mxradon" } let queryOptions = { "sql" : "select ?? from sampledb where ?? = ?, "values" : [["name","category"], "id", "07b7e7f0-520e-11e9-9b91-069b743e848f"] } ​ ls.lib.mysqlproxy.query(connectionOptions,queryOptions) .then((res)=> { // handle successful response here ls.log.Info("got data",res) }) .catch((error)=> { //handle error here ls.log.Error("error occured",error) }) ``` -------------------------------- ### jQuery AJAX Example for GET Request Source: https://apidocs.leadsquared.com/team-management Example of how to make a GET request to the LeadSquared API using jQuery AJAX. ```javascript var settings = { "async": true, "crossDomain": true, "url": '', // Replace with your actual API endpoint "method": "GET", "headers": { "Cache-Control": "no-cache" } } $.ajax(settings).done(function (response) { console.log(response); }); ``` -------------------------------- ### Install the lsbatch library Source: https://apidocs.leadsquared.com/write-code-for-batch-jobs Install the required SDK library using pip. Requires Python 3.7 and virtualenv. ```bash pip install lsbatch ``` -------------------------------- ### PHP cURL Example for GET Request Source: https://apidocs.leadsquared.com/team-management Example of how to make a GET request to the LeadSquared API using PHP cURL. ```PHP '', // Replace with your actual API endpoint CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "cache-control: no-cache" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:". $err; } else { echo $response; } ?> ``` -------------------------------- ### jQuery Example for Get Details of an Activity Owner Source: https://apidocs.leadsquared.com/get-activity-owner-details Example code in jQuery to call the Get Details of an Activity Owner API. ```javascript var settings = { "async": true, "crossDomain": true, "url": 'https://api.leadsquared.com/v2/ProspectActivity.svc/ActivityOwner.Get?', "method": "GET", "headers": { "Cache-Control": "no-cache" } } $.ajax(settings).done(function (response) { console.log(response); }); ``` -------------------------------- ### PHP SDK Example Source: https://apidocs.leadsquared.com/create-a-user Example of how to use the LeadSquared API with PHP, including setting up the request and handling the response. ```PHP "; $header = array( "Content-Type:application/json", "Content-Length:" . strlen($data_string) ); if (!empty($header) && isset($_POST["ad_key"]) && !empty($_POST["ad_key"])) { foreach ($_POST["ad_key"] as $key => $value) { if (!empty($value) && !empty($_POST["ad_value"][$key])) $header[] = $value . ':' . $_POST["ad_value"][$key]; } } try { $curl = curl_init($url); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); $response = curl_exec($curl); if ($err) { echo "cURL Error #:". $err; } else { echo $response; } } catch (Exception $ex) { curl_close($curl); } ?> ``` -------------------------------- ### Sample Query Syntax Examples Source: https://apidocs.leadsquared.com/connect-to-your-database-using-mysql-proxy-with-fixed-ip-address Various ways to structure query options for different SQL scenarios, including placeholder usage. ```javascript //Passing one value in where clause let queryOptions = { "sql" : "select id,name,category from sampledb where id = ?", "values" : [2] } ​ //Passing 2 values in where clause let queryOptions = { "sql" : "select id,name,category from sampledb where name = ? and id = ?", "values" : ['nameA','nameB'] } ​ //Passing columns and table name; column and column value in where clause let queryOptions = { "sql" : "select ?? from ?? where ?? = ?", "values" : [['id','name','company'],'sampledb','name','nameB'] } ``` -------------------------------- ### PHP Example for Get Details of an Activity Owner Source: https://apidocs.leadsquared.com/get-activity-owner-details Example code in PHP using cURL to call the Get Details of an Activity Owner API. ```PHP 'https://api.leadsquared.com/v2/ProspectActivity.svc/ActivityOwner.Get?', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "cache-control: no-cache" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:". $err; } else { echo $response; } ?> ``` -------------------------------- ### Initialize Lapp Plugin with x-api-key for Development Source: https://apidocs.leadsquared.com/invoking-lapp-apis Use this initialization method to test Lapps independently of a logged-in session. Never use this in production environments. ```html ``` -------------------------------- ### jQuery Example for Get Custom Web App Menu Source: https://apidocs.leadsquared.com/get-a-custom-custom-menu-for-the-web-app Example of how to call the Get Custom Web App Menu API using jQuery AJAX. ```javascript var settings = { "async": true, "crossDomain": true, "url": 'https://api.leadsquared.com/v2/Connector.svc/CustomWebAppMenu/Retrieve?', "method": "GET", "headers": { "Cache-Control": "no-cache" } } $.ajax(settings).done(function (response) { console.log(response); }); ``` -------------------------------- ### PHP Example for Get Custom Web App Menu Source: https://apidocs.leadsquared.com/get-a-custom-custom-menu-for-the-web-app Example of how to call the Get Custom Web App Menu API using PHP cURL. ```PHP 'https://api.leadsquared.com/v2/Connector.svc/CustomWebAppMenu/Retrieve?', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "cache-control: no-cache" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } ?> ``` -------------------------------- ### Pack Project for Deployment Source: https://apidocs.leadsquared.com/write-code-for-batch-jobs Create a zip file of the project for deployment. ```bash lsbatch pack ``` -------------------------------- ### PHP cURL Example Source: https://apidocs.leadsquared.com/invoking-lapp-apis Example of how to make a GET request using cURL in PHP. ```PHP '', // Replace with your actual URL CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "cache-control: no-cache" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:". $err; } else { echo $response; } ?> ``` -------------------------------- ### PHP SDK Example Source: https://apidocs.leadsquared.com/get-activities-of-a-lead Example of how to use the LeadSquared API with PHP using cURL. ```PHP "; $header = array( "Content-Type:application/json", "Content-Length:" . strlen($data_string) ); if (!empty($header) && isset($_POST["ad_key"]) && !empty($_POST["ad_key"])) { foreach ($_POST["ad_key"] as $key => $value) { if (!empty($value) && !empty($_POST["ad_value"][$key])) $header[] = $value . ':' . $_POST["ad_value"][$key]; } } try { $curl = curl_init($url); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:". $err; } else { echo $response; } } catch (Exception $ex) { curl_close($curl); } ?> ``` -------------------------------- ### jQuery Code Example Source: https://apidocs.leadsquared.com/custom-tabs-actions Example of how to make a GET request using jQuery AJAX. ```javascript var settings = { "async": true, "crossDomain": true, "url": '', // Replace with your actual endpoint URL "method": "GET", "headers": { "Cache-Control": "no-cache" } } $.ajax(settings).done(function (response) { console.log(response); }); ``` -------------------------------- ### PHP Code Example Source: https://apidocs.leadsquared.com/custom-tabs-actions Example of how to make a GET request using PHP cURL. ```PHP '', // Replace with your actual endpoint URL CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "cache-control: no-cache" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:". $err; } else { echo $response; } ?> ``` -------------------------------- ### Python SDK Example Source: https://apidocs.leadsquared.com/create-a-user Example of how to use the LeadSquared API with Python using the requests library. ```Python import requests url = "" querystring = payload = headers = { "content-type": "application/json", "cache-control": "no-cache" } response = requests.request("POST", url, data=payload, headers=headers, params=querystring) print(response.text) ``` -------------------------------- ### Check-Out User Implementation Examples Source: https://apidocs.leadsquared.com/check-out-user Code examples for performing the Check-Out User request using PHP and Python. ```php "; $header=array( "Content-Type:application/json", "Content-Length:" 0, ); if(!empty($header)&&isset($_POST["ad_key"])&&!empty($_POST["ad_key"])){ foreach ($_POST["ad_key"] as $key => $value) { if(!empty($value)&&!empty($_POST["ad_value"][$key])) $header[]= $value.$colan.$_POST["ad_value"][$key]; } } try { $curl = curl_init($url); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); $response = curl_exec($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; }else{ echo $response; } } catch (Exception $ex) { curl_close($curl); }?> ``` ```python import requests url = "" querystring = payload = headers = { "content-type": "application/json", "cache-control": "no-cache" } response = requests.request("POST", url, data=payload, headers=headers, params=querystring) print(response.text) ``` -------------------------------- ### Generate Code Examples Source: https://apidocs.leadsquared.com/enable-agent-pop-up Examples of how to call the Enable Agent Pop-Up API using PHP and jQuery. ```PHP 'https://api.leadsquared.com/v2/Telephony.svc/AgentPopup/Enable?', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "cache-control: no-cache" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:". $err; } else { echo $response; } ?> ``` ```jQuery var settings = { "async": true, "crossDomain": true, "url": 'https://api.leadsquared.com/v2/Telephony.svc/AgentPopup/Enable?', "method": "GET", "headers": { "Cache-Control": "no-cache" } } $.ajax(settings).done(function (response) { console.log(response); }); ``` -------------------------------- ### API Request Example with URL Parameters Source: https://apidocs.leadsquared.com/bulk-update-opportunities This example shows how to construct the API request URL with access and secret keys, and includes a sample JSON body for bulk updating opportunities. ```http POST https://{host}/v2/OpportunityManagement.svc/Bulk/Update/ByOpportunityId?accessKey=AccessKey&secretKey=SecretKey Content-Type: application/json [ { "ProspectOpportunityId": "4f530c63-4c93-4150-8b8e-83487befb3b2", "OpportunityEventCode": 12003, "Fields": [ { "SchemaName": "Status", "Value": "Won" }, { "SchemaName": "Owner", "Value": "96105aa0-61f2-11ea-8109-022edb41208c" } ] }, { "ProspectOpportunityId": "c5a7f37c-b789-44c9-929b-74aa6250b539", "OpportunityEventCode": 12000, "Fields": [ { "SchemaName": "mx_Custom_6", "Value": "23500" } ] } ] ``` -------------------------------- ### PHP cURL Request Example Source: https://apidocs.leadsquared.com/write-code-for-batch-jobs Example of how to make a GET request using PHP cURL to retrieve account details. ```PHP '', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "cache-control: no-cache" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:". $err; } else { echo $response; } ?> ``` -------------------------------- ### API Request Example Source: https://apidocs.leadsquared.com/create-a-lead An example of how to structure an API request to create a lead, including URL parameters and the JSON body. ```http POST https://{host}/v2/LeadManagement.svc/Lead.Create?accessKey=AccessKey&secretKey=SecretKey Content-Type: application/json [ { "Attribute": "EmailAddress", "Value": "joe.pesci@example.com" }, { "Attribute": "FirstName", "Value": "Joe" }, { "Attribute": "LastName", "Value": "Pesci" }, { "Attribute": "Phone", "Value": "8888888888" }, { "Attribute": "mx_City", "Value": "New York City" }, { "Attribute": "LeadType", "Value": "OT_1" }, { "Attribute": "mx_KYC", "Value": "", "Fields": [ { "Attribute": "Status", "Value": "Pending" }, { "Attribute": "mx_CustomObject_1", "Value": "XYZ12345.png" }, { "Attribute": "mx_CustomObject_2", "Value": "864563" } ] } ] ``` -------------------------------- ### PHP Example for Get User Tags Source: https://apidocs.leadsquared.com/get-user-tags Example code in PHP using cURL to fetch user tags from the LeadSquared API. ```PHP 'https://api.leadsquared.com/v2/UserManagement.svc/Retrieve/GetTags?', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( "cache-control: no-cache" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:". $err; } else { echo $response; } ?> ``` -------------------------------- ### API Request Example with Parameters Source: https://apidocs.leadsquared.com/generate-prefilled-forms-on-landing-pages-pro Example of submitting a request to the API with URL parameters and a JSON body. ```http POST ?accessKey=&secretKey= Host Name Please enter valid URL. Access Key Secret Key Additional Header Remove Add more Body { "PortalId": "8a31093e-f84c-11f0-8ecd-02eda0793197", "LeadId": "90fe71ae-25e3-468d-8b0f-55258e31ff13", "ActivityId": "886f5cdf-571a-4e9e-a274-267b4984b5b6", "OpportunityId": "9eca8ccb-1598-43e5-984e-895e4d77f", "QueryParams": [] } Reset Submit ``` -------------------------------- ### Initialize a new Batch Job project Source: https://apidocs.leadsquared.com/write-code-for-batch-jobs Create a new project structure in the current directory. ```bash lsbatch init ``` -------------------------------- ### Install Dependencies Source: https://apidocs.leadsquared.com/write-code-for-batch-jobs Commands to install project dependencies or custom packages. ```bash lsbatch install ``` ```bash lsbatch install {package_name} ``` -------------------------------- ### Create a Lead and Activity (Async) Source: https://apidocs.leadsquared.com/create-a-lead-and-activity-async This endpoint creates a new lead and activity asynchronously. It requires an `x-api-key` in the header and returns a `RequestId` to track the status. ```APIDOC ## POST /activity/createcustom ### Description Creates a new lead and activity asynchronously. Returns a `RequestId` to check the status of the operation. ### Method POST ### Endpoint `https://{async-host}/activity/createcustom?accessKey=AccessKey&secretKey=SecretKey` ### Parameters #### Query Parameters - **accessKey** (string) - Required - Your LeadSquared access key. - **secretKey** (string) - Required - Your LeadSquared secret key. #### Headers - **x-api-key** (string) - Required - Your LeadSquared API key for asynchronous requests. - **Content-Type** (string) - Required - `application/json` #### Request Body - **LeadDetails** (array) - Required - An array of lead attribute-value pairs. Can include `SearchBy` to identify an existing lead. - **Attribute** (string) - Required - The name of the lead attribute. - **Value** (string) - Required - The value of the lead attribute. - **Fields** (array) - Optional - For custom field sets, contains attribute-value pairs for CFS fields. - **Attribute** (string) - Required - The schema name of the custom object field. - **Value** (string) - Required - The value for the custom object field. - **Activity** (object) - Required - Details of the activity to be created. - **ActivityEvent** (integer) - Required - The code for the activity type. - **ActivityNote** (string) - Optional - Notes for the activity. - **ActivityDateTime** (string) - Required - The date and time of the activity in UTC (YYYY-MM-DD HH:MM:SS). - **Fields** (array) - Optional - Attribute-value pairs for activity fields. For custom field sets, contains attribute-value pairs for CFS fields. - **SchemaName** (string) - Required - The schema name of the custom object field. - **Value** (string) - Required - The value for the custom object field. ### Request Example ```json { "LeadDetails": [ { "Attribute": "EmailAddress", "Value": "email@example.com" }, { "Attribute": "mx_City", "Value": "Bangalore" }, { "Attribute": "mx_KYC", "Value": "", "Fields": [ { "Attribute": "Status", "Value": "Pending" }, { "Attribute": "mx_CustomObject_1", "Value": "XYZ12345.png" }, { "Attribute": "mx_CustomObject_2", "Value": "864563" } ] }, { "Attribute": "SearchBy", "Value": "EmailAddress" } ], "Activity": { "ActivityEvent": 105, "ActivityNote": "Note for the activity", "ActivityDateTime": "2016-07-07 10:55:00", "Fields": [ { "SchemaName": "mx_Custom_1", "Value": "123" }, { "SchemaName": "mx_Custom_2", "Value": "2016-07-07 10:55:00" }, { "Attribute": "mx_KYC", "Value": "", "Fields": [ { "Attribute": "Status", "Value": "Pending" }, { "Attribute": "mx_CustomObject_2", "Value": "XYZ12345.png" }, { "Attribute": "mx_CustomObject_4", "Value": "864563" } ] } ] } } ``` ### Response #### Success Response (200 OK) - **Status** (string) - A message indicating the request was accepted. - **RequestID** (string) - A unique identifier for the request, used to check the status. #### Response Example ```json { "Status": "Request accepted. Please use below request id to check the status", "RequestID": "571dfc10-d3e6-4511-8d33-c7a7ad8c236c" } ``` ### HTTP Response Codes - **200 OK**: Successful API call. - **401 Unauthorized**: Invalid access credentials. - **400 Bad Request**: Malformed request body or incorrect Content-Type. - **404 Not Found**: API endpoint not found. - **429 Too Many Requests**: Rate limit exceeded. - **500 Internal Server Error**: Server-side error during processing. ``` -------------------------------- ### API Request Example with URL Parameters Source: https://apidocs.leadsquared.com/get-sign-in-otp This example shows how to construct an API request URL with access key and secret key as URL parameters. It also includes a placeholder for additional headers and a JSON body. ```http POST ?accessKey=&secretKey= ``` -------------------------------- ### GET Request for Content Template Source: https://apidocs.leadsquared.com/get-email-template Example GET request to retrieve a content template by its ID. Ensure you provide valid accessKey, secretKey, and ContentTemplateId. ```http GET ?accessKey=&secretKey=&id=ContentTemplateId ``` -------------------------------- ### jQuery Example for Get User Tags Source: https://apidocs.leadsquared.com/get-user-tags Example code using jQuery's AJAX method to retrieve user tags from the LeadSquared API. ```javascript var settings = { "async": true, "crossDomain": true, "url": 'https://api.leadsquared.com/v2/UserManagement.svc/Retrieve/GetTags?', "method": "GET", "headers": { "Cache-Control": "no-cache" } } $.ajax(settings).done(function (response) { console.log(response); }); ``` -------------------------------- ### Configure Tenant Profile Source: https://apidocs.leadsquared.com/write-code-for-batch-jobs Use `lsbatch configure` to set up tenant profiles with specific access levels. You will be prompted for profile name, orgcode, region, and token. ```bash lsbatch configure ``` -------------------------------- ### Get User Work Day Details Response Example Source: https://apidocs.leadsquared.com/get-work-day-details Example JSON response for the GetWorkDayDetails API, indicating user availability and working hours. ```JSON { "IsAvailable": 1, "StatusReason": "", "UserId": "dd908e91-c5c9-11e5-8de3-22000aa5088d", "WorkingHours": [ { "StartTime": "09:00:00", "EndTime": "18:00:00" } ] } ``` -------------------------------- ### POST /v2/ProspectActivity.svc/CreateCustom Source: https://apidocs.leadsquared.com/create-lead-and-activity Creates a new lead and posts an activity on the lead simultaneously. If a lead exists, it will be updated; otherwise, a new lead will be created. ```APIDOC ## POST /v2/ProspectActivity.svc/CreateCustom ### Description Creates a new lead and posts an activity on the lead at the same time. If a lead exists with the specified value in 'SearchBy', it will be updated; otherwise, a new lead will be created. ### Method POST ### Endpoint https://{host}/v2/ProspectActivity.svc/CreateCustom?accessKey=AccessKey&secretKey=SecretKey ### Parameters #### Query Parameters - **accessKey** (string) - Required - Your API access key. - **secretKey** (string) - Required - Your API secret key. #### Request Body - **LeadDetails** (array) - Required - An array of lead attribute-value pairs. Can include 'SearchBy' to find an existing lead or create a new one. Supports custom fields via 'Fields' array. - **Attribute** (string) - Required - The name of the lead attribute (e.g., 'EmailAddress', 'mx_City', 'LeadType', 'SearchBy'). - **Value** (string) - Required - The value for the lead attribute. - **Fields** (array) - Optional - For custom field sets associated with the lead. - **Attribute** (string) - Required - The schema name of the custom object field. - **Value** (string) - Required - The value for the custom object field. - **Activity** (object) - Required - Details of the activity to be posted. - **ActivityEvent** (integer) - Required - The code of the activity type. - **ActivityNote** (string) - Optional - Notes for the activity. - **ActivityDateTime** (string) - Optional - The date-time of the activity in UTC (YYYY-MM-DD HH:MM:SS). - **Fields** (array) - Optional - For custom field sets associated with the activity. - **SchemaName** (string) - Required - The schema name of the custom object field. - **Value** (string) - Required - The value for the custom object field. ### Request Example ```json { "LeadDetails": [ { "Attribute": "EmailAddress", "Value": "joe@example.com" }, { "Attribute": "mx_City", "Value": "Bangalore" }, { "Attribute": "LeadType", "Value": "OT_1" }, { "Attribute": "mx_KYC", "Value": "", "Fields": [ { "Attribute": "Status", "Value": "Pending" }, { "Attribute": "mx_CustomObject_1", "Value": "XYZ12345.png" }, { "Attribute": "mx_CustomObject_2", "Value": "864563" } ] }, { "Attribute": "SearchBy", "Value": "EmailAddress" } ], "Activity": { "ActivityEvent": 105, "ActivityNote": "Note for the activity", "ActivityDateTime": "yyyy-MM-dd HH:mm:ss", "Fields": [ { "SchemaName": "mx_Custom_1", "Value": "123" }, { "SchemaName": "mx_Custom_2", "Value": "2016-07-07 10:55:00" } ] } } ``` ### Response #### Success Response (200 OK) - **Status** (string) - Indicates the status of the operation ('Success' or 'Error'). - **Message** (object) - Contains details about the operation result. - **Id** (string) - The unique identifier for the created or updated lead/activity. #### Response Example ```json { "Status": "Success", "Message": { "Id": "f0b1a207-7c72-11e5-a199-22000aa4133b" } } ``` ``` -------------------------------- ### Retrieve Activity API Request Examples Source: https://apidocs.leadsquared.com/retrieve-sales-activity Examples showing how to perform a GET request to the Retrieve Activity endpoint using PHP cURL and jQuery AJAX. ```php  'https://api.leadsquared.com/v2/SalesActivity.svc/RetrieveActivity?',         CURLOPT_RETURNTRANSFER => true,         CURLOPT_ENCODING => "",         CURLOPT_MAXREDIRS => 10,         CURLOPT_TIMEOUT => 30,         CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,         CURLOPT_CUSTOMREQUEST => "GET",         CURLOPT_HTTPHEADER => array(                 "cache-control: no-cache",             ),         ));         $response = curl_exec($curl);         $err = curl_error($curl);         curl_close($curl);         if ($err) {             echo "cURL Error #:" . $err;         } else {                 echo $response;         } ?> ``` ```javascript var settings = { "async": true, "crossDomain": true, "url": 'https://api.leadsquared.com/v2/SalesActivity.svc/RetrieveActivity?', "method": "GET", "headers": {             "Cache-Control": "no-cache",         }     } $.ajax(settings).done(function (response) {     console.log(response); }); ``` -------------------------------- ### PHP Code Example Source: https://apidocs.leadsquared.com/capture-leads-async Example of how to make a POST request to the Capture Leads (Async) API using PHP and cURL. ```PHP getMessage(); } ?> ```