SugarCRM SOAP test call fails - soap

I am attempting to test a SugarCRM Soap connection using the following code:
<?
define('sugarEntry', TRUE);
require_once('include/nusoap/nusoap.php');
$sugarclient = new nusoapclient('http://www.mycrmurl.com/soap.php?wsdl',true);
echo $sugarclient->call('test', 'test string');
?>
Unfortunately, the test call returns NULL. Thoughts on how to begin troubleshooting?

I'm not familiar with a SugarCRM SOAP method called test, so unless it's a custom method you made yourself, I'd try with some simple valid calls. (Tested with Sugar CE 6.2).
<?php
require_once('include/nusoap/lib/nusoap.php');
$myWsdl = 'http://www.mycrmurl.com/soap.php?wsdl';
$myAuth = array(
'user_name' => 'will',
'password' => MD5('will'),
'version' => '0.1'
);
$soapClient = new nusoap_client($myWsdl,true);
$loginParams = array('user_auth' => $myAuth, 'application_name' => 'MyApp');
$loginResult = $soapClient->call('login', $loginParams);
$sessionId = $loginResult['id'];
echo $sessionId;
?>
If the above still gives you problems, try the following:
Look in the web server log (Is the call getting through)
Enable the SugarCRM logging and set the level to debug
Either enable PHP error output or make PHP log errors to a log file
Use e.g. SoapUI to test SOAP call
See question 5396302 for a more thorough SOAP example
Check the SugarCRM SOAP documentation

Do this:
$result = $sugarclient->call('test', 'test string');
echo print_r ($result);
It will print the array result, if you just want to see the error description do this:
$result = $sugarclient->call('test', 'test string');
echo $result['error']['description'];
The result is a multidimensional array.

Related

Recaptcha2 'non-object' error in Zend

