How to sync my suiteCRM with my project

Hi , I am totally new in SuiteCRM. My requirement is to show a data list from my project(laravel project) database to the accounts page of the suite crm.How could i do this . Please help me out.

Hello,
Welcome to the community.
You can synchronize your data from Laravel to SuiteCRM accounts via REST API or a new version of API 8
Here is the documentation about API


But where i need to write the api code, and how could i update the accounts table with my project data dynamically as it will change by daily basis. Could you please elaborate, that will be very helpful to me.

if you want to have those one time only, You can export your Accounts info in CSV and import it via SuiteCRM Import functionality.

but as you require to update it daily basis, You create a PHP script on your server and do call API to insert or update your Accounts detail.
Here are the basic CURD example of REST API,

Please tell me where i have to write the API code.

Hi,
if you want to push accounts from laravel to SuiteCRM, use methods like “set_entry” (rest v4):

 /**
     * Update or create a single SugarBean.
     *
     * @param String $session -- Session ID returned by a previous call to login.
     * @param String $module_name -- The name of the module to return records from.  This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
     * @param Array $name_value_list -- The keys of the array are the SugarBean attributes, the values of the array are the values the attributes should have.
     * @param Bool $track_view -- Should the tracker be notified that the action was performed on the bean.
     * @return Array    'id' -- the ID of the bean that was written to (-1 on error)
     * @exception 'SoapFault' -- The SOAP error, if any
     */
    Method [  public method set_entry ] {
      

      - Parameters [4] {
        Parameter #0 [  $session ]
        Parameter #1 [  $module_name ]
        Parameter #2 [  $name_value_list ]
        Parameter #3 [  $track_view = false ]
      }
    }

This method creates a new record within the CRM using the attributes supplied in $name_value_list.

So, what you need to do:

  • identify which use cases should trigger an account creation/update in the CRM
  • identify how to extend these triggers (I’m not familiar with laraval, but I’m sure there are events like before/after save or on-create/on-update)
  • then you can start creating your webrequest (first get a session id from the crm, then start adding/updating crm entitities)

Note: if you plan to do a bidirectional synchronization, keep in mind to not start synchronization loops between the systems :wink:

as i am totally new to suitecrm, i could not understand from where these api will be managed?

I assume you are familiar with basic PHP code.
For example you want to create Accounts like,
name = “Urdhva tech”;
email = “abc@xyz.com”;

Now in any PHP file in your laravel project do create a PHP script where shown example. then

  1. Login via API and get a session

  2. Create Accounts in SuiteCRM via Set entry method as shown in the above-mentioned blog.

     $parameters = array(
     'session' => $session, //Session ID
     'module' => 'Accounts',  //Module name
     'name_value_list' => array (
             array('name' => 'name', 'value' => 'Urdhva tech'),
             array('name' => 'email1', 'value' => 'abc@xyz.com'),
         ),
     );
    

$json = json_encode($parameters);
$postArgs = ‘method=set_entry&input_type=JSON&response_type=JSON&rest_data=’ . $json;

curl_setopt($curl, CURLOPT_POSTFIELDS, $postArgs);
$response = curl_exec($curl);
$result = json_decode($response,true);
$recordId = $result[‘id’];

Do play around set_entry method and you will get your desired output.

You “consume” SuiteCRMs API in laravel’s code. So figure out how/when to execute your custom code in your existing laravel application, then add something like:

$url = "http://example.com/suitecrm/service/v4_1/rest.php";

function restRequest($method, $arguments){
 global $url;
 $curl = curl_init($url);
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 $post = array(
         "method" => $method,
         "input_type" => "JSON",
         "response_type" => "JSON",
         "rest_data" => json_encode($arguments),
 );

 curl_setopt($curl, CURLOPT_POSTFIELDS, $post);

 $result = curl_exec($curl);
 curl_close($curl);
 return json_decode($result,1);
}


$userAuth = array(
        'user_name' => 'suitecrmuser',
        'password' => md5('suitecrmpassword'),
);
$appName = 'My SuiteCRM REST Client';
$nameValueList = array();

$args = array(
            'user_auth' => $userAuth,
            'application_name' => $appName,
            'name_value_list' => $nameValueList);

$result = restRequest('login',$args);
$sessId = $result['id'];

$entryArgs = array(
 //Session id - retrieved from login call
	'session' => $sessId,
 //Module to get_entry_list for
	'module_name' => 'Accounts',
 //Filter query - Added to the SQL where clause,
	'query' => "accounts.billing_address_city = 'Ohio'",
 //Order by - unused
	'order_by' => '',
 //Start with the first record
	'offset' => 0,
 //Return the id and name fields
	'select_fields' => array('id','name',),
 //Link to the "contacts" relationship and retrieve the
 //First and last names.
	'link_name_to_fields_array' => array(
        array(
                'name' => 'contacts',
                        'value' => array(
                        'first_name',
                        'last_name',
                ),
        ),
),
   //Show 10 max results
  		'max_results' => 10,
   //Do not show deleted
  		'deleted' => 0,
 );
 $result = restRequest('get_entry_list',$entryArgs);

print_r($result);

this is a code example copied from the documentation, its logging in to Suite and retrieves data (you would have to alter the method name and the attributes in order to create/update beans instead).

1 Like

could you please give me example like, i have fetched data from my database table named as “user_list”, now the get data i want to show in my accounts page.how did i do that?

How do you want to save those “user_list” elements? Is each row from that user_list-table an account, a contact or something completely different?
If you know that, use “set_entry” to create new records in the CRM. This way, each pushed record in laraval becomes a Suite record too.

Note: this approach creates new objects in the CRM. If you don’t want to save those entities, there might be solutions that just query live data from laravel (this heavily depends on what you’re trying to do exactly).

E: Example json for contact creation (method set_entry):

{	
"session" : "{{sessionid}}",
	"module_name" : "Contacts",
	"name_value_list" : {
		"first_name" : "John",
        "last_name" : "Doe"
	}
}

user_list is my laravel project’s table name. and i want user_list’s data in accounts page.

Then you should create account-objects (so you already know what to use as module_name) :slight_smile: