Creating Custom Web Services In SugarCRM

sugarcrmdevelopers —  June 11, 2013

I have been using web services to access Sugar for sometime now, for purposes of integration and for accessing data from a portal. While it is reasonably well documented, there are restrictions, and last week I cam across a requirement I just couldn’t meet with the standard web services methods. It was time to explore custom web services.

When I did, I suddenly realised that it was very simple to implement, and allowed me to push much of the business logic back into the server where it belongs. I could create a new method that had all sorts of complex logic,and expose the results via web services.

Now I did think that this might restrict the ability of the client software; any time it needs to access a Sugar instance, that instance needs the custom web service installed. By zipping up the custom web service as a loadable module (a topic I’ll discuss in the future as it is a very easy and powerful way to deploy any sort of customisation) this objection was quickly overcome. In any cases I would normally have access to the server when doing this type of work.

The method I needed to return the following (I’ve changed it as the original used some custom modules that you wouldn’t be familiar with).

List all accounts along with the name of the most recent associated note, and the number of contact.

Can that be done with one standard web service call? If it can I would be pleased to hear how.

Before tackling that, lets see how the standard web service works. We will look at the version 4.1REST option from Sugar PRO 6.5.13.

service/v4_1/rest.php

/**
* This is a rest entry point for rest version 4
*/
chdir('../..');
require_once('SugarWebServiceImplv4_1.php');
$webservice_class = 'SugarRestService';
$webservice_path = 'service/core/SugarRestService.php';
$webservice_impl_class = 'SugarWebServiceImplv4_1';
$registry_class = 'registry';
$location = '/service/v4_1/rest.php';
$registry_path = 'service/v4_1/registry.php';
require_once('service/core/webservice.php');

We will create a new entry point that overrides the standard process. I’ll add the code soon.