Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Simple SOAP script for SugarCRM 4.5

  1. #1
    Scott_Savage is offline Sugar Community Member
    Join Date
    Aug 2006
    Location
    Sydney, Australia
    Posts
    193

    Default Simple SOAP script for SugarCRM 4.5

    Hi Guys,

    Just new to this SugarCRM stuff, but thought this code clip would help up some new people. It is based on the simple soap example that was posted on this forum for Sugar 4.2. Please let me know what you think!

    PHP Code:

    <?php 
    if(!defined('sugarEntry'))define('sugarEntry'true);  // allow this file as an entry point  
    require_once('include/nusoap/nusoap.php'); //use the nusoap library

    //define the SOAP Client and point to the SOAP Server 
    $client = new nusoapclient('http://yourCrmUrl/soap.php?wsdl',true);  

    // Create a session by passing a valid user name and password (password = hashed version stored in users->user_hash table) 
    // User must not be portal_only 
    echo "Login Result: ";
    echo 
    $client->call('create_session', array('user_name'=>'admin''password'=>'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')); 
    echo 
    "<br />";

    // the test function returns a string that you send it 
    echo "Test Output: ";
    echo 
    $client->call('test', array('string'=>'Hello World!')); 
    echo 
    "<br />";

    // End the session 
    echo "Closing Session: ";
    echo 
    $client->call('end_session', array('user_name'=>'soap')); 
    echo 
    "<br />";

    //kill the client
    unset($client);
    ?>
    Last edited by Scott_Savage; 2006-08-05 at 04:54 AM.

  2. #2
    julian's Avatar
    julian is offline Sugar Team Member
    Join Date
    Sep 2004
    Posts
    1,639

    Default Re: Simple SOAP script for SugarCRM 4.5

    Hello Scott,

    This is great! Perfect material for the wiki we'll be publishing on Monday.
    Julian Ostrow
    Systems and Applications Engineer
    SugarCRM Inc.

  3. #3
    Scott_Savage is offline Sugar Community Member
    Join Date
    Aug 2006
    Location
    Sydney, Australia
    Posts
    193

    Default Re: Simple SOAP script for SugarCRM 4.5

    Here is a slightly more complicated login/logout code snippet:

    PHP Code:
    <?php 
    if(!defined('sugarEntry'))define('sugarEntry'true);  // allow this file as an entry point  
    require_once('include/nusoap/nusoap.php'); //use the nusoap library

    //define the SOAP Client and point to the SOAP Server 
    $client = new nusoapclient('http://yourCrmUrl/soap.php?wsdl',true);  

    //prepare the authentication array which contains the username and password
    $user_auth = array( 'user_name'=>"admin",
                  
    'password' =>"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                  
    'version'  =>"4.5.0");
    //send the authentication info and application name to the login function
    $session $client->call('login', array('user_auth'=>$user_auth'application_name'=>'SugarCRM')); 

    //check to see if any login errors occurred
    $error $session['error'];
    if (
    $error['number']<>0){
        echo 
    "Login Error!<br />Error: ".$error['name']."<br />Descr: ".$error['description']."<br />";
    } else {
        
    //if no errors then output the session id
        
    echo "Session id: ".$session['id']."<br />";
    }

    //PERFORM OTHER FUNCTIONS HERE

    //log out of the session
    $error $client->call('logout'$session['id']);

    //check to see if any logout errors occured
    if ($error['number']<>0){
        echo 
    "Logout Error!<br />Error: ".$error['name']."<br />Descr: ".$error['description']."<br />";
    } else {
        
    //if no errors then output the session id
        
    echo "Session Closed Successfully.<br />";
    }

    //kill the client
    unset($client);
    ?>

  4. #4
    WayneSugar's Avatar
    WayneSugar is offline Sugar Community Member
    Join Date
    Oct 2005
    Posts
    155

    Default Re: Simple SOAP script for SugarCRM 4.5

    I would check out the example SOAP 'tests' in /examples/
    SoapFullTest.php is a good one
    Wayne Pan
    Software Eng.

  5. #5
    guz843 is offline Sugar Community Member
    Join Date
    May 2005
    Posts
    171

    Default Re: Simple SOAP script for SugarCRM 4.5

    i am trying to wrap my head around the soap thing....

    are there any tutorials on video? please help, im sure this is easy i just cant seem to get a solid example to work ytrhough to understand

  6. #6
    Scott_Savage is offline Sugar Community Member
    Join Date
    Aug 2006
    Location
    Sydney, Australia
    Posts
    193

    Default Re: Simple SOAP script for SugarCRM 4.5

    My example posted above is quite simple? I think the comments explain most of it.

    Basically it is a method of performing remote function calls. So the login call is made with the call('login') function, and some parameters are passed in which are just the same as parameters for any normal function call. ie login(username, password). The parameters are put into an array and passed through that way.

    Once you have logged in there are calls like setEntry and getEntry which can be used to create or retrieve records from the database. These functions are brilliant because you can retireve any type of record from the database (ie. contact, account, call etc.) and it will set or get the parameters you request.

    Like Wayne said 2 posts above there are some good examples in the /examples folder in the SugarCRM download. This SOAP stuff is good for me as I don't need to hack any PHP code, instead I just use the SOAP calls from external scripts. Helps a lot when upgrading versions or trying to find your dodgy code!!

  7. #7
    Niggy is offline Sugar Community Member
    Join Date
    Oct 2008
    Posts
    246

    Default Re: Simple SOAP script for SugarCRM 4.5

    I get the following result:

    Login Result: Failed
    Test Output: Hello World!
    Closing Session: Success

    Any ideas where I might be going wrong?

  8. #8
    Napolux is offline Member
    Join Date
    Jan 2009
    Posts
    5

    Default Re: Simple SOAP script for SugarCRM 4.5

    Quote Originally Posted by Niggy View Post
    I get the following result:

    Login Result: Failed
    Test Output: Hello World!
    Closing Session: Success

    Any ideas where I might be going wrong?

    Try to "md5" your password before trying to login

  9. #9
    sugarDauin is offline Member
    Join Date
    Jan 2009
    Posts
    6

    Default Re: Simple SOAP script for SugarCRM 4.5

    Hello,

    i am an absolte beginner with these things (sugarCRM, soap, Webservice, LAMP etc)

    How can i do tests with this script?

    I habe a fast stack installation (SugarCRM CE 5.2.0 on Windows) and i tried to start this script using my PHP-Editor.

    There i get

    Fatal error in your PHP code.
    Your php.exe file is bad.
    If you use a PHP extension, it is possible that the PHP interpreter can't locate one of extension .dll files, possibly because of incorrect extension_dir parameter in [PHP] section of your php.ini file.


    i think i do something wrong with starting this file, but what?
    Last edited by sugarDauin; 2009-01-29 at 05:32 PM.

  10. #10
    nvdp2002 is offline Sugar Community Member
    Join Date
    Mar 2008
    Posts
    134

    Default Re: Simple SOAP script for SugarCRM 4.5

    Sugar 5.2.0i
    iis
    mssql

    Hi

    I Tried both scripts and i always get a blank response. Its probably something small, but if anyone could help please. Ive tries the examples and some of them show a form , but when submitted there's no result.

    Is there an easy way to test to see if ones soap set-up is correct?

    Thank you,

    Nasser

Page 1 of 2 12 LastLast

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
  •