Convert PHP SoapClient to Perl SOAP::Lite - php

I am writing a web application that works with the five9 API. I have a working php script that uses the API to print out the email of the first User. My application is in Perl and I am trying to avoid shelling out to a PHP script. I have tried to use SOAP::Lite but am having difficulties. Here is my working PHP script.
#!/usr/bin/php
<?php
$soap = null;
$wsdl = "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl";
$user = "johnsmith#example.com";
$pass = "password";
$soap_options = array("login" => $user, "password" => $pass, "trace" => 1);
$soap = new SoapClient($wsdl, $soap_options);
$arryParams['userNamePattern'] = '';
$result = $soap->getUsersInfo($arryParams);
if(isset($result->return)) {
$objRecords = $result->return;
print $objRecords[0]->generalInfo->EMail;
print "\n";
}
?>
Here is what I have so far working with perl and SOAP::Lite
#!/usr/bin/env perl
use warnings;
use strict;
use MIME::Base64;
use Data::Dumper;
use SOAP::Lite +trace => [ transport => sub { print $_[0]->as_string } ];
my $wsdl_five9 = 'https://api.five9.com/wsadmin/AdminWebService?wsdl&user=johnsmith#example.com';
my $uri = 'https://api.five9.com/wsadmin/AdminWebService';
my $user = 'johnsmith#example.com';
my $password = 'password';
my $authorize = 'Basic '.encode_base64($user . ":" . $password);
my $client = SOAP::Lite->service($wsdl_five9);
$client->on_fault(
sub {
my $soap = shift;
my $res = shift;
if(ref($res) eq '') {
die($res);
} else {
die($res->faultstring);
}
return new SOAP::SOM;
}
);
print "Done\n";
If anyone has experience working with perl and SOAP any insight would be greatly appreciated.

Related

How to use the Firebase to send data to my PHP code

I am working with arduino project and I used PHP to connect to the Firebase.
I want to receive a data from firebase using PHP. I want the $new_ssid and $new_password to received from Firebase.
Here's my code:
<?php
require 'firebaseLib.php';
$Trash = $_GET["trash"];
$Distance = $_GET["distance"];
$Temperature = $_GET["temp_f"];
$Humidity= $_GET["humidity"];
$baseURI = 'x';
$token = 'x';
$devicestatus= array('Distance' => $Distance,'Temperature' =>
$Temperature,'Humidity' => $Humidity);
$firebasePath = '/x/';
$full= array($Trash => $devicestatus);
$fb = new Firebase($baseURI, $token);
$fb -> update($firebasePath, $full);
$new_ssid = "arduino";
$new_pass = "mechanical";
echo $new_ssid."/".$new_pass ;
?>

SoapFault exception

I'm using PHP Version 5.4.16
When I make a SOAP call, it gives me error:
SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in /var/www/html/VAS_sms/index.php:24
Stack trace:
#0 /var/www/html/VAS_sms/index.php(24): SoapClient->__call('SendSMS', Array)
#1 /var/www/html/VAS_sms/index.php(24): SoapClient->SendSMS(Array)
#2 {main}
That's beside a Warning:
Warning: The use statement with non-compound name 'SoapClient' has no
effect in C:\wamp\www\VAS_sms\index.php on line 2
I lost my mind making it run..
Here's my code:
<?php
use SoapClient;
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$wsdl_path = "https://smsvas.vlserv.com/KannelSending/service.asmx?WSDL";
$client = new SoapClient($wsdl_path, array('trace' => 1));
$userName = "username";
$Password = "password";
$SMSText = "text";
$SMSLang = "e";
$SMSSender = "sender";
$SMSReceiver = "01xxxxxxxxx";
try {
echo "<pre>\n";
$result = $client->SendSMS(array(
"Username" => $userName,
"Password" => $Password,
"SMSText" => $SMSText,
"SMSLang" => $SMSLang,
"SMSSender" => $SMSSender,
"SMSReceiver" => $SMSReceiver));
function objectToArray($d){
if (is_object($d)){
$d = get_object_vars($d);
}
if (is_array($d)){
return array_map(__FUNCTION__, $d);
}
else {return $d;}
}
$response_arr = objectToArray($result);
echo "return_code= " . str_replace(";", "", $response_arr);
echo "\n</pre>";
}
catch (SoapFault $exception) {
echo $exception;
}
?>
Any suggestions?
side Q: is there any file missing I should include instead of use SoapClient; ?!
Thanks in advance
EDIT 1
in the documentation file:
<?php
use SoapClient;
$client = new SoapClient("https://smsvas.vlserv.com/KannelSending/service.asmx");
$userName = "username";
$Password = "password";
$SMSText = "text";
$SMSLang = "e";
$SMSSender = "sender";
$SMSReceiver = "01xxxxxxxxx";
$result = $client->SendSMS(array(
"Username" => $userName,
"Password" => $Password,
"SMSText" => $SMSText,
"SMSLang" => $SMSLang,
"SMSSender" => $SMSSender,
"SMSReceiver" => $SMSReceiver));
$response_arr = objectToArray($result);
echo "return_code= " . str_replace(";", "", $response_arr);
function objectToArray($d)
{
if (is_object($d))
{$d = get_object_vars($d);}
if (is_array($d))
{return array_map(__FUNCTION__, $d);}
else {return $d;}
}
?>
Note:  We’re using PHP SoapClient to call the API Web Service, so you
need to enable the libxml PHP extension.  As its response is an
object (not string) so you need to convert it to an array by using
objectToArray function.

