
2006-11-07, 01:19 PM
|
|
Member
|
|
Join Date: Oct 2006
Posts: 11
|
|
Code snippets for SugarCRM webervices
Hi Everybody,
Im a newbie to webservices and i started my journey towards webservices(Sugarcrm Inetgration) using PHP and NuSOAP .
As there is very little information on using webservices to integrate sugarcrm,i just thought of sharing code
snippets of webservices methods i have used so far.I request you all to post any little information related to
webservices or code snippets you worked on so far, which will be helpful to many users like me.
Thank you in advance
Here is a simple code for get_entry_list method which returns all the 'contacts' information
PHP Code:
<?php
define('sugarEntry', TRUE);
require_once("../include/nusoap/nusoap.php");
$config['sugar_server'] = "http://localhost/sugarcrm/soap.php?wsdl";
$config['login'] = array(
'user_name' => 'admin',
'password' => md5('admin')
);
//$config['msg']="kldsfls";
//echo $config['msg'];
$config['application_name'] = 'harysh_test';
$sugarClient = new nusoapclient($config['sugar_server'], TRUE);
$err = $sugarClient->getError();
if ($err) {
var_dump($err);
die();
}
$sugarClientProxy = $sugarClient->getProxy();
if (!$sugarClientProxy) {
var_dump($err);
die();
}
$result = $sugarClientProxy->login($config['login'], $config['application_name']);
$session_id = $result['id'];
//Code for invoking the search method
$module_name='Contacts';
$query='contacts.last_name like "%" ';
$order_by='contacts.last_name';
$offset=0;
$select_fields='';
$max_results=5;
$deleted=0;
$search_list=$sugarClientProxy->get_entry_list($session_id,$module_name,$query,$order_by,$offset,$select_fields,$max_results,$deleted);
echo "Search result is <pre>";
print_r($search_list);
echo "</pre>";
echo '<h2>Request</h2><pre>' . htmlspecialchars($sugarClientProxy->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($sugarClientProxy->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($sugarClientProxy->debug_str, ENT_QUOTES) . '</pre>';
$sugarClientProxy->logout($session_id);
?>
harysh
harysh99@gmail.com
Last edited by julian; 2006-11-07 at 06:26 PM.
|

2006-11-07, 06:26 PM
|
 |
Sugar Team Member
|
|
Join Date: Sep 2004
Posts: 1,639
|
|
Re: Code snippets for SugarCRM webervices
Hello harysh,
I edited your post and added [php] tags around the code to make it a little more readable. It would be great if you could add this to the SOAP section in the Sugar Developer Wiki: http://wiki.sugarcrm.com/
__________________
Julian Ostrow
Systems and Applications Engineer
SugarCRM Inc.
Last edited by julian; 2006-11-07 at 06:31 PM.
|

2006-11-09, 11:47 AM
|
|
Member
|
|
Join Date: Oct 2006
Posts: 11
|
|
Re: Code snippets for SugarCRM webervices
Hi,
This is my second simple example for fetching a user id .... using get_user_id method.Its very simple ofcourse..
PHP Code:
<?php
define('sugarEntry', TRUE);
require_once("../../include/nusoap/nusoap.php");
$config['sugar_server'] = "http://localhost/sugarsuite/soap.php?wsdl";
$config['login'] = array(
'user_name' => 'admin',
'password' => md5('admin')
);
$config['application_name'] = 'harysh_test';
$sugarClient = new nusoapclient($config['sugar_server'], TRUE);
$err = $sugarClient->getError();
if ($err) {
var_dump($err);
die();
}
$sugarClientProxy = $sugarClient->getProxy();
if (!$sugarClientProxy) {
var_dump($err);
die();
}
$login_result = $sugarClientProxy->login($config['login'], $config['application_name']);
$session_id = $login_result['id'];
$getuserid_result=$sugarClientProxy->get_user_id($session_id);
echo "Userid is ".$getuserid_result;
echo '<h2>Request</h2><pre>' . htmlspecialchars($sugarClientProxy->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($sugarClientProxy->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($sugarClientProxy->debug_str, ENT_QUOTES) . '</pre>';
var_dump($session_id);
$sugarClientProxy->logout($session_id);
?>
harysh
harysh99@gmail.com
|

2006-11-09, 01:33 PM
|
|
Member
|
|
Join Date: Oct 2006
Posts: 11
|
|
Re: Code snippets for SugarCRM webervices
Hi,
Did anybody worked on set_entry method? I have tried creating a Contact using set_entry method.. but it is inserting NULL values in the database .. if anybody had luck using this method please let me know .. im lil bit confused on how to set/pass the values for name_value_list.
waiting for replies..
Thank you
harysh
harysh99@gmail.com
|

2006-11-10, 06:57 PM
|
|
Junior Member
|
|
Join Date: Nov 2006
Posts: 2
|
|
Re: Code snippets for SugarCRM webervices
Ok, If harrysh considers himself a newbe, I'm still an embryo.
I'm trying to make his PHP code work (I'm a pretty good PHP coder, just very new to Sugar.) and I've got it executing ok for the most part but it's not letting me login. Always giving "Login attempt failed..." messages.
I've created a portal only user and have the correct url, username and password in the script.
I've noticed that he uses "harysh_test" in the application_name definition. I changed this to "php_test" for my script. Is this something I have to define somewhere else in Sugar?
What really stupid and obvious things am I missing? Feel free to flame me briefly only if you tell me what/where to read to cure my ignorance.
Thanks much!!!
|

2006-11-10, 09:37 PM
|
 |
Sugar Team Member
|
|
Join Date: Sep 2004
Posts: 1,639
|
|
Re: Code snippets for SugarCRM webervices
Hey danb,
The 'application_name' parameter doesn't matter at all; don't worry about that. Do note that you need to md5() the password that's being sent across. If your Sugar username is 'dan' and your password is 'bE6123,' you should be sending the following authentication information over SOAP:
PHP Code:
$config['login'] = array(
'user_name' => 'dan',
'password' => '3e6105cd08d4f414e78cfda71c698c29'
);
$config['application_name'] = 'jostrow_test';
Note this is only valid for the login() SOAP method, not portal_login(), which has its own set of intricacies. Also note that you can set up logging and die() statements in the login() method on the Sugar side, since you're well-versed in PHP. Look at ./soap/SoapSugarUsers.php::login() for more information.
__________________
Julian Ostrow
Systems and Applications Engineer
SugarCRM Inc.
|

2006-11-13, 01:42 PM
|
|
Member
|
|
Join Date: Oct 2006
Posts: 11
|
|
Re: Code snippets for SugarCRM webervices
Hi,
This is an example for creating a new Account using set_entry method.We can use set_entry method for populating the values in other modules
PHP Code:
<?php
define('sugarEntry', TRUE);
require_once("../include/nusoap/nusoap.php");
$config['sugar_server'] = "http://localhost/sugarsuite/soap.php?wsdl";
$config['login'] = array(
'user_name' => 'admin',
'password' => md5('admin')
);
$config['application_name'] = 'example_test';
$sugarClient = new nusoapclient($config['sugar_server'], TRUE);
$err = $sugarClient->getError();
if ($err) {
var_dump($err);
die();
}
$sugarClientProxy = $sugarClient->getProxy();
if (!$sugarClientProxy) {
var_dump($err);
die();
}
$result = $sugarClientProxy->login($config['login'], $config['application_name']);
$session_id = $result['id'];
//CODE FOR creating an Account using set_entry method
$module_name="Accounts";
$account=array(array('name'=>'name','value'=>'Company ABC'),array('name'=>'email1','value'=>'example@example.com'),array('name'=>'phone_office','value'=>'123456789'));
$create_account=$sugarClientProxy->set_entry($session_id,$module_name,$account);
echo "Result is <pre>";
print_r($create_account);
echo "</pre>";
echo '<h2>Request</h2><pre>' . htmlspecialchars($sugarClientProxy->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($sugarClientProxy->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($sugarClientProxy->debug_str, ENT_QUOTES) . '</pre>';
$sugarClientProxy->logout($session_id);
?>
.
|

2006-11-13, 04:35 PM
|
|
A Prolific Poster
|
|
Join Date: Jan 2006
Posts: 405
|
|
Re: Code snippets for SugarCRM webervices
This always works. But as Julian mentioned, adding via a portal API is messed up. I hope Sugar comes with an example code for the community or if someone has an code, they can share. Currently, portal API don't work for me though I put username and password, portal name correctly. But I can't make it work using portal APIs.
|

2006-11-14, 07:20 PM
|
 |
Sugar Team Member
|
|
Join Date: Sep 2004
Posts: 1,639
|
|
Re: Code snippets for SugarCRM webervices
sugarcare,
Do you have a Contact whose "Portal Name" field matches the portal_name you're passing, and whose "Portal Active" checkbox is checked?
__________________
Julian Ostrow
Systems and Applications Engineer
SugarCRM Inc.
|

2006-11-14, 08:22 PM
|
|
A Prolific Poster
|
|
Join Date: Jan 2006
Posts: 405
|
|
Re: Code snippets for SugarCRM webervices
Yup. Login works. But It always says errors while fetching cases.
<br><br><b>GET CASES:</b><BR><b>HERE IS ERRORS:</b><BR>HTTP Error: no data present after HTTP headers<BR><BR><b>HERE IS RESPONSE:</b><BR>HTTP/1.1 200 OK
Date: Tue, 14 Nov 2006 21:35:39 GMT
Server: Apache/2.0.58 (Win32) PHP/5.1.4
X-Powered-By: PHP/5.1.4
Set-Cookie: PHPSESSID=5430f3e99f6e08dc8596e2644f08ba4f; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 0
Connection: close
Content-Type: text/html
Last edited by sugarcare; 2006-11-14 at 08:42 PM.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 07:54 AM.
|