使用CURL从CRM API抛出错误中提取数据



我必须与我们公司正在使用的CRM集成,Snapforce CRM。我只是想使用他们在文档上的示例代码拉数据,但它返回一个错误:

Error: Cannot create object

我直接从他们的api文档中复制的示例脚本。

这是我到目前为止的脚本,我几乎完全复制了它。

$url = 'https://crm.snapforce.com/vintage/sf_receive_request.inc.php';
$curl = curl_init($url);
$fetchRecords = "format=xml&api_user=$api_user&api_key=$api_key&module=Leads&status=Active&method=fetchRecords";
curl_setopt($curl, CURLOPT_FAILONERROR, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 5);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POST_FIELDS, $fetchRecords);
$r = curl_exec($curl);
curl_close($curl);
libxml_use_internal_errors(true);
$xml = simplexml_load_string($r) or die("Error: Cannot create object");
foreach ($xml as $xml1) {
echo $xml1->lead_id."n";
echo $xml1->type."n";
echo $xml1->website."n";
echo $xml1->contact_first."n";
}

这是一个问题,我如何尝试通过对象循环或我错过了一个settopt与CURL可能?如有任何建议,不胜感激。

CURLOPT_POST_FIELDS不是一个有效的选项,它是CURLOPT_POSTFIELDS

最新更新