Introduction

This section outlines the most important information with regards to the Leadtrekker API. If you are new to the Leadtrekker API you should read this section carefully to understand the basics of using the Leadtrekker API.

All of the examples in this documentation will make use of basic HTTP POST request methods to the API in order to send and receive information using the PHP cURL library.

Confirming Your cURL Installation

You can confirm that your PHP installation supports cURL by running the following code from any PHP script:

<?php echo function_exists('curl_version'); ?>

If the code above returns false (or a blank result) you can refer to these steps to install PHP cURL.

JSON Data

It is also important to note that all HTTP requests to the API should always be an encoded JSON formatted string or array with the value of each element in the array as a base64 encoded value. The Leadtrekker API will also send all responses back to you in JSON format. You can use the PHP function called json_decode() to parse the API responses.

Authentication

API Key

In order to use the Leadtrekker API each call to the API has to include a header called Apikey. This header should include a value that matches your API Key which in turn is used by the API to uniquely identify each client.

Keep Your API Key Secure

Your API key should always be kept secret! If your API key gets into the wrong hands it could be used to access sensitive information on your Leadtrekker account. You can change your API key by contacting your Leadtrekker partner or contacting Leadtrekker support directly by sending an email to support[at]leadtrekker.com.

Locate Your API Key

You can follow these steps to locate your unique Leadtrekker API Key.

  1. Log into the main Leadtrekker System.
  2. Click on Settings from the main navigation and then select Account.
  3. Look for the section called Leadtrekker API.

API Endpoints

API Endpoints are essentially the available functions presented by the API. These functions can be used to either send (POST) or receive information between the API and your web application or website. Understanding what each endpoint is used for is essential to successful Leadtrekker integration between your web application and the Leadtrekker database.

Apart from the compulsory Apikey header some endpoints might have other required, and sometimes optional, parameters that need to be passed along when using that specific endpooint.

Creating Leads

The most widely used endpoint the Leadtrekker API has to offer is the createlead endpoint. This endpoint is used to send leads from your web application into your Leadtrekker account.

URL
https://system.leadtrekker.com/api/createlead
Required Parameters
Property Type Description Default
name Base64 encoded string The name of the lead. -
number Base64 encoded string The contact number of the lead. -
email Base64 encoded string The email address of the lead. -
Optional Parameters
Property Type Description Default
company Base64 encoded string Company name of the lead. -
confidence Base64 encoded integer The level of confidence that the lead will convert into business. 1 being low 10 being high. 1
custom_fields Array with Base64 encoded values Key value pair array of custom fields. -
expected_closing_date Base64 encoded string The expected date the lead will convert into business. Last day of the current month.
notes Base64 encoded string Notes related to the lead. -
sourceid Base64 encoded integer The source id of the lead. 1
statusid Base64 encoded integer The status id of the lead. 1
value Base64 encoded float The value of the lead should it convert into business. 0
interested_in Base64 encoded string Wich service or product the lead seems interested in. -
group Base64 encoded string Link the lead to a group name. -
Response
Property Type Description
id Integer The id of the lead if it was created successfully. -

Creating Leads Examples

Most basic example to create a lead with only the three required parameters
<?php
$data = array();
$headers = array();
$Apikey = 'A1B2C3D4E5F6G7H8I9';
$url = 'https://system.leadtrekker.com/api/createlead';

$data['name'] = base64_encode('John Doe');
$data['email'] = base64_encode('john.doe@johnsbakery.com');
$data['number'] = base64_encode('0120040509');

$data = json_encode($data);

