首页 > 解决方案 > 从 Zoho APIv1 升级到 APIV2 -> 请求不保存数据

问题描述

我正在将我的客户网站从 Zoho 的生命周期结束 v1 API 升级到它的新 v2 API。

我已按照指南进行操作,但无法请求在 Zoho 系统中创建新的“潜在客户”存档。

我已经“正确”安装了 v2 API(没有错误,并且验证正确),但要插入新的潜在客户。

运行 v1 代码有效,所以我相信该帐户仍然可以。它在一个测试域上,但我没有看到任何可能限制这一点的地方。

v1 API 代码:

$xml  = '<?xml version="1.0" encoding="UTF-8"?>'; // same error with or without this line
$xml .= '<Leads>';
$xml .= '<row no="1">';
$xml .= '<FL val="Lead Owner">'.'luke@example.com'.'</FL>';
$xml .= '<FL val="First Name">'.$_POST['enquiry-firstname'].'</FL>';
$xml .= '<FL val="Last Name">'.$_POST['enquiry-lastname'].'</FL>';
$xml .= '<FL val="Email">'.$_POST['enquiry-email'] .'</FL>';
$xml .= '<FL val="Company">'.$_POST['enquiry-company'].'</FL>';
$xml .= '<FL val="Lead Source">Web Site</FL>';
$xml .= '<FL val="Phone">'.$_POST['enquiry-phone'].'</FL>';
$xml .= '<FL val="Description">
            Enquiry Type: ' . htmlentities($_POST['enquiry-enquiry'], ENT_QUOTES | ENT_IGNORE, "UTF-8") . '
            Message: '.htmlentities($_POST['enquiry-message'], ENT_QUOTES | ENT_IGNORE, "UTF-8") . '
            Board: ' . $zoho_descr;
$xml .= '</FL>';
$xml .= '</row>';
$xml .= '</Leads>';

$url ="https://crm.zoho.com/crm/private/xml/Leads/insertRecords";
$query="authtoken=<secret>&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);// Set the request as a POST FIELD for curl.

$response = curl_exec($ch);
curl_close($ch);

我已经修改为在 v2 中工作:** EDIT ** 将其更改为与文档匹配。字段值更改为 API 值。

require_once('vendor/autoload.php');

ZCRMRestClient::initialize();

try {
    $moduleIns = ZCRMRestClient::getInstance()->getModuleInstance("Leads");

    $leads = array();

    $lead = ZCRMRecord::getInstance("Leads", null);
    $lead->setFieldValue("Owner", "luke@example.com");
    $lead->setFieldValue("First_Name", $_POST['enquiry-firstname']);
    $lead->setFieldValue("Last_Name", $_POST['enquiry-lastname']);
    $lead->setFieldValue("Email", $_POST['enquiry-email']);
    $lead->setFieldValue("Company", $_POST['enquiry-company']);
    $lead->setFieldValue("Lead_Source", "Web Site");
    $lead->setFieldValue("Phone", $_POST['enquiry-phone']);
    $lead->setFieldValue("Description",  "Enquiry Type: " . htmlentities($_POST['enquiry-enquiry'], ENT_QUOTES | ENT_IGNORE, "UTF-8") . ' Message: '.htmlentities($_POST['enquiry-message'], ENT_QUOTES | ENT_IGNORE, 'UTF-8') . '  Board: ' . $zoho_descr);
    array_push($leads, $lead);

    $responseIn = $moduleIns->createRecords($records);

    foreach($responseIn->getEntityResponses() as $responseIns){
        echo "HTTP Status Code:".$responseIn->getHttpStatusCode();
        echo "Status:".$responseIns->getStatus();
        echo "Message:".$responseIns->getMessage();
        echo "Code:".$responseIns->getCode();
        echo "Details:".json_encode($responseIns->getDetails());
    }       
    echo "<pre>";
    var_dump($responseIn);
    echo "</pre>";
    die("Should be fine");
} catch (ZCRMException $e) {
    echo $e->getCode();
    echo $e->getMessage();
    echo $e->getExceptionCode();
    die("ZCRM Exception Dead");
} catch (Exception $e) {
    echo "<pre>";
    echo $e->getMessage();
    echo "</pre>";
    die("Exception Dead");
}   

** 编辑 **

$responseIn 返回:

object(BulkAPIResponse)#1161 (12) {
  ["bulkData":"BulkAPIResponse":private]=>
  array(0) {
  }
  ["status":"BulkAPIResponse":private]=>
  NULL
  ["info":"BulkAPIResponse":private]=>
  NULL
  ["bulkEntitiesResponse":"BulkAPIResponse":private]=>
  NULL
  ["httpStatusCode":"CommonAPIResponse":private]=>
  int(0)
  ["responseJSON":"CommonAPIResponse":private]=>
  NULL
  ["responseHeaders":"CommonAPIResponse":private]=>
  array(0) {
  }
  ["code":"CommonAPIResponse":private]=>
  NULL
  ["message":"CommonAPIResponse":private]=>
  NULL
  ["details":"CommonAPIResponse":private]=>
  NULL
  ["response":"CommonAPIResponse":private]=>
  bool(false)
  ["apiName":"CommonAPIResponse":private]=>
  NULL
}

运行 v2 代码会产生一个“已完成”的消息,因此直接没有错误,但仪表板中没有任何结果,更有趣的是 API 使用报告显示没有发送任何内容(但它确实显示了身份验证请求,所以我相信它已连接)。

如何通过 v2 API 向 Zoho 发送“潜在客户”?

** 编辑 ** 将字段名称更新为 API 名称。

标签: zoho

解决方案


在我看来,你的属性放错了。而不是“姓氏”,您应该输入“姓氏”。


推荐阅读