gpt4 book ai didi

api - 使用 PHP 通过 API 将记录插入到 Zoho CRM

转载 作者:行者123 更新时间:2023-12-05 09:24:39 26 4
gpt4 key购买 nike

我认为使用 get_file_contents 函数可以让我像执行过去使用的其他 API 一样执行 API。但是,这种方法不适用于 Zoho CRM API - 可能是因为我传递的是 XML 数据而不是 RESTful 查询?

API 文档位于 http://zohocrmapi.wiki.zoho.com/insertRecords-Method.html

当通过网络浏览器地址栏传递它时,它起作用了:

https://crm.zoho.com/crm/private/xml/Contacts/insertRecords?authtoken=Auth Token&scope=crmapi
&newFormat=1
&xmlData=
<Contacts>
<row no="1">
<FL val="First Name">Scott</FL>
<FL val="Last Name">James</FL>
<FL val="Email">test@test.com</FL>
<FL val="Department">CG</FL>
<FL val="Phone">999999999</FL>
<FL val="Fax">99999999</FL>
<FL val="Mobile">99989989</FL>
<FL val="Assistant">John</FL>
</row>
</Contacts>

使用 file_get_contents 运行时我没有收到任何错误。有谁知道我需要做什么才能让它工作?

最佳答案

这对我有用。我写了2个方法。一个用于获取授权 key ,一个用于创建联系人。

<?php 
class zoho{

public function getAuth()
{
$username = "youremail@mail.com";
$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', 'lol@lol.dk','adresse','by','postr','Danmark','Some comment');
print_r($result);
?>

我仍在研究您需要哪种 XML 来插入联系人的地址信息。

关于api - 使用 PHP 通过 API 将记录插入到 Zoho CRM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9959449/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com