Lead Gen & CRM
How can we help you?
Search our help articles, video tutorials, and quickstart guides

You've got this. You've got us. Search our Knowledge Base to quickly find answers to your questions.

Understanding Lead Gen & CRM Open API: Example Code

Article: 000050404
Updated: July 18, 2024

Review example code for connecting to Lead Gen & CRM's Open API

A common method of connecting to APIs is using the low level cURL utility. This article will provide example code for Lead Gen & CRM's Open API.


Article Contents

 
 
Users:
Administrators 
Company Managers  
Marketing Managers  
Sales Managers  
Salespersons  
Jr. Salespersons  


Additional API Information

This article provides an example of how to structure code for Lead Gen & CRM's API. However, given the size and scope of the API, information is broken up and is contained in different articles. Each article focuses on a specific function of Lead Gen & CRM's API. Additional API information can be found in the following articles:



.PHP Code Example

The following code is an example that demonstrates a request to the Lead Gen & CRM API using .PHP. The content type for the request is manually set to JSON, and data is encoded in JSON format.

Note: Constant Contact offers Professional Services to assist with custom coding and API issues.
<?php
   /** Get all leads with a limit of 500 results */

   $limit = 500;                                                                         
   $offset = 0;                                                                          
                                                                                          
   $method = 'getLeads';                                                                 
   $params = array('where' => array(), 'limit' => $limit, 'offset' => $offset);          
   $requestID = session_id();       
   $accountID = '';
   $secretKey = '';                                                     

   $data = array(                                                                                
       'method' => $method,                                                                      
       'params' => $params,                                                                      
       'id' => $requestID,                                                                       
   );                                                                                            
                                                                                                 
   $queryString = http_build_query(array('accountID' => $accountID, 'secretKey' => $secretKey)); 
   $url = "http://api.sharpspring.com/pubapi/v1/?$queryString";                             
                                                                                                 
   $data = json_encode($data);                                                                   
   $ch = curl_init($url);                                                                        
   curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                              
   curl_setopt($ch, CURLOPT_POSTFIELDS, $data);                                                  
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                               
   curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                   
       'Content-Type: application/json',                                                         
       'Content-Length: ' . strlen($data)                                                        
   ));                                                                                           
                                                                                                 
   $result = curl_exec($ch);                                                                     
   curl_close($ch);                                                                              
                                                                                                 
   echo $result; 

?>  

 



Structure for Where Clauses

The following code is an example of how to use the where clause:
 

{
    "method": "getLeads",
    "params": {
        "where": {
        	"id": [1, 2, 3, 4]
        }
    },
    "id": 123
}

 



Structure for createLeads

The following code is an example of how to use the createLeads method to create a lead in Lead Gen & CRM:
 

{
  "method":"createLeads",
  "params":
    {"objects":
      [
        {"firstName":"john","lastName":"smith","emailAddress":"john@smith.com"},
        {"firstName":"jane","lastName":"doe","emailAddress":"jane@doe.com"}
      ]
      
    },
  "id":"<your request ID>"
}

 



Structure for updateLeads

The following code is an example of how to use the updateLeads method to update leads already in Lead Gen & CRM:
 

{
  "method":"updateLeads",
  "params":
    {"objects":
      [
        {"id":"<lead ID>","firstName":"fooUpdate","lastName":"barUpdate"}
      ]
    },
  "id":"<your request ID>"
}

 



Structure for deleteLeads

The following code is an example of how to use the deleteLeads method to delete leads in Lead Gen & CRM:
 

{
  "method":"deleteLeads",
  "params":
  {"objects":
    [
      {"id":"<lead ID>"},
      {"id":"<another lead ID>"},
    ]
  },
  "id":"<your request ID>"
}
 


Constant Contact Logo

Copyright © 2025 · All Rights Reserved · Constant Contact · Privacy Center