This is just a PHP script I have written to read leads data from MYSQL and import them to OSDIAL . Maybe usefull for others . First Im creating XML and them using CURL to send data to OSDIAL API via POST method . you may want to read this post for adding Leads to OSDIAL as well .
<?php
error_reporting(E_ALL);
$url = "https://192.168.0.8/admin/api.php";
$now=date("Y-m-d H:i:s");
$servername = "localhost";
$username = "root";
$password = "mydbPassword";
$dbname = "OSDIALVTIGER";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * from Leads WHERE vtiger_to_osdial is NULL";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$log = date("h:i:sa"). " ListID : " . $row["ListID"]. " - Name: " . $row["Name"] . " - HP: " . $row["HP"] . " - Office: " . $row["Office"] . " - Home: " . $row["Home"] . " - Gender: " . $row["Gender"] . " - Age: " . $row["Age"] . " - Race: " . $row["Race"] . " - DOB: " . $row["DOB"] ."\n";
echo $log;
$vendor_lead_code = $row["id"] ;
$list_id = $row["ListID"] ;
$last_name = $row["Name"];
$phone_number = $row["HP"];
$alt_phone = $row["Office"];
$Gender = $row["Gender"];
$custom1 = $row["Age"];
$custom2 = $row["Race"] ;
$date_of_birth =str_replace("/","-", $row["DOB"]);
file_put_contents('./Logs/Vtiger_to_OSdial_log_'.date("j.n.Y").'.txt', $log, FILE_APPEND);
$xmlReq = new SimpleXMLElement('<api><params></params></api>');
# Username and Password for API access
$xmlReq['user'] = 'admin';
$xmlReq['pass'] = 'myapipass';
$xmlReq['function'] = 'add_lead';
$xmlReq['mode'] = 'admin';
$xmlReq['vdcompat'] = '0';
$xmlReq['test'] = '0';
$xmlReq['debug'] = '0';
# Parameters / DataControl - These flags change how the lead is validated and how to act on it.
$xmlReq->params->dnc_check = 'Y';
$xmlReq->params->duplicate_check = 'NO';
$xmlReq->params->gmt_lookup_method = 'AREACODE';
$xmlReq->params->add_to_hopper = 'Y';
$xmlReq->params->hopper_priority = '50';
$xmlReq->params->hopper_local_call_time_check = 'N';
$xmlReq->params->hopper_campaign_call_time_check = 'N';
# Parameters / ListData - Variables that apply to every lead loaded in this list.
$xmlReq->params->list_id = "$list_id"; # The list_id should exist and be assigned to a campaign.
$xmlReq->params->vendor_lead_code = "$vendor_lead_code"; # Use this so you can later identify what vendor the leads came from.
$xmlReq->params->source_id = 'VTIGER'; # The lead source ? Web/ Email/ Mail/ Phone...
$xmlReq->params->phone_code = '1';
$xmlReq->params->status = 'NEW';
# Parameters / LeadData - The Actual lead data.
$xmlReq->params->external_key = '123123';
$xmlReq->params->phone_number = "$phone_number";
$xmlReq->params->first_name = "$last_name";
$xmlReq->params->last_name = "$last_name";
$xmlReq->params->Gender = "$Gender";
$xmlReq->params->custom1 = "$custom1";
$xmlReq->params->custom2 = "$custom2";
$xmlReq->params->date_of_birth = "$date_of_birth";
$xmlReq->params-> alt_phone = "$alt_phone";
$xml = array('xml' => $xmlReq->asXML());
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
$output = curl_exec($ch);
print_r($output);
curl_close($ch);
$conn->query("UPDATE Leads SET vtiger_to_osdial = \"$now\" ");
}
}
?>
Comments
Post a Comment