Results 1 to 3 of 3

Thread: Soap, Sugar and Python.

  1. #1
    giblfiz is offline Junior Member
    Join Date
    Apr 2005
    Posts
    3

    Default Soap, Sugar and Python.

    II just started working with Sugar a few days ago, and have been mucking about with the SOAP interface quite a bit. I was hoping for some commentary on some of the mods that I have made. If there is either an easier or a better way to do any of the things that I have done I would love to hear about it so that I can avoid repeating my mistakes.

    my intended goal was to write a Python script that would take an incoming email, and add the email address, name, and any other information it could glean from the email to a new lead in Sugar using soap.

    Sadly the most developed python SOAP library SOAPpy can either control the order of method parameters or the name of them, but not both. Because of this I was forced to include a new file in soap.php in which I registered a new complex type
    Code:
    $server->wsdl->addComplexType(
                                  'create_leads_params',
                                  'complexType',
                                  'struct',
                                  'all',
                                  '',
                                  array(
                                        'user_name'=>array('name'=>'user_name', 'type'=>'xsd:string'),
                                        'password'=>array('name'=>'password', 'type'=>'xsd:string'),
                                        'first_name'=>array('name'=>'first_name', 'type'=>'xsd:string'),
                                        'last_name'=>array('name'=>'last_name', 'type'=>'xsd:string'),
                                        'email_address'=>array('name'=>'email_address', 'type'=>'xsd:string'),
                                        )
                                  );
    as well as a new function, which was pretty much just a wrapper for create_lead

    Code:
    $server->register('create_lead_py',
                      array('create_leads_params'=>'tns:create_leads_params'),
                      array('return'=>'xsd:string'),
                      $NAMESPACE);
    
    function create_lead_py($create_leads_params)
    {
       return (create_lead($create_leads_params['user_name'], 
    $create_leads_params['password'], 
    $create_leads_params['first_name'],
     $create_leads_params['last_name'],
     $create_leads_params['email_address']));
    }
    I was sort of surprised to find that the create_lead function defined in SOAP doesn't allow any of the many other contact fields to be filled in. (for instance if another application has phone numbers, names and emails and wants to pass them over to Sugar via SOAP a new function would need to be defined. Its easy enough to do, but the thought of drifting away from the main branch keeps me awake at night)

    Does anyone know why the create_lead function is so minimalist?

    Thanks for any advice.
    -Harry

  2. #2
    giblfiz is offline Junior Member
    Join Date
    Apr 2005
    Posts
    3

    Default Re: Soap, Sugar and Python.

    Answering some of my own questions:

    I was playing around with things and reading source code and documentation this morning, and I figured out how you are supposed to flesh out the Leads. By using the the method "set_entry" which is will let you set virtually any element of any module. The key to it is you have to pass it the id of the entry that you want to edit within the 'name_value_list' that you pass to it. This was a little bit unclear to me at first.

    Here is a sample. You need to replace the magic number" 9bf..." with whatever the id for your lead was (which is passed out when it is created, or can be found in a number of other ways"

    Code:
    $result = $soapclient->call('set_entry',array('session'=>$session,'module_name'=>'Leads', 'name_value_list'=>array(array('name'=>'id',\
     'value'=>'9bf0ffda-3b94-9a1f-a955-426e4b342bba'),array('name'=>'title','value'=>'Emperor'), array('name'=> 'last_name','value'=>'Nort\
    on'))));

  3. #3
    harrywood is offline Member
    Join Date
    Mar 2009
    Posts
    7

    Default on the wiki

    I've been wiki-fiddling (as is my habit), so these tips are linked this from the SOAP in Python wiki page. Any other python examples to link to?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •