我有一个功课,现在不怎么做。我需要连接vtiger rest api并显示一些字段,但不知道该怎么做。也许有人有一些代码示例或类似的东西?我已阅读文档,但不了解如何连接和抓取字段。有人帮忙吗?
答案 0 :(得分:0)
您可以使用以下示例代码。有关更多信息,请阅读webservice文档! https://wiki.vtiger.com/index.php/Webservices_tutorials
function callvtiger($url, $params, $type = "GET")
{
$is_post = 0;
if ($type == "POST") {
$is_post = 1;
$post_data = $params;
} else {
$url = $url . "?" . http_build_query($params);
}
$ch = curl_init($url);
if (!$ch) {
die("Cannot allocate a new PHP-CURL handle");
}
if ($is_post) {
curl_setopt($ch, CURLOPT_POST, $is_post);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$return = null;
if (curl_error($ch)) {
$return = false;
} else {
$return = json_decode($data, true);
}
curl_close($ch);
return $return;
}
$userName = "admin";
$userAccessKey = "bjwedjndwejndwjnd";
$Url = 'http://vtigerurl/webservice.php';
$sessionData = callvtiger($Url, array(
"operation" => "getchallenge",
"username" => $userName
));
$challengeToken = $sessionData['result']['token'];
$generatedKey = md5($challengeToken . $userAccessKey);
$dataDetails = call($endpointUrl, array(
"operation" => "login",
"username" => $userName,
"accessKey" => $generatedKey
), "POST");
$sessionid = $dataDetails['result']['sessionName'];
$phoneNumber = "0014242222222";
$query = "SELECT accountname,id FROM Accounts where phone = '$phoneNumber'";
$getUserDetail = callvtiger($Url, array(
"operation" => "query",
"sessionName" => $sessionid,
'query' => $query
));
$response = $getDetail['result'][0];