Vtiger API - radus28/Vtiger-DevOps GitHub Wiki

Introduction

Vtiger had 3 Types of API which can be used to integerate and sync external resources as well manipulate internal code.

  1. REST API - Standard API
  2. Mobile API - Built on the top of REST Api with User based Authentication instead of AccessKey to enable mobile sign in
  3. Soap API - Used specifically in Customer Portal

Rest API

$username = 'USER-NAME'; // You may use any user

$accessKey = 'ACCESS-KEY'; // Use access key if given by CRM administrator. If you are the Admin, Obtain from CRM > My Preference > Access Key (Use admin user to get all privileges

$endpointurl = 'http://CRM-URL/webservice.php'; // You crm url prepended with webservice.php

/**

* Getting challenge token - Challenge response authentication to avoid eavesdropping

*/

$ws_url = "{$endpointurl}?operation=getchallenge&username={$username}";

$response = getResponseFromURL($ws_url);

$resobj = json_decode($response);

$token = $resobj->result->token;

/**

* Authentication (Login)

*/

$preparedkey = md5($token . $accessKey);

$postlist = array(

`'operation' => 'login',`

`'username' => $username,`

`'accessKey' => $preparedkey`

);

$loginresponse = getResponseFromURL($endpointurl, $postlist);

$sesobj = json_decode($loginresponse);

$session = $sesobj->result->sessionName;

$userId = $sesobj->result->userId;

/**

* Create example : Contacts module

*/

$data = [];

$data['firstname'] = 'too tt';

$data['lastname'] = 'I';

$data['email'] = '[email protected]';

$data['phone'] = '12457889';

$data['assigned_user_id'] = '19x1';// note prefix '19x'

$params = array("sessionName" => $session, "operation" => 'create', "element" => json_encode($data), "elementType" => 'Documents');// Final parameters

$response = getResponseFromURL($endpointurl, $params);// Note 'getResponseFromURL()' is just a custom method used with php / cURL.

$created = json_decode($response);

END POINT : https://YOUR-CRM-URL/webservice.php

Mobile API

END POINT : https://YOUR-CRM-URL/modules/Mobile/api/wsapi.php

Using vtiger Web services internally

Retrieving

$data = vtws_retrieve($CRMID, $current_user);

WS CRMID

WS(Web Service) CRM ID is a combination of Webservice ID and CRMID

  1. WebService ID - from vtiger_ws_entity table
  2. CRM ID - From vtiger_crmentity table

Creating

$lineItem[0] = [

        `'productid' => $serviceData['id'],`

        `'quantity' => 1,`

        `'listprice' => $pricePerFortFortNight,`

        `'description' => $serviceData['description'],`

        `'product_name' => $serviceData['servicename'],`

        `'tax1' => '0',`

        `'tax2' => '0',`

        `'tax3' => '0',`

        `'tax4' => '10.000',`

        `'tax5' => '0',`
    `];`
  `-----`

   `-----`

 `$lineItem[n] =[..]`

  `$invoiceData = [`

        `'subject' => 'SUBJECT',`

        `'invoicedate' => 'INVOICE-DATE',`

        `'hdnTaxType' => 'group',`

        `'assigned_user_id' =>'assigned_user_id',`

        `'bill_street' => '',`

        `'ship_street' => '',`

        `'productid' => 'PRODUCT-ID',`

        `'pre_tax_total' => 'PRE-TAX-TOTAL',`

        `'invoicestatus' => 'Created',`

        `'LineItems' => $lineItem,`

    `];`

$invoiceRecord = vtws_create('Invoice', $invoiceData, $current_user);