Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get Relate documents of Account
$url = "http://localhost:8888/sugarcrm_dev_WebServices/service/v4_1/rest.php";
$username = "admin";
$password = "admin";
//function to make cURL request
function call($method, $parameters, $url)
$curl_request = curl_init();
curl_setopt($curl_request, CURLOPT_URL, $url);
curl_setopt($curl_request, CURLOPT_POST, 1);
curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($curl_request, CURLOPT_HEADER, 1);
curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0);
$jsonEncodedData = json_encode($parameters);
$post = array(
"method" => $method,
"input_type" => "JSON",
"response_type" => "JSON",
"rest_data" => $jsonEncodedData
curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($curl_request);
$result = explode("\r\n\r\n", $result, 2);
$response = json_decode($result[1]);
return $response;
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
$login_parameters = array(
$start = microtime();
$login_result = call("login", $login_parameters, $url);
//get session id
$session_id = $login_result->id;
/*******************GET DATA *********************/
$get_relationships_parameters = array(
//The name of the module from which to retrieve records.
'module_name' => 'Accounts',
//The ID of the specified module bean.
'module_id' => '13111fcd-1884-2a71-0b37-50b7d0f188f6',
//The relationship name of the linked field from which to return records.
'link_field_name' => 'documents',
//The portion of the WHERE clause from the SQL statement used to find the related items.
'related_module_query' => '',
//The related fields to be returned.
'related_fields' => array(
//For every related bean returned, specify link field names to field information.
'related_module_link_name_to_fields_array' => array(
//To exclude deleted records
'deleted'=> '0',
//order by
'order_by' => '',
'offset' => 0,
'limit' => 5,
$get_relationships_result = call("get_relationships", $get_relationships_parameters, $url);
echo "<pre>";
echo "</pre>";
$logout_parameters = array(
"session" => $session_id
$login_result = call("logout", $logout_parameters, $url);
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
echo $totaltime . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.