Zoho Crm

This is our file, which will be used for api call & authentication

zoho.php file

<?php
class zoho{

public  $username;
public  $password;

public function getAuth()
{
$param = “SCOPE=ZohoCRM/crmapi&EMAIL_ID=”.$this->username.”&PASSWORD=”.$this->password;
$ch = curl_init(“https://accounts.zoho.com/apiauthtoken/nb/create&#8221;);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
$result = curl_exec($ch);

$anArray     = explode(“\n”,$result);
$authToken  = explode(“=”,$anArray[‘2’]);
$cmp = strcmp($authToken[‘0’],”AUTHTOKEN”);
echo $anArray[‘2’].””; if ($cmp == 0)
{
return $authToken[‘1′];
}
curl_close($ch);
}

public function postData($auth, $firstName,$lastName, $email,$address,$phone,$fax,$mobile)
{
$xml =’
<contacts>
<row no=”1″>
<fl val=”First Name”>’.$firstName.'</fl>
<fl val=”Last Name”>’.$lastName.'</fl>
<fl val=”Email”>’.$email.'</fl>
<fl val=”Department”>’.$address.'</fl>
<fl val=”Phone”>’.$phone.'</fl>
<fl val=”Fax”>’.$fax.'</fl>
<fl val=”Mobile”>’.$mobile.'</fl>
</row>
</contacts>’;

$url =”https://crm.zoho.com/crm/private/xml/Contacts/insertRecords&#8221;;
$query=”authtoken=”.$auth.”&scope=crmapi&newFormat=1&xmlData=”.$xml;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
$response = curl_exec($ch);
curl_close($ch);
echo $response;

}
}

?>

 

Now lets call the file

add.php

<?php
include(‘zoho.php’);
$zoho = new zoho();
$zoho->username=’your_email_address’;
$zoho->password=’your_phone_number’;
$auth = $zoho->getAuth();
$result = $zoho->postData($auth, ‘Mamnun’,’Rashid’, ‘mamun@naz.com’,’Address’,’0170000′,’Fax-11111′,’M-0171111′);
print_r($result);
?>

 

its simple

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s