Sample Code

Code Example: Creating a New Sales Lead

To make getting started easy, we have an example php script which connects to our API in order to create a new lead in the leads app. The script has a basic contact form for a website, which does a postback in order to submit the form data via the API using the “createLeadWithLeadSource” method.

Example Php Code

Download the script

/*
* Define the Config Values
*/

@ini_set('display_errors',0);

$apptivoLeadWSDL ='https://api.apptivo.com/app/services/v1/BusinessSiteServices?wsdl'; // Apptivo BusinessSiteServices API url

$apptivoSiteKey = ''; // Define your Sitekey obtained from Apptivo

$apptivoAccessKey = ''; // Define your Access obtained from Apptivo

/*
* Check whether it is a form post action. if it is form post and it has values set for lastname and email. process the Post action
* Get the Lead details and store the values in array. We can send various details to apptivo with below the fields
*/

if(isset($_POST['lastname']) && ($_POST['email'] != '')) {

$leadDetails = array();

$leadDetails['firmId'] = null;

$leadDetails['firstName'] = $_POST['firstname'];

$leadDetails['lastName'] = $_POST['lastname'];

$leadDetails['emailId'] = $_POST['email'];

$leadDetails['jobTitle'] = null;

$leadDetails['company'] = null;

$leadDetails['address1'] = null;

$leadDetails['address2'] = null;

$leadDetails['city'] = null;

$leadDetails['state'] = null;

$leadDetails['zipCode'] = null;

$leadDetails['bestWayToContact'] = null;

$leadDetails['country'] = $_POST['country'];

$leadDetails['leadSource'] = 'Contact Form Lead'; // this is used to separate the leads in Apptivo Leads App

$leadDetails['phoneNumber']= $_POST['phone'];

$leadDetails['comments'] = null;

$leadDetails['noteDetails'] = null;

$leadDetails['targetListId'] = null; // this values is used to collect the data into Apptivo TargetList App

$leadDetails['images'] = null;

$leadDetails['statusCode'] = null;

$leadDetails['statusMessage'] = null;

$client = new SoapClient($apptivoLeadWSDL); // Create SOAP object -- Make sure we have soap client installed in PHP

/* create an array for method inputs */

$params = array (
"arg0" => $apptivoSiteKey, // Apptivo siteKey
"arg1" => $apptivoAccessKey, // Apptivo SiteAccess Key
"arg2" => $leadDetails, // Lead Details data array
);

try {
/* Call Apptivo Services with lead data*/

$response = $client->__soapCall('createLeadWithLeadSource', array($params));
// 'createLeadWithLeadSource' is the Apptivo web service method name
}

catch (Exception $e) {
// display error message while calling apptivo services

print_r($e->getMessage());
}

$value = $response->return;

}