提前致谢,郑重声明,这与洪水无关。该请求必须通过 cURL 提供。
问题:
1- 获取与 $criteria 匹配的联系人的请求将返回 ZohoBooks 中的所有联系人,而不是包含该字符串的联系人。
这意味着 $criteria 不会显示匹配的“contact_names”。它把他们都带来了。
2-我 90% 确信问题出在我构建 $url 的方式上,但是在 zoho.com/books/api/v3/contacts/ 上进行的大量阅读或使用 POSTman 都没有给我任何关于如何更好的想法正确通过过滤器。
... $criteria = "(contact_name:contains:'" . urlencode($contactName) . "')"; //***this is an update from previous post*** $url = "https://www.zohoapis.com/books/v3/contacts?organization_id=$organizationId&criteria=$criteria"; logMessage("Initiating cURL request to URL: $url");
如果重要的是我的其余代码:
<?php
include_once '../../zoho_refresh.php';
date_default_timezone_set('America/Panama');
error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('log_errors', 1);
ini_set('error_log', __DIR__ . '/call_to_name_validator_zoho.log');
$logFile = __DIR__ . '/call_to_name_validator_zoho.log';
function errorHandler($errno, $errstr, $errfile, $errline) {
global $logFile;
$date = date('Y-m-d H:i:s');
$errorMessage = "[{$date}] Error: {$errno}: {$errstr} in {$errfile} on line {$errline}\n";
error_log($errorMessage, 3, $logFile);
echo "An error occurred. Please try again later.";
}
set_error_handler("errorHandler");
function logMessage($message) {
global $logFile;
$timeStamp = date('Y-m-d H:i:s');
$logEntry = "[{$timeStamp}] $message\n---------------------------------------------\n";
error_log($logEntry, 3, $logFile);
}
logMessage("Validator executed");
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['contact_name']) && !empty($_POST['contact_name'])) {
$contactName = $_POST['contact_name'];
logMessage("Contact name received: $contactName");
$accessToken = getAccessToken();
logMessage("Access token retrieved: $accessToken");
$organizationId = '##########';
$criteria = "(contact_name:contains:'" . urlencode($contactName) . "')"; //*** This is an update from original post ***
$url = "https://www.zohoapis.com/books/v3/contacts?organization_id=$organizationId&criteria=$criteria";
logMessage("Initiating cURL request to URL: $url");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Zoho-oauthtoken ' . $accessToken,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if ($err) {
logMessage("cURL error: $err");
echo json_encode(['status' => 'error', 'message' => $err]);
} else {
logMessage("Zoho response: $response");
$result = json_decode($response, true);
if (isset($result['contacts'])) {
$contacts = array_map(function ($contact) {
return [
'contact_name' => $contact['contact_name'],
'customer_name' => $contact['customer_name'] ?? null,
'email' => $contact['email'] ?? null,
];
}, $result['contacts']);
echo json_encode(['status' => 'success', 'contacts' => $contacts]);
} else {
echo json_encode(['status' => 'error', 'message' => 'No contacts found']);
}
}
} else {
logMessage("No or invalid contact name provided");
echo json_encode(['status' => 'error', 'message' => 'No or invalid contact name provided']);
}
?>
我尝试过的
**每次,我收到的回复都是前 200 个联系人(根据 Zoho Books 限制),所以我确信它会忽略 &criteria=$criteria" 部分。**
我所期待的
然而我的期望是获得“包含”“标准”的联系人。例如,如果我在搜索框中输入 Fu...,它应该会列出所有包含 Fu 或 fu .... 的客户端,例如法兰克福机场 Rosa Kuchen Corp.、有趣的是我总是把它拧在简单的部分上、Fushin显示我,Sei Fuori Dal Gioco...
我认为问题所在
我愿意打赌,问题是我不知道向 ZohoBooks 传递正确标准以获取与提供的字符串匹配的字段的正确方法是什么。
$url = "https://www.zohoapis.com/books/v3/contacts?organization_id=$organizationId&criteria=$criteria";
这就是解决方案:
$url = "https://www.zohoapis.com/books/v3/contacts?organization_id=" 。 $organizationId 。 “&contact_name_startswith=”。 $contactName;