1

I am trying to call a vtiger webservice using PHP CURL like this.

$selectQuery = urlencode("SELECT title,firstname,lastname FROM Contacts;");
            $curl = curl_init($data['url'].'/webservice.php?operation=query&sessionName='.$this->sessionName.'&query='.$selectQuery); 
            curl_setopt($curl, CURLOPT_FAILONERROR, true); 
            curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json'));
            curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0");
            curl_setopt($curl, CURLINFO_HEADER_OUT, true);
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);   
            $query = curl_exec($curl); 
            //$query = json_decode($query);
            print_r($query);

but i am getting the error

error:The requested URL returned error: 406 Not Acceptable

I am just doing all the process as mentioned in the below url

http://community.vtiger.com/help/vtigercrm/developers/third-party-app-integration.html#list-types-operation

Anybody knows the solution for the same ?

Punit Gajjar
  • 4,937
  • 7
  • 35
  • 70

1 Answers1

-1

Hi Root ingenious please try

my code

$endURL = 'http://192.168.192.140/vtigercrm71'; //use ur url
$userName = 'admin'; //use ur username
$userAccessKey = 'h3fNwMr0Nc2hNQOL'; //use ur useraccesskey

$url = $endURL . '/webservice.php?operation=getchallenge&username=' . $userName;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, 0);
$output = curl_exec($ch);
curl_close($ch);
$res = json_decode($output);
$challengeToken = $res->result->token;

$generatedKey = md5($challengeToken . $userAccessKey);
$params = array(
    "operation" => 'login',
    "username" => $userName,
    "accessKey" => $generatedKey,
);

$postData = '';
foreach ($params as $k => $v) {
      $postData .= $k . '=' . $v . '&';
}
$postData = rtrim($postData, '&');
$url = $endURL . '/webservice.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, count($postData));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$output = curl_exec($ch);
curl_close($ch);
$res = json_decode($output);

$sessionName = $res->result->sessionName;
$userId = $res->result->userId;

$domain_name = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
$selectQuery = urlencode("SELECT title,firstname,lastname FROM Contacts;");
$url = $endURL . '/webservice.php?operation=query&query=' . $selectQuery . '&sessionName=' . $sessionName;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, 0);
$output = curl_exec($ch);
curl_close($ch);
$res = json_decode($output);
echo "<pre>";
print_r($res);
exit;

result

stdClass Object
(
    [success] => 1
    [result] => Array
        (
            [0] => stdClass Object
                (
                    [title] => 
                    [firstname] => asdfas
                    [lastname] => dfdsafdsf
                    [id] => 12x3
                )

        )

)