SuiteCRM how to retrieve all account related contacts

1.9k views Asked by At

I have problem retrieveing all account related contacts with REST API v4_1. I am using SuiteCRM.

As I can see by table structure, there is table account and accounts_contacts which contains ID to the Contacts. I use this code to get all Accounts related to the logged user.

$get_entry_parameters = array
        (
            //session id
            'session' => $this->session_id,

            //The name of the module from which to retrieve records
            'module_name' => "Accounts",

            //The ID of the record to retrieve.
            //'id' => NULL,

            //Where conditions without "where" keyword
            'query' => "accounts.assigned_user_id='" . $this->user_id . "'",

            //Sort result by
            'order_by' => NULL,

            //offset
            'offset'  => 0,

            //The list of fields to be returned in the results
            'select_fields' => array( 'id'),

            //optional
            'link_name_to_fields_array' => array(array()),

            //Max number of results to list
            'max_results' => 20,

            'deleted' => false
        );

        $response = $this->call("get_entry_list", $get_entry_parameters);

Then I would love for each of those accounts, to retrieve their related contacts, but I don't know how can I do that.

1

There are 1 answers

0
AudioBubble On

I don't know what went wrong, but this code is now producing what I want. I was not properly defining value of return fields for related data. I should have defined them in array. I guess this was the only problem. If someone else spot another problem, let me know, since I am just learning about sugar/suite crms and where something fits in.

function account_data()
    {
        $get_entry_parameters = array
        (
            //session id
            'session' => $this->session_id,

            //The name of the module from which to retrieve records
            'module_name' => "Accounts",

            //The ID of the record to retrieve.
            //'id' => NULL,

            //Where conditions without "where" keyword
            'query' => "accounts.assigned_user_id='" . $this->user_id . "'",

            //Sort result by
            'order_by' => NULL,

            //offset
            'offset'  => 0,

            //The list of fields to be returned in the results
            'select_fields' => array('id', 'name'),

            //optional
            'link_name_to_fields_array' => array(
                array(
                    'name' => 'contacts',
                    'value' => array('id', 'name')
                )
            ),

            //Max number of results to list
            'max_results' => 20,

            'deleted' => false
        );

        return $response = $this->call("get_entry_list", $get_entry_parameters);
}