REST API - Access Denied when using "get_relationships"

Hi everyone,

I have a problem with the REST API, everything works fine when I use the “get_entry” or “get_entry_list” methods but I always get an “Access Denied” when I use “get_relationships” (ex: to retrieve the Account linked to a Contact).

It seems to be caused by the ACL check, but I’m not familiar with Roles and the user used by the web service is administrator, so I thought he would have access to everything given that in the menu I can do everything with him.

I have this problem in SuiteCRM 7.3.2 (also in SugarCRM 6.5.20) installed on PlanetHoster (CentOS 6.7) ; also tested on a Ubuntu 14.04 and on Windows 7 (Wamp Server).

Can someone help me on this ? I tried to create some Roles and security groups, to repair Roles and to do quick repair and rebuild, but it doesn’t change anything… still have this “Access Denied”.

Thanks in advance !

It could be that you ate passing some extra parameters that are invalid, or in the wrong order. This is generally the issue if it’s not a roles problem

Hi Matt,

According to the documentation page (here) I think I’m passing the right parameters in the right order but I may be wrong.

Here’s the code I’m using to test :


	# the REST service
	$url = "http://localhost/CRM/SuiteCRM-7.3.2/service/v4_1/rest.php/";

	# login and password
	$username = "admin";
	$password = "password";

	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 );
		curl_close( $curl_request );

		$result = explode( "\r\n\r\n", $result, 2 );
		$response = json_decode( $result[1] );

		return $response;

	$login_parameters = array (
		"user_auth"	=>	array(
			"user_name"		=>	$username,
			"password"		=>	md5( $password ),
			"version"		=>	"1",
		"application_name"	=>	"RestTest",
		"name_value_list"	=>	array(),
	$login_result = call( "login", $login_parameters, $url );

	echo 'REST API -- Login : ';
	echo "<pre>";
	print_r($login_result); # login is working
	echo "</pre>";

	$session_id = $login_result->id;

	$get_relationships_parameters = array(
		'session'					=> $session_id,
		'module_name'			=> 'Contacts',
		'module_id'				=> '634a07c6-066a-f5d8-dff0-562e0020060c',
		'link_field_name' => 'contacts_accounts',
		'related_module_query' => " ",
		'related_fields' => array(
		 'related_module_link_name_to_fields_array' => array(),
		 'deleted'=> 0,
		 'order_by' => '',
		 'offset' => 0,
		 'limit' => 200,

	$result = call( "get_relationships", $get_relationships_parameters, $url );

	echo 'REST API -- get_relationships : ';
	echo "<pre>";
	print_r($result); # Access Denied 40 You do not have access
	echo "</pre>";

	$get_entry_parameters = array(
     'session' 				=> $session_id,
     'module_name' 		=> "Contacts",
     'id' 						=> "634a07c6-066a-f5d8-dff0-562e0020060c",
     'select_fields' 	=> array(
    'link_name_to_fields_array' => array(),
    'track_view' 			=> true,

	$result = call ( "get_entry", $get_entry_parameters, $url );
	echo "<pre>";
	print_r($result); # get_entry works fine
	echo "</pre>";


the link_field_name for ‘accounts_contacts’ in contacts is ‘accounts’,

‘accounts_contacts’ is the name of the relationship, not the link field

There’s was a mistake in my previous code (wrong relationship’s name).
Anyway, I tried to replace this :

'link_field_name' => 'accounts_contacts',

with this :

'link_field_name' => 'accounts',

and it doesn’t work either way, always returns “Access Denied”…

Maybe I misunderstood something : my goal is to retrieve the account to which my contact is linked using the “accounts_contacts” relationship.
In the Sugar documentation, it says that the link_field_name is “the relationship name of the linked field from which to return records”. ; so my understanding is that I have to use the relationship name that I see between these two modules in the studio :

Am I misunderstanding something ?

it is the name of the link field you need to use, which in this case is ‘accounts’,

but it seems the problem you are having is that you have a space in related_module_query which is causing the issue :-

1 Like

It works! Thank you so much Matt!

Last question : obviously I misunderstood something about the usage of get_relationships, where do you find the name of the link field to use ?