Connecting to web service using SOAP & PHP

I'm trying to connect to a web service using PHP's soap client which I can successfully do using Visual Studio, pressing F5 and running the page locally which works a treat.
As soon as I upload the exact same file to my apache web host, I keep getting the error: "failed to load external entity".
Here's my code with the credentials and url taken out...
Any ideas?
<?php
header("Access-Control-Allow-Origin: http://example.com");
header("Access-Control-Request-Method: GET,POST");
ini_set('display_errors', true);
ini_set("soap.wsdl_cache_enabled", "0");
error_reporting(E_ALL);
try
{
$soapclient = new SoapClient('http://example.com');
$params = array ('SystemID' => 'testID','Username' => 'test', 'Password' => 'test');
$response = $soapclient->GetEngineerList($params);
print_r($response);
}
catch(SoapFault $e)
{
print_r($e);
}
strings are not read twice and parsed in single quotes
$soapclient = new SoapClient('$url');
try
$soapclient = new SoapClient($url);
also...do you have $url = ''; anywhere?
UPDATE 1
please try using basic auth to get to your wsdl:
$login = 'bert';
$password = 'berts password';
$client = new SoapClient(
'http://' . urlencode($login) . ':' . urlencode($password) . '#www.server.com/path/to/wsdl',
array(
'login' => $login,
'password' => $password
)
);

HTTP Request inside laravel command not working

I'm trying to create a laravel command to call Mercado Libre API. When I run this sample script in my htdocs from XAMPP folder, it returns the body data, but when I run from my laravel command it returns the body empty.
This is the script:
$app_id = 'xxx';
$secret_key = 'xxxx';
$meli = new Meli($app_id, $secret_key);
$access_token = 'xxxx';
$params = array('access_token' => $access_token);
$result = $meli->get('/users/me', $params, true);
This is the command
public function handle()
{
$app_id = 'xxx';
$secret_key = 'xxx';
$meli = new Meli($app_id, $secret_key);
$access_token = 'xxx';
$params = array('access_token' => $access_token);
$result = $meli->get('/users/me', $params, true);
}
EDIT
The scirpts are running in the same environment. I test and curl is callable.
if(is_callable('curl_init')){
//Code here
print_r("normal");
}

Softlayer API PHP error Function ("setObjectFilter") is not a valid method for this service

I tried to use object filter to get valid device:
Below is the php code:
$client= SoftLayer_SoapClient::getClient('SoftLayer_Account', null, $username, $apiKey);
$filter = new stdClass();
$filter->applicationDeliveryControllers = new stdClass();
$filter->applicationDeliveryControllers->billingItem = new stdClass();
$filter->applicationDeliveryControllers->billingItem->id = new stdClass();
$filter->applicationDeliveryControllers->billingItem->id->operation = new stdClass();
$filter->applicationDeliveryControllers->billingItem->id->operation = $bId;
$client->setObjectFilter($filter);
try {
$mask ='mask[id, name]';
$client->setObjectMask($mask);
$myInstance = $clientNetscaler->getApplicationDeliveryControllers();
} catch(exception $ex) {
}
I got the following error in my run time environment:
There was an error querying the SoftLayer API: Function
("setObjectFilter") is not a valid method for this service
The error came from line $client->setObjectFilter($filter);
Anybody has any idea of why there's such error?
For me the filter is working fine. Just in case, I copied my code. Please make sure you have PHP 5.2.3 or higher and the PHP extension for SOAP. Also try re-downloading the Softlayer PHP client https://github.com/softlayer/softlayer-api-php-client and try again.
Regards
<?php
require_once ('/SoapClient.class.php');
$apiUsername = 'set me';
$apiKey = 'set me';
$accountService = Softlayer_SoapClient::getClient('SoftLayer_Account', null,$apiUsername, $apiKey);
$bId = 51774239;
$filter = new stdClass();
$filter->applicationDeliveryControllers = new stdClass();
$filter->applicationDeliveryControllers->billingItem = new stdClass();
$filter->applicationDeliveryControllers->billingItem->id = new stdClass();
$filter->applicationDeliveryControllers->billingItem->id->operation = new stdClass();
$filter->applicationDeliveryControllers->billingItem->id->operation = $bId;
$accountService->setObjectFilter($filter);
$mask ='mask[id, name]';
$accountService->setObjectMask($mask);
try {
$myInstance = $accountService->getApplicationDeliveryControllers();
print_r($myInstance);
} catch (Exception $e) {
die('Unable to executre the request. ' . $e->getMessage());
}

Categories