aggrosoft Posted November 9, 2016 Share Posted November 9, 2016 Is there any way to add our own custom api functions for the external api or do we have to code the whole authentication etc. by ourselves? Link to comment Share on other sites More sharing options...
pablobaldovi Posted November 29, 2016 Share Posted November 29, 2016 I hope to understand your question When you use the external api you must configure a white IP list with the addresses that can be connected to the api externally. (General Settings> Security) Then just pass in each call the username and password (with md5) Docs: http://docs.whmcs.com/API Link to comment Share on other sites More sharing options...
aggrosoft Posted December 7, 2016 Author Share Posted December 7, 2016 You did not understand the question, anyways - it's easy. You can just add your own php files to the api folder and they will be used as the action: <?php //File includes/api/adddownload.php use WHMCS\Database\Capsule; if (!defined("WHMCS")) { die("This file cannot be accessed directly"); } function getParams($vars) { $param = array('action' => array(), 'params' => array()); if (isset($vars['cmd'])) { //Local API mode $param['action'] = $vars['cmd']; $param['params'] = (object) $vars['apivalues1']; $param['adminuser'] = $vars['adminuser']; } else { //Post CURL mode $param['action'] = $vars['_REQUEST']['action']; unset($vars['_REQUEST']['username']); unset($vars['_REQUEST']['password']); unset($vars['_REQUEST']['action']); unset($vars['_REQUEST']['accesskey']); $param['params'] = (object) $vars['_REQUEST']; } return (object) $param; } try { // Get the arguments $vars = get_defined_vars(); $params = getParams($vars); $data = $params->params; $pid = Capsule::table('tblproducts')->where('moduleid', $data->module)->value('id'); if($pid){ $downloadId = Capsule::table('tbldownloads') ->insertGetId([ 'category' => isset($data->category) ? $data->category : 2, 'type' => isset($data->type) ? $data->type : 'zip', 'title' => $data->title, 'description' => $data->description, 'location' => $data->file, 'clientsonly' => isset($data->clientsonly) ? $data->clientsonly : 1, 'created_at' => new DateTime(), 'updated_at' => new DateTime(), 'productdownload' => isset($data->productdownload) ? $data->productdownload : 1 ]); Capsule::table('tblproduct_downloads')->insert([ 'product_id' => $pid, 'download_id' => $downloadId ]); //Cleanup old downloads, keep maximum of 5 Versions /*$count = Capsule::table('tblproduct_downloads')->where([ 'product_id' => $pid ])->count(); if($count > 5){ }*/ }else{ throw new Exception('Module with ID '.$data->module.' not found'); } $apiresults = array("result" => "success", "message" => "Download added successfully!"); } catch (Exception $e) { $apiresults = array("result" => "error", "message" => $e->getMessage()); } Link to comment Share on other sites More sharing options...
WHMCS Nate Posted December 14, 2017 Share Posted December 14, 2017 Just wanted to add a bit of context here, what is discussed here is a method to add code server side that can be triggered remotely. For me an API can be understood as a promise between the developer using it and then developer providing it to communicate and respond in specific ways. We work hard to preserve backwards compatibility with our APIs. We are not making that kind of a promise and in fact this will not work with our API Credential Roles functionality. If you want to implement a URL that can run custom code, I would recommend using an addon module with the admin area output or client area output functionality: https://developers.whmcs.com/addon-modules/admin-area-output/ https://developers.whmcs.com/addon-modules/client-area-output/ 1 Link to comment Share on other sites More sharing options...
Recommended Posts