$cSession = curl_init();
$headers[] = 'Apikey:' . $Apikey;
curl_setopt($cSession, CURLOPT_URL, $url);
curl_setopt($cSession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cSession, CURLOPT_HEADER, false);
curl_setopt($cSession, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($cSession, CURLOPT_POSTFIELDS, $data);
curl_setopt($cSession, CURLOPT_SSL_VERIFYPEER, false);
$headers[] = 'Content-Type: application/json';
curl_setopt($cSession, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($cSession);
curl_close($cSession);
?>
Example to create a lead with all optional parameters except custom fields
<?php
$data = array();
$headers = array();
$Apikey = 'A1B2C3D4E5F6G7H8I9';
$url = 'https://system.leadtrekker.com/api/createlead';

$data['name'] = base64_encode('John Doe');
$data['email'] = base64_encode('john.doe@johnsbakery.com');
$data['number'] = base64_encode('0120040509');
$data['company'] = base64_encode('Johns Bakery');
$data['confidence'] = base64_encode('6');
$data['expected_closing_date'] = base64_encode('2020-09-11');
$data['notes'] = base64_encode('This will be added as a note to the lead.');
$data['sourceid'] = base64_encode('12345');
$data['statusid'] = base64_encode('54321');
$data['value'] = base64_encode('125.00');

$data = json_encode($data);

$cSession = curl_init();
$headers[] = 'Apikey:' . $Apikey;
curl_setopt($cSession, CURLOPT_URL, $url);
curl_setopt($cSession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cSession, CURLOPT_HEADER, false);
curl_setopt($cSession, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($cSession, CURLOPT_POSTFIELDS, $data);
curl_setopt($cSession, CURLOPT_SSL_VERIFYPEER, false);
$headers[] = 'Content-Type: application/json';
curl_setopt($cSession, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($cSession);
curl_close($cSession);
?>
Example to create a lead with some optional parameters and a few custom fields
<?php
$data = array();
$headers = array();
$Apikey = 'A1B2C3D4E5F6G7H8I9';
$url = 'https://system.leadtrekker.com/api/createlead';

$data['name'] = base64_encode('John Doe');
$data['email'] = base64_encode('john.doe@johnsbakery.com');
$data['number'] = base64_encode('0120040509');
$data['company'] = base64_encode('Johns Bakery');
$data['confidence'] = base64_encode('6');
$data['expected_closing_date'] = base64_encode('2020-09-11');
$data['notes'] = base64_encode('This will be added as a note to the lead.');
$data['sourceid'] = base64_encode('12345');
$data['statusid'] = base64_encode('54321');
$data['value'] = base64_encode('125.00');

$data['custom_fields'] = array(
    'Country' => base64_encode('South Africa'),
    'Age' => base64_encode('50'),
    'Sex' => base64_encode('Male'));

$data = json_encode($data);

$cSession = curl_init();
$headers[] = 'Apikey:' . $Apikey;
curl_setopt($cSession, CURLOPT_URL, $url);
curl_setopt($cSession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cSession, CURLOPT_HEADER, false);
curl_setopt($cSession, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($cSession, CURLOPT_POSTFIELDS, $data);
curl_setopt($cSession, CURLOPT_SSL_VERIFYPEER, false);
$headers[] = 'Content-Type: application/json';
curl_setopt($cSession, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($cSession);
curl_close($cSession);
?>

Creating Custom Fields

Add custom fields to leads after they have been created.

Create Custom Fields While Creating a Lead

You can create all your custom fields while creating the lead. Refer to the Creating Leads section form more information.

URL
https://system.leadtrekker.com/api/createcustomfields
Required Parameters
Property Type Description
leadid Base64 encoded integer The id of the lead.
custom_fields Array with Base64 encoded values The createcustomfields API method expects an array called custom_fields. Each value in the array should be Base64 encoded.
Response
Property Type Description
Response Text String The status of the request. A successful request returns OK. -

Creating Custom Fields Example

This example creates 3 different custom fields and links them to lead with id 12345
<?php
$data = array();
$headers = array();
$Apikey = 'A1B2C3D4E5F6G7H8I9';
$url = 'https://system.leadtrekker.com/api/createcustomfields';

$data['leadid'] = base64_encode('12345');
  $data['custom_fields'] = array(
    'Age' => base64_encode('30'),
    'Sex' => base64_encode('Male'),
    'Location' => base64_encode('South Africa')
  );

$data = json_encode($data);

$cSession = curl_init();
$headers[] = 'Apikey:' . $Apikey;
curl_setopt($cSession, CURLOPT_URL, $url);
curl_setopt($cSession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cSession, CURLOPT_HEADER, false);
curl_setopt($cSession, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($cSession, CURLOPT_POSTFIELDS, $data);
curl_setopt($cSession, CURLOPT_SSL_VERIFYPEER, false);
$headers[] = 'Content-Type: application/json';
curl_setopt($cSession, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($cSession);
curl_close($cSession);
?>

Creating Notes

Use this endpoint to create notes.

URL
https://system.leadtrekker.com/api/createnote
Required Parameters
Property Type Description
leadid Base64 encoded integer The id of the lead.
note Base64 encoded string The actual text of the note to be created.
Optional Parameters
Property Type Description Default
userid Base64 encoded integer The id of the user creating the note. 0 (System user)
Response
Property Type Description
Response Text String The status of the request. A successful request returns OK. -

Creating Notes Example

<?php
$data = array();
$headers = array();
$Apikey = 'A1B2C3D4E5F6G7H8I9';
$url = 'https://system.leadtrekker.com/api/createnote';

$data = array(
  'leadid' => base64_encode(12345),
  'note' => base64_encode('Hello world!'),
  'userid' => base64_encode(123)
  ); 

$data = json_encode($data);

$cSession = curl_init();
$headers[] = 'Apikey:' . $Apikey;
curl_setopt($cSession, CURLOPT_URL, $url);
curl_setopt($cSession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cSession, CURLOPT_HEADER, false);
curl_setopt($cSession, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($cSession, CURLOPT_POSTFIELDS, $data);
curl_setopt($cSession, CURLOPT_SSL_VERIFYPEER, false);
$headers[] = 'Content-Type: application/json';
curl_setopt($cSession, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($cSession);
curl_close($cSession);
?>

List Sources

Use this endpoint to view all the lead sources on your account.

URL
https://system.leadtrekker.com/api/sources
Response
Property Type Description
Sources Array All the sources linked to your account. -

List Sources Example

<?php
$headers = array();
$Apikey = 'A1B2C3D4E5F6G7H8I9';
$url = 'https://system.leadtrekker.com/api/sources';

$cSession = curl_init();
$headers[] = 'Apikey:' . $Apikey;
curl_setopt($cSession, CURLOPT_URL, $url);
curl_setopt($cSession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cSession, CURLOPT_HEADER, false);
curl_setopt($cSession, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($cSession, CURLOPT_POSTFIELDS, $data);
curl_setopt($cSession, CURLOPT_SSL_VERIFYPEER, false);
$headers[] = 'Content-Type: application/json';
curl_setopt($cSession, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($cSession);
curl_close($cSession);
?>

Update Statuses

Use this endpoint to update the status of an existing lead.

URL
https://system.leadtrekker.com/api/updatestatus
Required Parameters
Property Type Description Default
statusid Base64 encoded integer The id of the lead. -
leadid Base64 encoded integer The id of the lead. -
Response
Property Type Description
Response Text String The status of the request. A successful request returns OK. -

Update Statuses Example

<?php
$headers = array();
$Apikey = 'A1B2C3D4E5F6G7H8I9';
$url = 'https://system.leadtrekker.com/api/updatestatus';

$data = array(
  'leadid' => base64_encode(12345),
  'statusid' => base64_encode(2)  
  ); 

$data = json_encode($data);

$cSession = curl_init();
$headers[] = 'Apikey:' . $Apikey;
curl_setopt($cSession, CURLOPT_URL, $url);
curl_setopt($cSession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cSession, CURLOPT_HEADER, false);
curl_setopt($cSession, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($cSession, CURLOPT_POSTFIELDS, $data);
curl_setopt($cSession, CURLOPT_SSL_VERIFYPEER, false);
$headers[] = 'Content-Type: application/json';
curl_setopt($cSession, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($cSession);
curl_close($cSession);
?>