Last active
December 13, 2016 23:43
-
-
Save jarodium/a76115da1e8acbc1d238 to your computer and use it in GitHub Desktop.
Zoho CRM API Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
class ZOHO { | |
private $U = ""; | |
private $P = ""; | |
protected $BURL = 'https://crm.zoho.com/crm/private/xml/'; | |
protected $token = ""; | |
protected $pdata = array(); | |
public function __construct() { | |
$this->pdata = array("authtoken" => $this->token,"scope" => "crmapi"); | |
} | |
protected function xml2json($xml) { | |
$xml = str_replace(array("\n", "\r", "\t"), '', $xml); | |
$xml = trim(str_replace('"', "'", $xml)); | |
$simpleXml = simplexml_load_string($xml); | |
if (isset($simpleXml->nodata)) { | |
return array((int)$simpleXml->nodata->code => $this->dumpErro((int)$simpleXml->nodata->code)); | |
} | |
else if (isset($simpleXml->error)) { | |
return array((int)$simpleXml->error->code => $this->dumpErro((int)$simpleXml->error->code)); | |
} | |
else { | |
return json_encode($simpleXml); | |
} | |
} | |
protected function dumpErro($codigo) { | |
$erros = array( | |
"4000" => 'Please use Authtoken, instead of API ticket and APIkey.', | |
"4500" => 'Internal server error while processing this request', | |
"4501" => 'API Key is inactive', | |
"4502" => 'This module is not supported in your edition', | |
"4401" => 'Mandatory field missing', | |
"4600" => 'Incorrect API parameter or API parameter value. Also check the method name and/or spelling errors in the API url.', | |
"4820" => 'API call cannot be completed as you have exceeded the "rate limit".', | |
"4831" => 'Missing parameters error', | |
"4832" => 'Text value given for an Integer field', | |
"4834" => 'Invalid ticket. Also check if ticket has expired.', | |
"4835" => 'XML parsing error', | |
"4890" => 'Wrong API Key', | |
"4487" => 'No permission to convert lead.', | |
"4001" => 'No API permission', | |
"401" => 'No module permission', | |
"401.1" => 'No permission to create a record', | |
"401.2" => 'No permission to edit a record', | |
"401.3" => 'No permission to delete a record', | |
"4101" => 'Zoho CRM disabled', | |
"4102" => 'No CRM account', | |
"4103" => 'No record available with the specified record ID.', | |
"4422" => 'No records available in the module', | |
"4420" => 'Wrong value for search parameter and/or search parameter value.', | |
"4421" => 'Number of API calls exceeded', | |
"4423" => 'Exceeded record search limit', | |
"4807" => 'Exceeded file size limit', | |
"4424" => 'Invalid File Type', | |
"4809" => 'Exceeded storage space limit' | |
); | |
return $erros[$codigo]; | |
} | |
protected function insert($modulo,$data) { | |
$url = $this->BURL.$modulo."/insertRecords"; | |
$pdata = $this->pdata; | |
$pdata["xmlData"] = $data; | |
$pdata["newFormat"] = 1; | |
$x = $this->auxPost($url,$pdata,null,null,"POST"); | |
return $this->xml2json($x); | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Accounts extends ZOHO { | |
public function insertAccount($dados) { | |
$xml = '<Accounts> | |
<row no="1"> | |
<FL val="Account Name">'.$dados["nome"].'</FL> | |
<FL val="Rating">Active</FL> | |
<FL val="Phone">'.$dados["tlf"].'</FL> | |
<FL val="Website">'.$dados["site"].'</FL> | |
<FL val="Billing State">'.$dados["regiao"].'</FL> | |
<FL val="Billing Country">'.$dados["pais"].'</FL> | |
</row> | |
</Accounts>'; | |
$x = $this->insert(__CLASS__,$xml); | |
//para efeitos de log posso acrescentar mais coisas. | |
if (is_array($x)) { return $x; } | |
else { return true; } | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Contacts extends ZOHO { | |
public function insertContact($dados) { | |
//dd.MM.yyyy | |
$xml = '<Contacts> | |
<row no="1"> | |
<FL val="First Name">'.$dados["nome"].'</FL> | |
<FL val="Last Name">'.$dados["apelido"].'</FL> | |
<FL val="Phone">'.$dados["tlf"].'</FL> | |
<FL val="Email">'.$dados["email"].'</FL> | |
<FL val="Date of Birth">'.$dados["data_nasc"].'</FL> | |
<FL val="Mailing State">'.$dados["regiao"].'</FL> | |
<FL val="Mailing Country">'.$dados["pais"].'</FL> | |
</row> | |
</Contacts>'; | |
$x = $this->insert(__CLASS__,$xml); | |
//para efeitos de log posso acrescentar mais coisas. | |
if (is_array($x)) { return $x; } | |
else { return true; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment