Server APIs

Server API enables data flow control for a module. It is recommended for use when a module needs to access of other module data / state. The Server API will take measure to apply the required Sharing / Profile access restriction as configured for the logged in user. Also triggers configured Event handlers (Workflow etc…) for operations like Save / Delete.

Attention

Using direct database queries is discouraged as developers might induce data-security issues unknowingly and increase risk.

Webservice ID

include_once 'include/Webservices/Utils.php';

$crmid = '1'; // ID of Leads record.
$wsid = vtws_getWebserviceEntityId('Leads', $crmid);

List Types

include_once 'include/Webservices/ModuleTypes.php';

$current_user = CRMEntity::getInstance('Users');
$current_user->retrieveCurrentUserInfoFromFile(1);

try {
        $typeInformation = vtws_listtypes(array(), $current_user);
        foreach ($typeInformation['types'] as $name) {
                echo sprintf("%s\n", $name);
        }
        foreach ($typeInformation['information'] as $name => $information) {
                echo sprintf("Name: %s, Label: %s, SingluarLabel: %s, IsEntity: %s \n",
                        $name, $information['label'], $information['singular'], ($information['isEntity']? "yes": "no"));
        }
} catch (WebServiceException $ex) {
        echo $ex->getMessage();
}

Describe

include_once 'include/Webservices/DescribeObject.php';

try {
        $describe = vtws_describe('Leads', $current_user);
        foreach ($describe['fields'] as $field) {
                echo sprintf("%s (%s), Mandatory? %s \n", $field['name'],
                        $field['type']['name'], ($field['mandatory']? "yes": "no"));
        }
} catch (WebServiceException $ex) {
        echo $ex->getMessage();
}

Create

include_once 'include/Webservices/Create.php';
try {
        $data = array (
                'lastname' => 'LNAME',
                'firstname'=> 'FNAME',
                'company'  => 'CNAME',
                'assigned_user_id' => '19x1', // 19=Users Module ID, 1=First user Entity ID
        );
        $lead = vtws_create('Leads', $data, $current_user);

        print_r($lead);

} catch (WebServiceException $ex) {
        echo $ex->getMessage();
}

Retrieve

include_once 'include/Webservices/Retrieve.php';
try {
        $wsid = vtws_getWebserviceEntityId('Leads', 'CRMID') // Module_Webservice_ID x CRM_ID
        $lead = vtws_retrieve($wsid, $current_user);
        print_r($lead);

} catch (WebServiceException $ex) {
        echo $ex->getMessage();
}

Revise

include_once 'include/Webservices/Revise.php';
try {
        $wsid = vtws_getWebserviceEntityId('Leads', 'CRMID') // Module_Webservice_ID x CRM_ID
        $data = array('firstname' => 'FIRSTNAME', 'id' => $wsid);
        $lead = vtws_revise($data, $current_user);
        print_r($lead);

} catch (WebServiceException $ex) {
        echo $ex->getMessage();
}

Query

include_once 'include/Webservices/Query.php';
try {
        $q = "SELECT * FROM Leads WHERE lastname LIKE '%LNAME%'";
        $q = $q . ';'; // NOTE: Make sure to terminate query with ;
        $records = vtws_query($q, $current_user);
        print_r($records);

} catch (WebServiceException $ex) {
        echo $ex->getMessage();
}

Delete

include_once 'include/Webservices/Delete.php';
try {
        $wsid = vtws_getWebserviceEntityId('Leads', 'CRMID') // Module_Webservice_ID x CRM_ID
        vtws_delete($wsid, $current_user);

} catch (WebServiceException $ex) {
        echo $ex->getMessage();
}