REST API method "get_relationships" gives an empty set

Hi everyone,
i am building an external application interacting with the SuiteCRM using REST API. I have created a module “franchise” which would have many leads in it, so created a one to many relationship between franchise and leads. Now i am trying retrieve a lead record and the franchise associated to it. But I get an empty result. Here’s my code:

$get_franchise_lead_parameters = array(
‘session’=>$sessionID,
‘module_name’=>‘Leads’,
‘module_id’=>$_GET[‘leadid’], //the id of the specific lead record.
‘link_field_name’=>‘wbur_franchise_leads_1’,
‘related_fields’=>array(
‘id’,
‘name’,
),
‘deleted’ => ‘0’,
);
$get_franchise_lead = call(‘get_relationships’,$get_franchise_lead_parameters, $url);

I get the following set which is empty.

stdClass Object ( [entry_list] => Array ( ) [relationship_list] => Array ( ) )

But this not coorect, when i login to the suite crm, i can see the franchise name linked to each lead created.

I also tried using the get_entry_list method to retrieve all the Leads and tried to retrieve the field wbur_franchise_leads_1_name and assigned_user_name. I could get assigned_user_name but not the franchise name. Why is this so? When assigned_user_name is also relationship field why dont I get wbur_franchise_leads_1_name?

Could any one please help me…!!!

Hi,

What you have looks reasonable, there’s a few things you can try however.

Try replacing $_GET with a hardcoded Lead id so you can test that it isn’t due to this (is $_GET in the code you are using? This is unlikely to be an id - it is the array of GET parameters).

Secondly you can check the link name - ensure that it is wbur_franchise_leads_1. Note that this is not the relationship name but the name of the link field on leads.

Thirdly I’d supply an empty array for the ‘related_module_link_name_to_fields_array’ parameter. I know that the REST API can be unhappy with arguments in a different order or missing. See here for the reccomended arguments and their order: http://support.sugarcrm.com/02_Documentation/04_Sugar_Developer/Sugar_Developer_Guide_6.5/02_Application_Framework/Web_Services/05_Method_Calls/get_relationships/

Hope this helps,
Jim

1 Like

Thanks for this!
Is there any easy method to just get all the related modules for all the records using get_entry_list method, rather than giving an id and then retriving the related record?

As far as I’m aware there’s no way to get all the related modules without specifying. I think you’ll need to specify each relationship you want to retrieve using the link_name_to_fields_array parameter of get_entry_list.

Thanks,
Jim