By popular request, here are some examples that worked for me when using the SOAP API offered by
SugarCRM. Its nice that there is an interface, but it isn't brilliantly documented or nearly as widely used as it should be!
SugarCRM can't talk to PHP 5 native SOAP libraries in WSDL mode, so connect without it. Find below a series of queries that each worked for me, all just dumped here in succession, don't try to run this whole piece of code - it is intended as a series of examples. Use each line and then var_dump($response) to see what's happening.
// set up options array$options =
array( "location" =>
'http://192.168.1.129/aeat/spm/crm/soap.php',
"uri" =>
'http://www.sugarcrm.com/sugarcrm',
"trace" =>
1 );
// connect to soap server$client =
new SoapClient
(NULL,
$options);
// look what modules sugar exposes$response =
$client->
get_available_modules($session_id);
// look in more detail at the fields in the Accounts module$response =
$client->
get_module_fields($session_id,
'Accounts');
// look for a particular account name and then get its ID$response =
$client->
get_entry_list($session_id,
'Accounts',
'name like "%LornaJane%"');
$account_id =
$response->
entry_list[0]->
id;
// create a new account record and grab its ID$response =
$client->
set_entry($session_id,
'Accounts',
array( array("name" =>
'name',
"value" =>
'New Company') ));
$account_id =
$response->
id;
// create a new contact record, assigned to this account, and grab the contact ID$response =
$client->
set_entry($session_id,
'Contacts',
array( array("name" =>
'first_name',
"value" =>
'Geek'),
array("name" =>
'last_name',
"value" =>
'Smith'),
array("name" =>
'email1',
"value" =>
'a@b.com'),
array("name" =>
'account_id',
"value" =>
$account_id) ));
$contact_id =
$response->
id;
I hope this helps - if you have anything to add, or would like to post some examples, please do :)
Since SugarCRM only works with PHP5 in non-WSDL mode, I had to create all my calls from scratch. The SugarCRM documentation is somewhat minimal, as I may have mentioned, and I found I was mostly reading the WSDL to figure out how to format my SOAP calls.
Tracked: Apr 24, 17:34