Extending the moduleapi endpoint does not work

if you put this in custom/clients/base/api/CustomModuleApi.php
<?phpif(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');require_once("clients/base/api/ModuleApi.php");class CustomModuleApi extends ModuleApi
{
    public function registerApiRest()
    {
        return parent::registerApiRest();
    }    public function retrieveRecord(ServiceBase $api, array $args)
    {
        $result = parent::retrieveRecord($api, $args);        //append the current timestamp
        return $result . ' ' . time();
    }
}
it is supposed to intercept the GET method for any module with an id request, although it does not.The ping module seems to work though.  If you put this in custom/clients/base/api/CustomPingApi.php
<?phpif(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');require_once("clients/base/api/PingApi.php");class CustomPingApi extends PingApi
{
    public function registerApiRest()
    {
        //in case we want to add additional endpoints
        return parent::registerApiRest();
    }    //override to modify the ping function of the ping endpoint
    public function ping($api, $args)
    {
        $result = parent::ping($api, $args);        //append the current timestamp
        return $result . ' ' . time();
    }
}
it works perfectly...  can anyone tell me why the ping works and the module does not?  Am I missing something?
  • Hi Nate,

    Can you provide an example of module which it does not work for? And did you test for other modules, does for any of them work?

    I am asking, because some core modules, already extend the ModuleApi. You would find those in the directory modules/<module name>/clients/base/api/

    For those modules, you would have to extend the extended module api, to make sure your api version is the last extension used for the module module's api.

    Example: Contacts already have modules/Contacts/clients/base/api/ContactsApi.php with class ContactsApi extends ModuleApi. For Contacts you would have to extend ContactsApi and not just the generic ModuleApi.

    Hopefully this drives you towards the right direction.

    All the best

    --

    Enrico Simonetti

    Sugar veteran (from 2007)

    www.naonis.tech


    Feel free to reach out for consulting regarding:

    • API Integration and Automation Services
    • Sugar Architecture
    • Sugar Performance Optimisation
    • Sugar Consulting, Best Practices and Technical Training
    • AWS and Sugar Technical Help
    • CTO-as-a-service
    • Solutions-as-a-service
    • and more!

    All active SugarCRM certifications

    Actively working remotely with customers based in APAC and in the United States

  • Lets start with Manufacturers, I don't see any extension in modules/Manufacturers/clients/base/api nor do I see anything in custom/modules/Manufacturers/clients/base/api, yet the above code does not run...

  • What about if you change the code to this and repair?

    <?php

    class CustomModuleApi extends ModuleApi
    {
        public function registerApiRest()
        {
            return parent::registerApiRest();
        }

        public function retrieveRecord(ServiceBase $api, array $args)
        {  
            $GLOBALS['log']->fatal('CustomModuleApi->retrieveRecord called');
            return parent::retrieveRecord($api, $args);
        }
    }

    Do you see the log entry on the sugarcrm.log when leveraging the Manufacturers single record retrieve api?

    --

    Enrico Simonetti

    Sugar veteran (from 2007)

    www.naonis.tech


    Feel free to reach out for consulting regarding:

    • API Integration and Automation Services
    • Sugar Architecture
    • Sugar Performance Optimisation
    • Sugar Consulting, Best Practices and Technical Training
    • AWS and Sugar Technical Help
    • CTO-as-a-service
    • Solutions-as-a-service
    • and more!

    All active SugarCRM certifications

    Actively working remotely with customers based in APAC and in the United States

  • Hi Enrico, Thanks for the assistance.  I found my issue.  I needed to increase my endpoint score.  This is what finally worked for me.

    https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.0/Integration/Web_Services/REST_API/… 

    the 'extraScore' entry allowed me to increase the endpoint score so the system will prioritize this endpoint.

    public function registerApiRest() {
    return array(
    'retrieve' => array(
    'reqType' => 'GET',
    'path' => array('<module>','?'),
    'pathVars' => array('module','record'),
    'method' => 'retrieveRecord',
    'shortHelp' => 'Returns a single record',
    'longHelp' => 'include/api/help/module_record_get_help.html',
    'extraScore' => 1,
    ),
    );
    }