Converting Custom Entry Points into REST API

Last Modified Date

Using REST API calls as an alternative to Entry points is an intelligent practice which increases overall efficiency of Web service. To Customize REST API, see the example given below:

(This example has been taken from the official SugarCRM Developer Guide for Ping functionality. You can modify it as per your functionality requirements.)



$base_url = “//{site_url}/rest/v10”;

$username = “admin”;

$password = “password”;


* Generic function to make cURL request.

* @param $url – The URL route to use.

* @param string $oauthtoken – The oauth token.

* @param string $type – GET, POST, PUT, DELETE. Defaults to GET.

* @param array $arguments – Endpoint arguments.

* @param array $encodeData – Whether or not to JSON encode the data.

* @param array $returnHeaders – Whether or not to return the headers.

* @return mixed


function call(









$type = strtoupper($type);

if ($type == ‘GET’)


$url .= “?” . http_build_query($arguments);



$curl_request = curl_init($url);

if ($type == ‘POST’)


curl_setopt($curl_request, CURLOPT_POST, 1);


elseif ($type == ‘PUT’)


curl_setopt($curl_request, CURLOPT_CUSTOMREQUEST, “PUT”);


elseif ($type == ‘DELETE’)


curl_setopt($curl_request, CURLOPT_CUSTOMREQUEST, “DELETE”);


curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);

curl_setopt($curl_request, CURLOPT_HEADER, $returnHeaders);

curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0);

if (!empty($oauthtoken))


$token = array(“oauth-token: {$oauthtoken}”);

curl_setopt($curl_request, CURLOPT_HTTPHEADER, $token);


if (!empty($arguments) && $type !== ‘GET’)


if ($encodeData)


//encode the arguments as JSON

$arguments = json_encode($arguments);


curl_setopt($curl_request, CURLOPT_POSTFIELDS, $arguments);


$result = curl_exec($curl_request);

if ($returnHeaders)


//set headers from response

list($headers, $content) = explode(“rnrn”, $result ,2);

foreach (explode(“rn”,$headers) as $header)




//return the nonheader data

return trim($content);



//decode the response from JSON

$response = json_decode($result);

return $response;



//Login – POST /oauth2/token

$url = $base_url . “/oauth2/token”;

$oauth2_token_arguments = array(

“grant_type” => “password”,

//client id/secret you created in Admin > OAuth Keys

“client_id” => “<CustomID>”,

“client_secret” => “<CustomSecret>”,

“username” => $username,

“password” => $password,

“platform” => “base”


$oauth2_token_response = call($url, ”, ‘POST’, $oauth2_token_arguments);

//Ping – GET /ping

$url = $base_url . “/ping”;

$ping_response = call($url, $oauth2_token_response->access_token, ‘GET’);

echo “<pre>”;


echo “</pre>”;




This endpoint does not accept any request arguments.




Rolustech is a SugarCRM Certified Developer & Partner Firm. We have helped more than 700 firms with various SugarCRM integrations and customization. Get in touch today for your FREE Business Analysis. We will be happy to assist you!

Need Help? Get Free Consultation

By clicking you agree to our Terms and Conditions

Send me news and updates

Get in touch

Contact Information

Looking For a Job ?