SugarCRM is nowadays very widely used CRM system so I will cover it in my posts every now and then.

The API is not very well documented but you can browse its capabilities be opening http://URL-TO-SUGAR/soap.php in your browser
At work we use it by ourselves to handle some processes and have been working with customers using it. There are things I like and thing I don’t like in SugarCRM. It is bit bloated and the code is not the most beautiful I have seen. On the other hand it does its job quite well and it is easy to configure without touching a line of code.
If you use a CRM in your business for a while you will most likely to find that you would like to do some integration. At work we have been doing various kinds of integration tasks. We have integrated a phone system to automatically make entries to SugarCRM when inbound or outbound calls have been made, connected registration of a web application to create a new accounts to CRM, connected a LIMS in various ways to it and so on. The reason I found SOAP-API to be the best way in most these cases is the fact that if you use it you won’t break down anything and it is likely that your code will work with future releases too. Off course there is a performance penalty and using SOAP API is not a good option when performance is an issue. So lets get to the business.
Installing SOAPpy
I assume that installing Python module with easy_install is not a problem. However, latest version of SOAPpy was not compatible with Python 2.5. To install SOAPpy I would suggest the following:
1. Download and extract SOAPpy http://sourceforge.net/project/showfiles.php?group_id=26590&package_id=18246
2. Move every “from __future__ import” lines to the beginning of the files where they are in. Below you can see the listing of these files.
localhost:SOAPpy-0.12.0 tuomas$ grep -R __future__ SOAPpy/*.py SOAPpy/Client.py:from __future__ import nested_scopes SOAPpy/GSIServer.py:from __future__ import nested_scopes SOAPpy/NS.py:from __future__ import nested_scopes SOAPpy/Server.py:from __future__ import nested_scopes SOAPpy/Types.py:from __future__ import nested_scopes
3. Install SOAPpy
sudo python setup.py install
The simplest possible example of SugarCRM + SOAPpy
The code below logs in to the SugarCRM, asks the version of the server and prints it. Here is the code:
import md5
import SOAPpy
USERNAME= "user"
PASSWORD= "pass"
auth = {'user_name': USERNAME, 'password': md5.new(PASSWORD).hexdigest(), "version": "1.1"}
# Url of SugarCRM + soap.php?wsdl
SUGAR_URL = 'http://192.160.0.1/soap.php?wsdl'
sugar = SOAPpy.WSDL.Proxy(SUGAR_URL)
session = sugar.login(auth, "foobar")
try:
response = sugar.get_server_version()
except StandardError, err:
print '\nError in information retrieval from SugarCRM:' + str(err)
print response
The API is not documented very well but you can list all of its capabilities by browsing yourself to http://URL-TO-SUGAR/soap.php.
Advanced example
This script will log into SugarCRM and create a new Account.
import md5
import SOAPpy
USERNAME= "user"
PASSWORD= "pass"
auth = {'user_name': USERNAME, 'password': md5.new(PASSWORD).hexdigest(), "version": "1.1"}
# Url of SugarCRM + soap.php?wsdl
SUGAR_URL = 'http://192.160.0.1/soap.php?wsdl'
sugar = SOAPpy.WSDL.Proxy(SUGAR_URL)
session = sugar.login(auth, "foobar")
module = "Accounts"
adata = [{'name': 'name', 'value': "Test Account"},
{'name': 'shipping_address_street', 'value': "Address test"}]
try:
response = sugar.set_entry(session['id'], module, adata)
except StandardError, err:
print '\nError in information retrieval from SugarCRM:' + str(err)
print response
UPDATE: It appears to be that, Sugar Team is working with the API and the documentation at the moment and I’ll take back what I said about missing documentation. Thanks SugarCRM devs!
Tags: Open Source, python, sugarcrm
Hi,
I followed the example, but after the session = sugar.login(auth, “foobar”) I get a HTTPError 403 forbidden. I checked the user/pass (it was correctly written). If I print out the auth variable, I see that the ‘password’: ‘xxxx’ is the first element (?¿). Is this the problem?
Thanks
Hi,
Just guessing here, do you have extra http-auth for your Sugarcrm installation? I so you can give the password in url like this http://user:pass@url-to-sugar... The example in the post works fine with me. My test case was without https. Are you using SSL, I haven’t test SOAPpy with SSL.
Your password is
md5.new(PASSWORD).hexdigest()should look like this random hex:Tuomas
I had trouble with SOAPpy & ZSI. I found a package in pypi called pysugar (currently ver 0.0.6). Works well (so far).
This is great! Thanks for your article. I am a newbie at development and this is a big help.