これは私のために働いています。私は2つの方法を書いた。 1つは認証キーを取得し、もう1つは連絡先を作成するためのものです。
<?php
class zoho{
public function getAuth()
{
$username = "[email protected]";
$password = "yourpassword";
$param = "SCOPE=ZohoCRM/crmapi&EMAIL_ID=".$username."&PASSWORD=".$password;
$ch = curl_init("https://accounts.zoho.com/apiauthtoken/nb/create");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
$result = curl_exec($ch);
/*This part of the code below will separate the Authtoken from the result.
Remove this part if you just need only the result*/
$anArray = explode("\n",$result);
$authToken = explode("=",$anArray['2']);
$cmp = strcmp($authToken['0'],"AUTHTOKEN");
echo $anArray['2'].""; if ($cmp == 0)
{
echo "Created Authtoken is : ".$authToken['1'];
return $authToken['1'];
}
curl_close($ch);
}
public function postData($auth, $fornavn,$efternavn, $email,$addr,$by,$postnr,$land,$kommentar)
{
$xml =
'<?xml version="1.0" encoding="UTF-8"?>
<Contacts>
<row no="1">
<FL val="First Name">'.$fornavn.'</FL>
<FL val="Last Name">'.$efternavn.'</FL>
<FL val="Email">'.$email.'</FL>
<FL val="Department">'.$land.'</FL>
<FL val="Phone">999999999</FL>
<FL val="Fax">99999999</FL>
<FL val="Mobile">99989989</FL>
<FL val="Assistant">none</FL>
</row>
</Contacts>';
$url ="https://crm.zoho.com/crm/private/xml/Contacts/insertRecords";
$query="authtoken=".$auth."&scope=crmapi&newFormat=1&xmlData=".$xml;
$ch = curl_init();
/* set url to send post request */
curl_setopt($ch, CURLOPT_URL, $url);
/* allow redirects */
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
/* return a response into a variable */
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
/* times out after 30s */
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
/* set POST method */
curl_setopt($ch, CURLOPT_POST, 1);
/* add POST fields parameters */
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);// Set the request as a POST FIELD for curl.
//Execute cUrl session
$response = curl_exec($ch);
curl_close($ch);
echo $response;
}
}
?>
このような
使用:
<?php
include('zoho.php');
$zoho = new zoho();
echo "testing....<br />";
$auth = $zoho->getAuth();
echo " <pre>";
echo $auth;
$result = $zoho->postData($auth, 'Bob','test', '[email protected]','adresse','by','postr','Danmark','Some comment');
print_r($result);
?>
Imはまだあなたが連絡先のアドレス情報を挿入する必要があるXMLの種類に取り組んでいます。
$ authtoken = "7d3e4882977bb4ec00b457cb3292196"; $です。xmlData =」 スコット ジェームズ・ [email protected] CG 999999999 99999999 99989989 John
'; $ query = "newFormat = 1&authtoken = {$ authtoken}&scope = crmapi&xmlData = {$ xmlData}"; curl_setopt($ ch、CURLOPT_POSTFIELDS、$ query); $応答= curl_exec($ ch); echo $ response; curl_close($ ch); –
user1525978