how to create connection , vtiger, php

you can use the following sample code. for more information read webservice documents!
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];

Leave a Comment