Jump to content

SugarCRM Integration - NuSOAP to PHP SOAP Issue


spyro

Recommended Posts

Recently I read a post that said PHP SOAP was faster than NuSOAP when interfacing with SugarCRM. So, I decided to start testing and then hit a wall.

 

I have been playing with PHP SOAP calls and have made three functions. One to login, one to get a quote record, and one to approved a quote record. The login appears to work but the retrieval of the quote record fails with an invalid login.

 

If I execute this code my output from the function login is:

stdClass Object ( [id] => dedf1134e237144b25281eae38ad8135 [error] => stdClass Object ( [number] => 0 [name] => No Error [description] => No Error ) )

 

When I try to get the record I get:

stdClass Object ( [result_count] => -1 [entry_list] => Array ( ) [error] => stdClass Object ( [number] => 10 [name] => Invalid Login [description] => Login attempt failed please check the username and password ) )

 

<?php
    
    $wsdl="http://localhost/test/soap.php?wsdl";
    $user_name = "admin";
    $password = md5("admin");
    define('sugarEntry',TRUE);
        
    //$soapclient = new SoapClient($wsdl);
    $options = array(
        "location" => 'http://localhost/test/soap.php',
        "uri" => 'http://localhost/test',
        "trace" => 1
        );
    // connect to soap server
    $soapclient = new SoapClient(NULL, $options);
    
    //$soapclient = new SoapClient($wsdl);
    
    $approve = $_GET['approve'];
    $view = $_GET['view'];
    $quoteNum = $_GET['quote'];
    
    $time_start = microtime(true);
    
    $info = setLogin($user_name,$password,$soapclient);
    $session_id = $info['session_id'];
    $user_guid = $info['user_guid'];

    $time_end = microtime(true);
    $time = $time_end - $time_start;
    echo "Login time " . $time;

    echo '<img src="header.jpg"></a>';
    echo '<h1>Customer Portal</h1>';
    
    if(isset($view) && isset($quoteNum))
    {
        
        $query = 'quotes.id =\''.$quoteNum.'\'';
        $singleQuote = getQuotesList($session_id,$soapclient,$query);
        //print_r($singleQuote);
        $quoteId = $singleQuote['entry_list'][0]['id'];
        $quoteName = $singleQuote['entry_list'][0]['name_value_list'][5]['value'];
        $quoteTotal = $singleQuote['entry_list'][0]['name_value_list'][36]['value'];
        echo '<b>Quote ID </b>' . $quoteId . '</br>';
        echo '<b>Quote Name </b>' . $quoteName . '</br>';
        echo '<b>Quote Total </b>' . round($quoteTotal,2) . '</br>';
        echo '<a href="listQuotes.php?approve=1&quote='. $quoteId .'">Approve '.$quoteName.'</a>';
        
        
    }
    elseif(isset($approve) && isset($quoteNum))
    {
        
        $data = setQuoteApproved($session_id,$soapclient,$quoteNum  );
        echo 'Thank you for your business';
        //print_r($data);
        
        
    }
    else
    {
    $time_start = microtime(true);    

    $query = 'quote_type =\'Quotes\' AND quotes_cstm.portal_viewable_c =\'1\'';
    //print_r($soapclient);
    $quotesList = getQuotesList($session_id,$soapclient,$query);
    print_r($quotesList);
    //$quoteId = $quotesList['entry_list'][0]['id'];
    //$quoteName = $quotesList['entry_list'][0]['name_value_list'][5]['value'];
    echo '<b>My Quotes</b></br>';
    echo '<a href="listQuotes.php?view=1&quote='. $quoteId .'">'.$quoteName.'</a>';
    
    $time_end = microtime(true);
    $time = $time_end - $time_start;
    echo $time;
    }
    
    
    
    
    function setLogin($user_name,$password,$soapclient)
    {
           $user_auth = array(
                          'user_name' => $user_name,
                          'password' => $password,
                          'version' => '0.1'
                         );
    
            $result_array = $soapclient->login($user_auth);
            print_r($result_array);
            $session_id = $result_array->id;
            //echo $session_id;

            $user_guid = $soapclient->get_user_id($session_id);
            
            $loginInfo = array(
                                'session_id'=>$session_id,
                                'user_guid'=>$user_guid
                                );
            return $loginInfo;
            
    
}
    
    function getQuotesList($sessionid,$soapclient,$query)
    {
                   
         $set_entry_params = array(
               'session' => $sessionid,
               'module_name' => 'Quotes',
               'query' => $query,
                );
        
            $list = $soapclient->get_entry_list($set_entry_params);
            //print_r($list);
            return $list;
        
    }
    
    function setQuoteApproved($sessionid,$soapclient,$id)
    {
        $set_entry_params = array(
            'session'=> $sessionid,
            'module_name' => 'Quotes',
              'name_value_list'=>array(
                    array('name'=>'id','value'=>$id),
                    array('name'=>'quote_stage','value'=>'Closed Accepted'),
                ) 
        );
        
        $data = $soapclient->call('set_entry',$set_entry_params);
        
        return $data;
        
        
    }
?> 

 

Any ideas on the problem?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.