Yeah I know, the title promises a mess of the subjects, but bear with me.
It makes sense.
First of all. Install SugarCRM – how to install it, you ask? Well, check the documentation for your favorite distribution and I guess it’ll “just work”.
The problem I have is that the CRM is written in PHP. I know it’s the next best thing after sliced bread, but I just don’t like it.
I prefer using Python for my programming ventures, but lately trying to enter the functional programming area, but that’s whole new thing and I won’t go into it (yet).
Therefore I’ve decided to just access the data from SugarCRM using MySQL and after checking the documentation I’ve found the SugarCRM can be access using SOAP.
And since I’ve used ZSI before – for SOAP access to the web services it was natural to try it with the SugarCRM.
Here are the results of the jury:
The simplest thing to try was login service, for which the WSDL file says:
<message name="loginRequest">
<part name="user_auth" type="tns:user_auth"/>
<part name="application_name" type="xsd:string"/>
</message>
and user_auth is ComplexType:
<xsd:complexType name="user_auth">
<xsd:all>
<xsd:element name="user_name" type="xsd:string"/>
<xsd:element name="password" type="xsd:string"/>
<xsd:element name="version" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
And the code to do it is following:
#-*- encoding: utf-8 -*-
import sys,md5
# call: python <script_name> -u <url_of_wsdl_file>
from optparse import OptionParser
from ZSI.ServiceProxy import ServiceProxy
op = OptionParser(usage="%prog [options]")
op.add_option("-u", "--url", help="service URL (mandatory)", metavar="URL")
options, args = op.parse_args()
if not options.url:
op.print_help()
sys.exit(1)
else:
options.url = options.url.replace("?WSDL", "?wsdl")
if not options.url.endswith("?wsdl"):
options.url += "?wsdl"
service = ServiceProxy(wsdl=options.url, tracefile=sys.stdout)
print "Accessing service in SugarCRM, method login..."
#password is md5 encoded
passwrd = md5.new("user_password").hexdigest()
auth = {"user_name":"insert_user_name","password":passwrd,"version":"1.1"}
resultDict = service.login(user_auth=auth,application_name="sugar_soap")
id = resultDict["return"]["id"]
print "session id=",id
print "error=",resultDict["return"]["error"]