custome response for out-of-the-box sugar API WS

We are sugar partners and we have a large implementation of sugarcrm in terms of customization.

They will be using sugar flower "serve + sell" that is ondemand deployment option only for now.

The thing is that user is no conform with the way sugar api WS response, specially delete and put, since the stock response doesn't tell them if the operation did works of not, like if there was a DB or php error.

For example, when you perform a DELETE request of a record, sugar just return the same id of the records that you request to remove, that it doesn't tell if it did works at 100%, the only way to be sure if to try to GET the same record again.

Another example is for PUT, when you request update a record with the sugar api, the WS stock response just return you the hole module/record entity with all fields on it instead of just the ones you did update on your request JSON body you could try to check one by one if the value send is the same sent/received what is not ideal.

There is  a way to customize the stock response of sugar stock response to add some "status" key to the JSON and tell the client if it did works as expected or just fail it?

Please let me know what do you think about this and if there is a way to accomplish this.

  • You can create a custom endopoint for overriding the deleteRecord method (DELETE /<Module>/<id>).

    Create the file custom/clients/base/api/CustomModuleApi.php:

    class CustomModuleApi extends ModuleApi {

       public function registerApiRest() {

          'delete' => array(
             'reqType' => 'DELETE',
             'path' => array('<module>','?'),
             'pathVars' => array('module','record'),
             'method' => 'deleteRecord',
             'shortHelp' => 'This method deletes a record of the specified type',
             'longHelp' => 'include/api/help/module_record_delete_help.html',


       public function deleteRecord(ServiceBase $api, array $args) {

          // override your code here.


    Go to Admin -> Repair -> Quick Repair and Rebuild


    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hello

    Hi André, thanks for your help and reply on this.

    Is that custom endopoint that overrites the deleteRecord method upgradeSafe and ondmeand compatible?

      Will this custom code have new sugar versions features/changes of the stock endPoint deleteRecord method (DELETE /<Module>/<id>).


  • Yes, it is upgradeSafe and packageScanSafe.

    In order to let the custom endpoint acquire new features/changes then you need to invoke the parent endpoint and then apply your custom changes and finally return whatever you want to.


    André Lopes
    Lampada Global
    Skype: andre.lampada