I'm trying to implement a Recaptcha2 in an old project that uses Zend. I'm using this library for it https://packagist.org/packages/cgsmith/zf1-recaptcha-2
Initially I was getting this error
Uncaught Zend_Exception: No entry is registered for key 'application'
In my _initRecaptcha, I changed the first line from
$config = \Zend_Registry::get('application');
to
$config = \Zend_Registry::get('config')->application;
This is my _initRecaptcha now
public function _initRecaptcha()
{
$config = \Zend_Registry::get('config')->application;
$params = $config->recaptcha->toArray();
$params['messageTemplates'] = [
\Cgsmith\Validate\Recaptcha::INVALID_CAPTCHA => 'The captcha was invalid', // set custom/translated message
\Cgsmith\Validate\Recaptcha::CAPTCHA_EMPTY => 'The captcha must be completed'
];
\Zend_Registry::set('recaptcha', $params);
}
But now I am getting this error
Trying to get property of non-object in /var/www/my-site/application/Bootstrap.php on line 79
Line 79 is the first line in _initRecaptcha
Can anyone what I need to change?
Thanks.
The library seems to be assuming your config is stored in the registry under the key 'application' (which seems questionable to me). You could either add a method to your bootstrap that sets this up (see their example: https://github.com/cgsmith/zf1-recaptcha-2/blob/master/example/application/Bootstrap.php#L13-L18), or change the code to not require it:
public function _initRecaptcha()
{
$params = $this->getOptions()['recaptcha'];
$params['messageTemplates'] = [
\Cgsmith\Validate\Recaptcha::INVALID_CAPTCHA => 'The captcha was invalid', // set custom/translated message
\Cgsmith\Validate\Recaptcha::CAPTCHA_EMPTY => 'The captcha must be completed'
];
\Zend_Registry::set('recaptcha', $params);
}
(It's a long time since I used ZF1 but I think that should work.)
Both cases assume you've added recaptcha lines to your application.ini per the library instructons.

Facebook Real Time Subscriptions Throws Exception Even when challenge is answered

I'm trying to subscribe from my app to Real Time Subscription of Facebook using v2.4 Graph API (after creating a callback function in fbcallback.php) using the code below from my index.php page (the appid and IP address obviously fake in this post):
try {
$response=$fb->sendRequest('POST','/1111/subscriptions',
array(
'object' => 'user',
'callback_url' => 'http://111.111.111.111/fbcallback.php',
'fields' => 'first_name',
'verify_token' => 'thisisaverifystringtestuser',
)
);
$graphNode = $response->getGraphNode();
}catch (Facebook\Exceptions\FacebookSDKException $e) {
echo "exception:" . $e->getMessage(); }
While i'm sure from callback log that Facebook reaches my callback function and i use in it the code below:
<?php
define('VERIFY_TOKEN', 'thisisaverifystringtestuser');
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'GET' && $_GET['hub_mode'] == 'subscribe' &&
$_GET['hub_verify_token'] == VERIFY_TOKEN) {
echo $_GET['hub_challenge'];
}
?>
i get the Message from my index page code looking like this:
exception:(#2201) response does not match challenge, expected value = '866531638', received='866531638'
Anyone encountered it?
P.S I created a test user from the app dashboard roles and configured him to subscribe to app on creation and also got (but not used) an access token for this user from dashboard also.....since i can't denote a specific user during the subscription proccess from my php code i expect (or wish) this user to be subscribed by my php code...am i wrong?
Looks like your script outputs more than just the hub_challenge value.
When I copy&paste the error message from your posting, and insert it in NotePad++, I get that part shown as
received='?866531638'
^
– so there seems to be some invisible/not display-able character before the actual value.
Make sure your script is saved as UTF-8 without BOM, and that it does not make any other output besides the hub_challenge value either. (That could include stuff outside of <?php … ?> tags as well.)

Zend 1.12 Zend/Form/Element -> addError() gives warning on line 2247 of Zend/FormI/Element

Environment:
Apache 2.4
Windows 8
PHP 5.4.14
Zend 1.12
I am doing a very very very simple action on my form, adding an error message on one of my elements with:
$form->getElement('elemetnid')->addError('error');
It works wonders for everyone else, but on my case it also gives out a warning that reads:
Warning: Invalid argument supplied for foreach() in ...\library\Zend\Form\Element.php on line 2247
This only happens when I try to set the error on my MultiSelect element, but if I do so on another element like Text, then everything is great and no warning is given. So I went to inspect the line on the warning, and realized that the problem is that "getValue()" for that element is returning "NULL" and that is not a correct value for the foreach loop inside the framework´s code. But how is that my responsability?
My question is, if anyone knows how to add an error message for a multiSelect without this warning popping up.
Thanks
I can't recreate your error with: Apache 2.2.16, Php 5.3.7 and Zf 1.12.5.
The behaviour is rather odd though. If I invalidate an element before validating the form (by adding an error to an element), it looks like it short circuits the form validation and the error message does not get applied to the form output.
If I try and force in an invalid value via the URL, a value not in my multi-select, I get repeat error messages, and my previously set error messages override the 'X' was not found in the haystack message.
$form = new Zend_Form;
$form->setMethod('GET');
$listOptions = array('one','two', 'three');
$select = new Zend_Form_Element_Multiselect('options', array(
'multiOptions' => $listOptions,
'validators' => array(
array('InArray',
false,
array(array_keys($listOptions)))
)
));
$submit = new Zend_Form_Element_Submit('submit', array(
'label' => 'Do something'
));
$form->addElements(array($select, $submit));
if(isset($_GET) && count($_GET)) {
if(true)
$select
->addError('The form will never validate.')
->addError('Two wrongs don\'t make a right.');
$form->isValid($_GET);
}
$form->setView(new Zend_View);
echo $form;
if ($form->isErrors()) {
echo 'Form did not validate';
var_dump($form->getErrors());
}

Set Timeout SOAP client (Zend Framework)

I'm requesting a webservice using SOAP for which I need to set a request timeout.
new Zend_Soap_Client(http://www.aaa.com/ws/Estimate.asmx?wsdl",
array('encoding' => 'UTF-8');
I have also tried passing 'connection_timeout'=>100 but it seems like "unknow SOAP client option". Please suggest a way I can set the set timeout.
Thanks
I found a solution to set the timeout with Zend_Framework:
If you have your SoapClient-Object like this:
$client = new Zend_Soap_Client(http://www.aaa.com/ws/Estimate.asmx?wsdl", array('encoding' => 'UTF-8');
You can set the timeout for HTTP-Requests. The default timeout in PHP is 30 seconds. With the following code you can e.g. set it to 1 minute.
$context = stream_context_create(
array(
'http' => array(
'timeout' => 1000
)
)
);
$client->setStreamContext($context);
Found on downlifesroad.com
Connection timeout option is not supported, the code is present in Zend_Soap_Client but commented
// Not used now
// case 'connection_timeout':
// $this->_connection_timeout = $value;
// break;
ini_set('default_socket_timeout',$seconds);
Here is a suggested solution using ZendHttpClient and Zend_Http_Client_Adapter_Curl.
$client = new Zend_Http_Client($location);
$adapter = new Zend_Http_Client_Adapter_Curl();
$client->setAdapter($adapter);
$adapter->setCurlOption(CURLOPT_TIMEOUT, $this->_timeout);
$client->setMethod(Zend_Http_Client::POST);
$client->setHeaders('Content-Type', $version == 2 ?
'application/soap+xml' : 'text/xml');
$client->setHeaders('SOAPAction', $action);
The idea is that you send an http request with the SOAP envelope as string at the request.
Full gist code here
I solved this issue by using native PHP SoapClient class...
$client = new SoapClient($url,
array(
'connection_timeout'=>'30'
));
$response = $client->wsMethod(array
('param'=>'value));
You can define the whole duration limit using
ini_set('default_socket_timeout', '30');
Before calling it.
Works like a charm... ;)

Migrating SOAP functionality from PHP to Perl using SOAP::WSDL

I'm struggling to get SOAP working in perl.
In PHP it works perfectly, and without any trouble. And now I'm trying to do the same thing in Perl.
The functional PHP is:
$client = new SoapClient("http://thirdpartyurl.com/api.aspx?WSDL");
$info = $client->GetSomeInfo(array('username' => 'myusername', 'password' => 'mypassword'));
Which works great, but I just can't get it working in perl. I tried SOAP::Lite, but didn't make any progress. And I'm now trying SOAP::WSDL:
use SOAP::WSDL;
my $wsdl = SOAP::WSDL->new(wsdl => 'http://thirdpartyurl.com/api.aspx?WSDL');
my $info = $wsdl->call('GetSomeInfo', 'username', 'myusername', 'password', 'mypassword');
Which just doesn't work.
I looked at the raw requests, and the perl version isn't even sending the user/pass parameters through. What am I doing wrong?
For what it's worth, I achieved authentication, and managed to get parameters sent by using the following:
use SOAP::Lite;
my $service = SOAP::Lite->proxy($service_url)->uri($service_url);
sub SOAP::Transport::HTTP::Client::get_basic_credentials {
return 'myusername' => 'mypassword';
}
my $result = $service->insert(
SOAP::Data->name(
'data' => \SOAP::Data->value(
SOAP::Data->name(
'item' => \SOAP::Data->value(
SOAP::Data->name('key' => 'name'),
SOAP::Data->name('value' => 'new_campaign_x')
)
)
)
)->type('Map')
);
Is there a better way to achieve the same results? I realise overwriting 'get_basic_credentials' is a bit hacky.
I've had pretty good luck with SOAP::Lite in my applications. The username/password combo, is that supposed to be authenticating at the HTTP layer or the SOAP layer? Or just regular soap parameters?
When I want to do SOAP, I reach for XML::Compile.