webservice.php Vtiger update查询字符串php curl post


webservice.php Vtiger update Query String php curl post

是否有人知道如何在vtiger中正确格式化更新查询以更新Leads模块下的记录?

我一直在遵循这个:http://community.vtiger.com/help/vtigercrm/developers/third-party-app-integration.html

和已经能够登录,查询,并做挑战响应,但我一直无法获得更新功能的工作,这可能是因为我不确定他们想要查询的样子。这是我发送查询时得到的错误:

stdClass Object ( [success] => [error] => stdClass Object ( [code] => ACCESS_DENIED [message] => Permission to perform the operation is denied for id ) )   

当前测试代码:

function updatesomeone(){
global $createduserleadnum;
global $url;
global $sessionID;
global $createduserid;

$customdata = array(
'firstname'=> 'TestAPILead2',//Update First name
'lastname'=> 'TestAPILeadLast2', //Updated Last name
'leadstatus'=> 'New',
'leadsource'=> 'Some Lead Source', //Not Real Lead source
'assigned_user_id'=> 'User-Assigned', //not real user
'cf_755'=> 'A Custom Field', // A Custom Field
'lead_no' => $createduserleadnum, Acquired from other function/stored value
);
$customdata = json_encode($customdata);
$field = array(
'operation' => 'update',
'sessionName'=> $sessionID,
'element' => $customdata
);

$fields_string;
foreach($field as $key=>$value) { global $fields_string;
$fields_string .= $key.'='.$value.'&'; }
$ch = curl_init();

curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($field));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
$pringjson = json_decode($result);
print_r($pringjson);

}

明白了。它与$fieldstring变量有关。由于某些原因,它没有停留在函数的局部,所以它包含了一些其他变量。只是改变了字段字符串变量与一个数字在结束。在最后的代码中,我将编写一个更好的脚本来对变量进行url化。我还必须使用给定的完整id。无论哪种方式,现在都解决了,代码正常工作。

我对你的代码有一个建议。你没有移除&在"foreach"循环结束后生成。因此,只需在foreach之后添加rtrim,并将$fields_string变量定义为空白。

$fields_string = '';
foreach($field as $key=>$value) {
     global $fields_string;
     $fields_string .= $key.'='.$value.'&'; 
}
rtrim($fields_string, '&');