While I was introducing the SOAP support for the module I had remember some differences between the SOAP and RESTful protocols in Version 1 and 2 of the web services. The following list show different responses for the same call using different protocols.
I've compiled a list of results comming from different request types of the 'login' web service method. (Using php syntax highlight for now, while I found a way to show these kind of results in a more beauty way..)
This is the old SOAP V1 response of a SugarPRO 5.2.0 version:
<?php
Array (
[id] => mro1j8tcgmuujamrpdvt6u3uo1
[error] => Array
(
[number] => 0
[name] => No Error
[description] => No Error
)
)
?>Not different than a SOAP V1 for SugarENT 5.5.0beta2
<?php
Array (
[id] => 3ritlv0meh0kkh40oec5kblck2
[error] => Array (
[number] => 0
[name] => No Error
[description] => No Error
)
)
?>The previous responses are array comming from the Version 1 SOAP interface : "server/soap.php"
Now, moving to the Version 2 of the Web Services "server/service/v2/"..:
a REST serializez V2 call returns an array:
<?php
Array (
[id] => 1df91c8136fa7a86e56cee67e3fcf597
[module_name] => Users
[name_value_list] => Array (
[0] => 1
[1] => admin
[2] => en_us
)
)
?>Doing the same request but using JSON for encoding, returns a stdClass:
<?php
stdClass Object (
[id] => 6debcdc2cb4c48bb66d0298261d09ec7
[module_name] => Users
[name_value_list] => Array (
[0] => 1
[1] => admin
[2] => en_us
)
)
?>And finally, the SOAP call using (V2 provider) returns an array
<?php
Array (
[id] => a2da46c2062bae16ae8b6238bf753728
[module_name] => Users
[name_value_list] => Array (
[0] => Array (
[name] => user_id
[value] => 1
)
[1] => Array (
[name] => user_name
[value] => admin
)
[2] => Array (
[name] => user_language
[value] => en_us
)
[3] => Array (
[name] => user_currency_id
[value] =>
)
[4] => Array (
[name] => user_currency_name
[value] => US Dollars
)
)
)
?>I guess this one (using SOAP) hast the right ouput for 'name_value_list'.. but also has one main difference, it includes the user_currency_id and user_currency_name in the reply (there's nothing about that in the documentation). I guess, somewhere in the RESTful implementation there is a broken function to change stdObject Class into name_value_lists...
This is an abstract of login function from SugarWebServiceImpl.php (used in webservice calls)
<?php
if($success){
session_start();
...
$nameValueArray['user_id'] = self::$helperObject->get_name_value('user_id', $current_user->id);
$nameValueArray['user_name'] = self::$helperObject->get_name_value('user_name', $current_user->user_name);
$nameValueArray['user_language'] = self::$helperObject->get_name_value('user_language', $current_language);
...
$nameValueArray['user_currency_id'] = self::$helperObject->get_name_value('user_currency_id', $cur_id);
$nameValueArray['user_currency_name'] = self::$helperObject->get_name_value('user_currency_name', $currencyObject->name);
...
return array('id'=>session_id(), 'module_name'=>'Users', 'name_value_list'=>$nameValueArray);
}
?>The fact is that service/core/SoapHelperWebService.php, used in SOAP requests declares this function:
<?php
function get_name_value($field,$value){
return array('name'=>$field, 'value'=>$value);
}
?>and service/core/SugarRestUtils.php, used in REST requests, declares the same function.. but..
<?php
function get_name_value($field,$value){
return $value;
}
?>I've updated the post to include what happends with the invalid logins also..
This is the reply of a V1 SOAP request in the SugarENT 5.5.0beta2.. an array
<?php
Array(
[id] => -1
[error] => Array (
[number] => 10
[name] => Invalid Login
[description] => Login attempt failed please check the username and password
)
)
?>This is the reply of a V2 SOAP request in the SugarPRO 5.5.0beta2. Another array.. but has a completely different layout..
<?php
Array (
[faultcode] => 10
[faultactor] =>
[faultstring] => Invalid Login
[detail] => Login attempt failed please check the username and password
)
?>And this is the reply of a V2 RESTful request in the same SugarPRO 5.5.0beta2.
Nothing?
Actually, it's not nothing. The RESTful provider just takes control of the HTTP requests and fills up the following HTTP response:
<?php
HTTP/1.1 500 Internal Server Error
Date: Sun, 06 Sep 2009 09:38:33 GMT
Server: Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i mod_autoindex_color PHP/5.2.8
X-Powered-By: PHP/5.2.8
Content-Length: 4
Connection: close
Content-Type: text/html; charset="ISO-8859-1"
null
?>I wonder why "null" :?
Just, to finish this blog post, in the documentation, the 'user_auth' argument for the call is defined as an array of the elements:
there's another argument, but I guess this one was left just because of other product integration (maybe LDAP?): $user_auth['encryption']
If this value is set to the string 'PLAIN', SugarCRM will understand that $user_auth['password'] is not a hash and should do the md5 for you..
All this leads me to do a more in depth research about current API status.. I need to find a way to get the same reply whatever the version and protocol used, and whatever the result of the operation is..