简体   繁体   中英

“Query failed:Permission to perform the operation is denied for name” in vtiger webservice query through which I want to list one of module records

I am getting an issue in vtiger webservice. Can any body please help me to sort this out. I am getting this error "Query failed:Permission to perform the operation is denied for name" in vtiger webservice query through which I want to list one of module records.

My Code is:

<?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!";
 }
?>

You should not use the real DB table name for your "SQL" query but only the module name like that:

$query = "SELECT * FROM accounts;";
or
$query = "SELECT * FROM Contacts WHERE lastname='Valiant';";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM