У меня проблема с веб-сервисом vtiger. Любое тело, пожалуйста, помогите мне разобраться с этим. Я получаю эту ошибку «Запрос не выполнен: в разрешении на выполнение операции для имени отказано» в запросе веб-службы vtiger, с помощью которого я хочу перечислить одну из записей модуля.
Мой код:
<?php
require_once("../vtlib/Vtiger/Net/Client.php");
require_once("../include/Zend/Json.php");
class CRMwebrequests {
var $endpointUrl;
var $userName;
var $userKey;
var $token;
function __construct($url, $name, $key) {
$this->endpointUrl=$url;
$this->userName=$name;
$this->userKey=$key;
$this->token=0;
}
function getChallenge() {
$httpc = new Vtiger_Net_Client($this->endpointUrl);
$params["operation"]="getchallenge";
$params["username"]=$this->userName;
$response = $httpc->doGet($params);
$httpc->disconnect();
$jsonResponse = Zend_JSON::decode($response);
if($jsonResponse["success"]==false)
die("getChallenge failed:".$jsonResponse["error"]["message"]."<br>");
$challengeToken = $jsonResponse["result"]["token"];
return $challengeToken;
}
function Login() {
$token = $this->getChallenge();
$generatedKey = md5($token.$this->userKey);
$httpc = new Vtiger_Net_Client($this->endpointUrl);
//POST containing array
$response = $httpc->doPost(
array("operation"=>"login", "username"=>$this->userName,
"accessKey"=>$generatedKey));
$httpc->disconnect();
$jsonResponse = Zend_JSON::decode($response);
if($jsonResponse["success"]==false) {
die("Login failed:".$jsonResponse["error"]["message"]."<br>Token:".$token."<br>");
}
$sessionId = $jsonResponse["result"]["sessionName"];
//save session id
$this->token=$sessionId;
//25765819bac6eb068
return true;
}
function Query($query) {
//handle "special" characters
$queryParam = ($query);
$params = array("sessionName"=>$this->token,"operation"=>"query", "query"=>$queryParam);
$httpc = new Vtiger_Net_Client($this->endpointUrl);
$response = $httpc->doGet($params);
$jsonResponse = Zend_JSON::decode($response);
echo "<pre>";
print_r($jsonResponse);
if($jsonResponse["success"]==false) {
die("Query failed:".$jsonResponse["error"]["message"]);
}
//Array of retrieved objects
$retrievedObjects = $jsonResponse["result"];
return $retrievedObjects;
}function delete($id){
$params = array("sessionName"=>$sessionId, "operation"=>'delete', "id"=>$id);
//delete operation request must be POST request.
$httpc = new Vtiger_Net_Client($this->endpointUrl);
$response = $httpc->doPost($params);
$jsonResponse = Zend_JSON::decode($response);
if($jsonResponse['success']==false){
die('delete failed:'.$jsonResponse['error']['errorMsg']);
}
//Array of retrieved objects
$retrievedObjects = $jsonResponse["result"];
return $retrievedObjects;
}
function LogOut() {
$params = array("operation"=>"logout","sessionName"=>$this->token);
$httpc = new Vtiger_Net_Client($this->endpointUrl);
$response = $httpc->doGet($params);
$jsonResponse = Zend_JSON::decode($response);
if($jsonResponse["success"]==false) {
//handle the failure case.
die("Logout failed:".$jsonResponse["error"]["message"]);
}
return true;
}
}
$CRMurl = 'http://localhost/vtigercrm';
$APPkey = 'R6JNLCLkjCFTm44b';
$crmobject = new CRMwebrequests($CRMurl."/webservice.php", "admin", $APPkey);
if ($crmobject->Login()) {
$wsquery = "SELECT * FROM vtiger_account";
$Details = $crmobject->Query($wsquery);echo "<b>Accounts</b><br>";
echo "<table border='1'>";
echo "<tr>";
echo "<th>Account No</th>";
echo "<th>Accoun Name</th>";
echo "<th>Account Type</th>";
echo "<th>Industry</th>";
echo "<th>Ownership</th>";
echo "</tr>";
foreach ($Details as $value){
echo "<tr>";
echo "<td>".$value["account_no"]."</td>";
echo "<td>".$value["accountname"]."</td>";
echo "<td>".$value["account_type"]."</td>";
echo "<td>".$value["industry"]."</td>";
echo "<td>".$value["ownership"]."</td>";
echo "</tr>";
}
echo "</table></br>";
}
else {
echo "Error!";
}
?>
Вы не должны использовать реальное имя таблицы БД для запроса «SQL», а только имя модуля, подобное этому:
$query = "SELECT * FROM accounts;";
or
$query = "SELECT * FROM Contacts WHERE lastname='Valiant';";
Других решений пока нет …