Nico
Nico

Reputation: 326

Get result from vTiger webservice

I am writing a wordpress-plugin which queries data from the vTiger Webservice-API. I read the tutorial (https://wiki.vtiger.com/index.php/Webservices_tutorials#QueryResult) and know the reference (https://wiki.vtiger.com/index.php/Webservice_reference_manual). In the tutorial the use Zend-JSON and HTTP_Client. I use cURL (because it was installed and I thought it was worth a try to use before I install other utilities). It works quite well and I am able to Login to vTiger with our API-User and send the queries. What I receive is something like this:

array(2) {
  ["success"]=>
  bool(true)
  ["result"]=>
    array(4) {
    ["sessionName"]=>
    string(21) "4d103e2058f9d365c22ff"
    ["userId"]=>
    string(4) "19x9"
    ["version"]=>
    string(4) "0.22"
    ["vtigerVersion"]=>
    string(5) "6.5.0"
  }
}

Looks very good to me but the Thing I am missing is the actual data from my query.

This is my PHP-Code:

  $vtiger->initCurl();
  $challengeToken = $vtiger->getChallengeToken();
  $sessionId = $vtiger->getSessionId($challengeToken);
  $result = $vtiger->query($sessionId, "SELECT firstname FROM 'Contacts' WHERE lastname = 'XXX';");
  $wpdb->replace( $wpdb->prefix.$_CONFIG['dbtable'], array( 'id' => 1, 'syncfields' => $result), array('%d', '%s') );
  $vtiger->logout($sessionId);
  $vtiger->closeCurl();
  $result = json_decode($result, true);
  return var_dump(($result['success']) ? $result : "Error");

What am I missing to get the firstname (or any other value from the vTiger-DB)?

In the Code I am just writing the Response to the wp-db (extra-Table).

Thanks,

Nico

Upvotes: 1

Views: 1204

Answers (1)

Hamid
Hamid

Reputation: 398

Vtiger Result Return in array format. you should change your code

$vtiger->initCurl();
$challengeToken = $vtiger->getChallengeToken();
$sessionId = $vtiger->getSessionId($challengeToken);
$result = $vtiger->query($sessionId, "SELECT firstname FROM 'Contacts' WHERE lastname = 'XXX';");
$syncfield = result['0'];
$wpdb->replace( $wpdb->prefix.$_CONFIG['dbtable'], array( 'id' => 1, 'syncfields' => $syncfield), array('%d', '%s') );
$vtiger->logout($sessionId);
$vtiger->closeCurl();
$result = json_decode($result, true);
return var_dump(($result['success']) ? $result : "Error");

َAlso You Can Use vtiger CRM Webservice Client Library http://forge.vtiger.com/projects/vtwsclib/

Upvotes: 1

Related Questions