Skip to content

Extensibility (invoking you own operations)

Zhmayev Yaroslav edited this page Nov 30, 2017 · 1 revision

It's possible to add custom Web Services operation:

INSERT INTO `vtiger_ws_operation` 
       ( `name`, `handler_path`, `handler_method`, `type`, `prelogin`)
VALUES ('new_operation', 'include/Webservices/MyCoolWebService.php', 'new_operation_method', 'PUT', 0);

-- Replace <new_operation_ID> with the actual ID generated by the query above 
INSERT INTO `vtiger_ws_operation_parameters` (`operationid`, `name`, `type`, `sequence`)
VALUES (<new_operation_ID>, 'someParam', 'String', 1);

INSERT INTO `vtiger_ws_operation_parameters` (`operationid`, `name`, `type`, `sequence`)
VALUES (<new_operation_ID>, 'dateParam', 'TimeStamp ', 2);

now create the following file include/Webservices/MyCoolWebService.php

<?php

function new_operation_method($someParam, $dateParam){
    global $log,$adb;

    // ... do something here

    return $result;
}

So later you could use this new method via vtwsclib-php in this way

<?php
$params = [
    'someParam' => 'foobar',
    'dateParam' => strtotime('now'),
];
$result = $client->invokeOperation('new_operation', $params, 'POST');