I use the nusoap client. I'm just going to post code because that's all you asked for but if you need a further explanation I'd be happy to oblige.
To login:
Notes:
-The user and password are the same you would use to login to SugarCRM
-Your password has to be md5 encripted (PHP comes with an md5() function).
-Its a really good idea to store your session id as this is used in moth other functions.
-your wsdl url should include the '?wsdl' at the end of it.
Code:
PHP Code:
inculde_once('path/to/nusoap.php');
$client = new nusoap_client($wsdl,true);
//login
$auth_array = array(
'user_name' => $username,
'password' => $password,
'version' => '0.1'
);
$login_params = array('user_auth' => $auth_array,
'application_name' => 'WebForm');
$login_results = $client->call('login',$login_params);
$session_id = $login_results['id'];
Insert:
Notes:
-You must have a session id
PHP Code:
$set_entry_params = array(
'session' => $session_id,
'module_name' => 'Leads',
'name_value_list' => array(
array('name' =>'email1',
'value' => $_REQUEST['webtolead_email1']),
array('name' =>'first_name',
'value' => $_REQUEST['first_name']),
array('name' =>'last_name',
'value' => $_REQUEST['last_name']),
array('name' =>'title',
'value' => $_REQUEST['title']),
array('name' =>'account_name',
'value' => $_REQUEST['account_name']),
array('name' =>'phone_work',
'value' => $_REQUEST['phone_work']),
array('name' =>'website',
'value' => $_REQUEST['website']),
array('name' =>'lead_source',
'value' => 'Web Site'),
array('name' => 'status',
'value' => 'Inactive')
)
);
$set_entry_result = $client->call('set_entry', $set_entry_params);
Update:
Notes:
-You must have a session id.
-Updating is a two step process. You must first find the entry you want to update. In this case I'm searching my Contacts and Leads module for a record with a given email (assuming I have a unique email for every contact/lead). Then, you do the same thing you would for an insert, except in your name/value pairs you MUST add the record id.
Code:
PHP Code:
//Search leads and contacts
$search_by_module_params = array(
'user_name' => $username,
'password' => $password,
'search_string' => $_REQUEST['m_email'],
'modules' => array('Contacts', 'Leads'),
'offset' => 0,
'max_results' => '1'
);
$search_by_module_result = $client->call('search_by_module', $search_by_module_params);
$entryid = $search_by_module_result['entry_list'][0]['id'];
$nvl = array(
array('name' => 'id',
'value' => $entryid),
array('name' =>'email1',
'value' => $_REQUEST['m_email']),
array('name' =>'first_name',
'value' => $_REQUEST['m_first_name']),
array('name' =>'last_name',
'value' => $_REQUEST['m_last_name']),
array('name' =>'title',
'value' => $_REQUEST['m_title']),
array('name' =>'account_name',
'value' => $_REQUEST['m_company']),
array('name' =>'phone_work',
'value' => $_REQUEST['m_phone']),
array('name' =>'set_opt_c',
'value' => $_REQUEST['m_opt_out']),
array('name' =>'flag_opt_c',
'value' => '1'),
array('name' =>'website',
'value' => $_REQUEST['m_website'])
);
$set_entry_params = array(
'session' => $session_id,
'module_name' => $search_by_module_result['entry_list'][0]['module_name'],
'name_value_list' => $nvl);
$set_entry_result = $client->call('set_entry', $set_entry_params);
If any of your functions aren't working, you can always print_r() the response that you get from $client->call() to see if there are any errors. Let me know if you have any questions.
Bookmarks