A common method of connecting to APIs is using the low level cURL utility. This article will provide example code for SharpSpring's Open API.
|
Available with: | ||||
Marketing Automation | ✓ | ||||
CRM Ultimate | ✓ | ||||
CRM PRO | ✓ | ||||
CRM Free | ✓ | ||||
Toolbar: | |||||
![]() ![]() |
|||||
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 SharpSpring'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 SharpSpring'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 SharpSpring API using .PHP. The content type for the request is manually set to JSON, and data is encoded in JSON format. |
Note: SharpSpring 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;
?>
Creating Leads with JSON
The following code is an example of how to use the createLeads
method to create a lead in SharpSpring:
{ "method":"createLeads", "params": {"objects": [ {"firstName":"john","lastName":"smith","emailAddress":"john@smith.com"}, {"firstName":"jane","lastName":"doe","emailAddress":"jane@doe.com"} ] }, "id":"<your request ID>" }
Updating Leads with JSON
The following code is an example of how to use the updateLeads
method to update leads already in SharpSpring.
{ "method":"updateLeads", "params": {"objects": [ {"id":"<lead ID>","firstName":"fooUpdate","lastName":"barUpdate"} ] }, "id":"<your request ID>" }
Deleting Leads with JSON
The following code is an example of how to use the deleteLeads
method to delete leads in SharpSpring.
{ "method":"deleteLeads", "params": {"objects": [ {"id":"<lead ID>"}, {"id":"<another lead ID>"}, ] }, "id":"<your request ID>" }