Last active
August 29, 2015 14:22
-
-
Save mmarum-sugarcrm/6b0d045b48d1dd987f43 to your computer and use it in GitHub Desktop.
Mobile Contracts Proxy API example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'clients/base/api/FilterApi.php'; | |
/** | |
* Class MobileContractsMobileFilterApi | |
* | |
* Tested with Sugar 7.6 | |
* | |
* Example of how to build a simple proxy API that can be used to make API requests to one module pull data from another module. | |
* In this case, we can pull data from the Contracts module (which is not implemented in SugarCRM Mobile yet) via a | |
* proxy Custom Module called test_MobileContracts. This is a way to satisfy a need for a limited view of Contracts | |
* data from within the SugarCRM Mobile app. | |
* | |
*/ | |
class MobileContractsMobileFilterApi extends FilterApi | |
{ | |
public function registerApiRest() | |
{ | |
//New API definition that the base Filter API endpoint for only test_MobileContracts module | |
return array( | |
'filterModuleAll' => array( | |
'reqType' => 'GET', | |
'path' => array('test_MobileContracts'), | |
// Not needed because we will hard code module argument below. | |
// 'pathVars' => array('module'), | |
'method' => 'myFilterList', | |
'jsonParams' => array('filter'), | |
'shortHelp' => 'Proxy API for retrieving all Contract records.', | |
'exceptions' => array( | |
// Thrown in filterList | |
'SugarApiExceptionInvalidParameter', | |
// Thrown in filterListSetup and parseArguments | |
'SugarApiExceptionNotAuthorized', | |
), | |
), | |
); | |
} | |
public function myFilterList(ServiceBase $api, array $args, $acl = 'list') | |
{ | |
//Hard code module redirect | |
$args['module'] = 'Contracts'; | |
// We could transform the 'fields' argument here, but we could also assume that | |
// the field names being passed match those found in Contracts module | |
//Call normal filter API endpoint with our modified arguments | |
return $this->filterList($api, $args, $acl); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment