I got converted WSDL to PHP script but something is not working very I am trying to connect http://www.regcheck.org.uk/api/reg.asmx?wsdl, but getting this error
Array ( [RegCheckServiceCheck::Check] => SoapFault Object ( [message:protected] => System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at webtropy.CarReg.Check(String RegistrationNumber, String username) in c:\inetpub\wwwroot\regcheck.org.uk\api\reg.asmx:line 26 --- End of inner exception stack trace --- [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\xampp\htdocs\Check\RegCheckServiceCheck.php [line:protected] => 32 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\xampp\htdocs\Check\RegCheckServiceCheck.php [line] => 32 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => Check [1] => Array ( [0] => RegCheckStructCheck Object ( [RegistrationNumber] => [username] => [result:RegCheckWsdlClass:private] => [lastError:RegCheckWsdlClass:private] => Array ( ) [internArrayToIterate:RegCheckWsdlClass:private] => [internArrayToIterateIsArray:RegCheckWsdlClass:private] => [internArrayToIterateOffset:RegCheckWsdlClass:private] => ) ) ) ) [1] => Array ( [file] => C:\xampp\htdocs\Check\RegCheckServiceCheck.php [line] => 32 [function] => Check [class] => SoapClient [type] => -> [args] => Array ( [0] => RegCheckStructCheck Object ( [RegistrationNumber] => [username] => [result:RegCheckWsdlClass:private] => [lastError:RegCheckWsdlClass:private] => Array ( ) [internArrayToIterate:RegCheckWsdlClass:private] => [internArrayToIterateIsArray:RegCheckWsdlClass:private] => [internArrayToIterateOffset:RegCheckWsdlClass:private] => ) ) ) [2] => Array ( [file] => C:\xampp\htdocs\sample-regcheck.php [line] => 46 [function] => Check [class] => RegCheckServiceCheck [type] => -> [args] => Array ( [0] => RegCheckStructCheck Object ( [RegistrationNumber] => [username] => [result:RegCheckWsdlClass:private] => [lastError:RegCheckWsdlClass:private] => Array ( ) [internArrayToIterate:RegCheckWsdlClass:private] => [internArrayToIterateIsArray:RegCheckWsdlClass:private] => [internArrayToIterateOffset:RegCheckWsdlClass:private] => ) ) ) ) [previous:Exception:private] => [faultstring] => System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at webtropy.CarReg.Check(String RegistrationNumber, String username) in c:\inetpub\wwwroot\regcheck.org.uk\api\reg.asmx:line 26 --- End of inner exception stack trace --- [faultcode] => soap:Server [detail] => ) )
I am sure something is missing in config files, mybe someone got idea ?
It's possible to call that web service via a HTTP GET request as follows;
<?php
$username = 'Your username here';
$regNumber = 'SK08KPT';
$xmlData = file_get_contents("https://www.regcheck.org.uk/api/reg.asmx/Check?RegistrationNumber=" . $regNumber ."&username=" . $username);
$xml=simplexml_load_string($xmlData);
$strJson = $xml->vehicleJson;
$json = json_decode($strJson);
print_r($json->Description);
?>
Not as elegant as a SOAP call, but simpler.
Script open source files
You can see all main files
https://www.wsdltophp.com/Wsdls/8a71627601a684624c5694104cce023f/RegCheck-1-0-1-1-1-1-0-0-0-0
Related
I would like to know if it is possible to connect to my WHM with PHP using the cPanel PublicAPI PHP Repository https://github.com/CpanelInc/publicapi-php so that I can create a list of the accounts in the WHM.
Is there anything I should know? Are there any restrictions? I simply want to populate a list of my accounts that are in my WHM.
Right now I'm getting an error
Warning: count(): Parameter must be an array or an object that implements Countable in
I was wondering if there was something blocking me?
Here is what my code looks like, I'd like to create a php variable to holds the array data, then loop through it printing the account domain name
require_once '../_libraries/publicapi-php-master/Cpanel/Util/Autoload.php';
$config = array(
'service' => array(
'whm' => array(
'config' => array(
'host' => 'XXXXXXXXXXXXXX',
'user' => 'XXXXXXXXXXXXXX',
'password' => 'XXXXXXXXXX'
),
),
),
);
$cp = Cpanel_PublicAPI::getInstance($config);
$accounts = $cp->whm_api('listaccts');
print_R($accounts);
#print $accounts->_response->dataContainer->storage->acct->dataContainer->storage[0];
When I do a print_r($accounts) this is what I get, I just need to know how to traverse this and loop through it with PHP. I can see in this output the first domain is cfpacking.com, that is the data I'm after.
Cpanel_Query_Object Object
(
[_query:Cpanel_Query_Object:private] => Cpanel_Core_Object Object
(
[dataContainer:protected] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[adapter] => whostmgr
[client] => curl
[url] => https://XXXXXXXXXXXXXX:2087/json-api/listaccts
[args] =>
[argsArray] => Cpanel_Core_Object Object
(
[dataContainer:protected] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
)
)
)
[authstr] => Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXX==
[directURL] =>
)
)
)
[_response:Cpanel_Query_Object:private] => Cpanel_Core_Object Object
(
[dataContainer:protected] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[status] => 1
[statusmsg] => Ok
[acct] => Cpanel_Core_Object Object
(
[dataContainer:protected] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[0] => Cpanel_Core_Object Object
(
[dataContainer:protected] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[inodeslimit] => 500000
[ip] => XXXXXXXXXXXXXXX
[mailbox_format] => maildir
[plan] => default
[maxftp] => unlimited
[maxparked] => unlimited
[owner] => XXXXXXXXXXXXXXXXXXX
[maxpop] => unlimited
[email] => XXXXXXXXXXXXXXXXXXXXXX
[max_email_per_hour] => 500
[disklimit] => unlimited
[maxlst] => unlimited
[min_defer_fail_to_trigger_protection] => 5
[backup] => 1
[startdate] => 17 Dec 27 15:59
[inodesused] => 3281
[maxsql] => unlimited
[max_defer_fail_percentage] => 25
[ipv6] => Cpanel_Core_Object Object
(
[dataContainer:protected] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
)
)
)
[max_emailacct_quota] => unlimited
[maxsub] => unlimited
[unix_startdate] => 1514411971
[outgoing_mail_hold] => 0
[partition] => home
[legacy_backup] => 1
[maxaddons] => unlimited
[suspendtime] => 0
[uid] => 1750
[suspendreason] => not suspended
[suspended] => 0
[user] => XXXXXXXXXXXXXX
[domain] => cfpacking.com
[diskused] => 79M
[theme] => paper_lantern
[temporary] => 0
[is_locked] => 0
[shell] => /bin/bash
[outgoing_mail_suspended] => 0
)
)
)
[1] => Cpanel_Core_Object Object
The response object can be turned into an array using the following syntax:
require_once '../_libraries/publicapi-php-master/Cpanel/Util/Autoload.php';
$config = array(
'service' => array(
'whm' => array(
'config' => array(
'host' => 'XXXXXXXXXXXXXXXXXXXX',
'user' => 'XXXXXXXXXXXXXXXXXXXX',
'password' => 'XXXXXXXXXXXXXXXX'
),
),
),
);
$cp = Cpanel_PublicAPI::getInstance($config);
$accounts = $cp->whm_api('listaccts',array('search'=>'XXXXXXXXX','searchtype'=>'owner'));
$accounts = $accounts->getResponse('array')['acct'];
foreach($accounts as $account){
print $account['domain'];
print '<br />';
}
The library(https://github.com/CpanelInc/publicapi-php) contains code that generates warnings in php 7.2 because of a breaking change. Because the library hasn't been maintaned for 9 years you will have to fix it yourself.
The fix:
old:
Cpanel/PublicApi.php line 343
if (count($storedServicesConfig) > 1) {
new:
Cpanel/PublicApi.php line 343
if (count($storedServicesConfig->getAllData()) > 1) {
I'm using a sites API to check the status of some of my links, it returns the status with json so i'm using $obj = json_decode($result); to access it which works fine.
How can i get the status for each of the files, I tried to do $obj->result->acQeh1UXI-c->status but i'm guessing that's wrong as it didn't display anything
if i use print_r($obj); i get the following:
stdClass Object
(
[status] => 200
[msg] => OK
[result] => stdClass Object
(
[acQeh1UXI-c] => stdClass Object
(
[id] => acQeh1UXI-c
[status] => 200
[name] => 2769.rar
[size] => 18693570
[sha1] => 739c79942bf743b35223fc59e693fcfffc8c8433
[content_type] => application/x-rar
[cstatus] => 0
)
[BNdoJQDSSFo] => stdClass Object
(
[id] => BNdoJQDSSFo
[status] => 200
[name] => 2589.rar
[size] => 99478
[sha1] => 56427728d57c0bd611018305a9133eac83ef8a3a
[content_type] => application/x-rar
[cstatus] => 0
)
[OrnGndPlQEI] => stdClass Object
(
[id] => OrnGndPlQEI
[status] => 200
[name] => 1234.rar
[size] => 293646
[sha1] => 746e09cfaeef4c9c1e6abb7205e78615e661f21b
[content_type] => application/x-rar
[cstatus] => 0
)
)
)
I suggest you turn in to an associative array by using the second parameter available in json_decode.
$obj = json_decode($result, true);
Then you could,
$obj['result']['acQeh1UXI-c']['status'];
Tried with bracket ?
$obj['result']['acQeh1UXI-c']['status']
I am trying to parse some data out of the Hubspot API response. The response looks like this json_decoded:
stdClass Object(
[addedAt] => 1411052909604
[vid] => 24
[canonical-vid] => 24
[merged-vids] => Array
(
)
[portal-id] => XXXXX
[is-contact] => 1
[profile-token] => AO_T-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[profile-url] => https://app.hubspot.com/contacts/XXXXX/lists/public/contact/_AO_T-XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[properties] => stdClass Object
(
[lastname] => stdClass Object
(
[value] => testtt
)
[firstname] => stdClass Object
(
[value] => test
)
[lastmodifieddate] => stdClass Object
(
[value] => 1411052906670
)
)
[form-submissions] => Array
(
[0] => stdClass Object
(
[conversion-id] => 85d24dd2-9ee9-4d47-b8f3-3035acbd8f3b
[timestamp] => 1411052834097
[form-id] => fb16efd9-23cc-4511-889c-204fc8b41dba
[portal-id] => 401824
[page-url] => http://wbl-1.hs-sites.com/test
[canonical-url] => http://wbl-1.hs-sites.com/test
[content-type] => landing-page
[page-title] => test
[page-id] => 1570433242
[title] => Default Form (Sample)
[first-visit-url] => http://wbl-1.hs-sites.com/test
[first-visit-timestamp] => 1411052722970
[meta-data] => Array
(
)
)
)
[list-memberships] => Array
(
)
[identity-profiles] => Array
(
[0] => stdClass Object
(
[vid] => 24
[identities] => Array
(
[0] => stdClass Object
(
[type] => EMAIL
[value] => test#user.com
[timestamp] => 1411052834097
)
[1] => stdClass Object
(
[type] => LEAD_GUID
[value] => 0b6acf21-6cee-4c7b-b664-e65c11ee2d8e
[timestamp] => 1411052834201
)
)
)
)
[merge-audits] => Array
(
)
)
I'm looking specifically to try to dig out an email inside the indentities-profile area.
I've tried to do the following:
echo $results->contacts[0]->identity-profiles;
But it just gives me a value of 0
Then I try to go further into the array by doing:
echo $results->contacts[0]->identity-profiles[0];
But at that point - I get a parse error:
Parse error: syntax error, unexpected '['
What am I doing wrong? And how can I dig all the way down to
identity-profiles[0]->identities->[0]->value
which should equal: test#user.com
What am I missing?
As mentioned in the comment I would suggest to decode the JSON to an associative array by passing true as second parameter to json_decode. Example: json_decode($data, true) Than you could access your identity profiles by:
$results['contacts'][0]['identitiy-profiles']
If you still want to get the results as an object you have to access the properties the following way because they contain a -:
$results->contacts[0]->{'identity-profiles'}
i have create yii framework based wsdl service:
from the link :-
http://www.yiiframework.com/doc/guide/1.1/en/topics.webservice
and facing the issues that is their in the comment
http://www.yiiframework.com/doc/guide/1.1/en/topics.webservice#c6656
and server create fine as i am able to see the wsdl file
but when i try to access the method by the code from external file not in yii site folder
below file is inside another folder not in mysite_yii folder hope that not create any issue as it has to call the wsdl file
$client=new SoapClient('http://localhost/mysite_yii/index.php?r=stock/quote');
try
{
echo $client->getPrice('GOOGLE');
}
catch(Exception $e)
{
echo "<pre>";
print_r($e);
}
i am getting the following exception
SoapFault Object
(
[message:protected] => Function ("getPrice") is not a valid method for this service
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /var/www/serverclient/stock.php
[line:protected] => 9
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /var/www/serverclient/stock.php
[line] => 9
[function] => __call
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => getPrice
[1] => Array
(
[0] => GOOGLE
)
)
)
[1] => Array
(
[file] => /var/www/serverclient/stock.php
[line] => 9
[function] => getPrice
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => GOOGLE
)
)
)
[previous:Exception:private] =>
[faultstring] => Function ("getPrice") is not a valid method for this service
[faultcode] => Client
[faultcodens] => http://schemas.xmlsoap.org/soap/envelope/
)
i have done the same changes as suggested in the comment but not able to call that method
any suggestions ?
Thanks in advance
you must off the server cache for soap, u can off it by adding
ini_set("soap.wsdl_cache_enabled", "0"); to your code
This question already has answers here:
Does this SOAP Fault mean what I think it means?
(3 answers)
Closed 8 years ago.
There is nothing too much to write here other than this error message :
SoapFault Object ( [message:protected] => Wrong Version [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\wamp\www\nsoap\phpclient.php [line:protected] => 10 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\wamp\www\nsoap\phpclient.php [line] => 10 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => getIMIPremium [1] => Array ( [0] => Array ( [imiPolicy] => Array ( [expiryDate] => 23-09-2013 [imiInsured] => Array ( [item] => Array ( [item] => Array ( [age] => 23 [basicSumInsured] => 33233 [coverRageType] => 12 [dateOfBirth] => 26-09-1986 [preExistingDisease] => no ) ) ) [inceptionDate] => 12-09-2009 [noOfInsured] => 1 [partnerCode] => 2121 [stateCode] => 233 ) ) ) ) ) [1] => Array ( [file] => C:\wamp\www\nsoap\phpclient.php [line] => 10 [function] => getIMIPremium [class] => SoapClient [type] => -> [args] => Array ( [0] => Array ( [imiPolicy] => Array ( [expiryDate] => 23-09-2013 [imiInsured] => Array ( [item] => Array ( [item] => Array ( [age] => 23 [basicSumInsured] => 33233 [coverRageType] => 12 [dateOfBirth] => 26-09-1986 [preExistingDisease] => no ) ) ) [inceptionDate] => 12-09-2009 [noOfInsured] => 1 [partnerCode] => 2121 [stateCode] => 233 ) ) ) ) ) [previous:Exception:private] => [faultstring] => Wrong Version [faultcode] => VersionMismatch [faultcodens] => http://schemas.xmlsoap.org/soap/envelope/ [xdebug_message] => ( ! ) SoapFault: Wrong Version in C:\wamp\www\nsoap\phpclient.php on line 10 Call Stack #TimeMemoryFunctionLocation 10.0009674576{main}( )..\phpclient.php:0 20.0704702744SoapClient->getIMIPremium( )..\phpclient.php:10 )
Is it possible that there is an error in the client php code for it ? I have tried NuSoap, but it is also generating error that "Call error: Response not of type text/xml: application/wsdl+xmlHTTP/1.1 200 OK Date: Tue, 17 Sep 2013 16:55:39 GMT Server: Apache/2.2.22 (Win64) PHP/5.3.13 Last-Modified: Tue, 17 Sep 2013 13:18:39 GMT ETag: "a0000000a818c-12e9-4e69428b54054" Accept-Ranges: bytes Content-Length: 4841 Connection: close Content-Type: application/wsdl+xml ".
Do you know any fix for it ?
PHP Code :
<?php
try{
$client = new SoapClient("http://mysite.com/nsoap/IMIPremiumWebService.wsdl");
$args= array("imiPolicy" => array("expiryDate" => "23-09-2013", "imiInsured" =>array("item" => array("item" => array("age"=>'23', "basicSumInsured"=>'33233', "coverRageType"=>'12',"dateOfBirth"=>'26-09-1986',"preExistingDisease" => 'no'))), "inceptionDate"=>"12-09-2009" ,"noOfInsured"=>'1',"partnerCode" => '2121', "stateCode" => '233'));
$something = $client->getIMIPremium($args);
echo $client->responseData;
print_r($something);
}
catch (Exception $e)
{
echo "*****************";
print_r($e);
}
?>
You can find wsdl here (in my question related to NuSOAP:
WSDL Client Not Working
A little bit of googling with that particular error message reveals that it might be related to the Soap server answering in Soap version 1.2, while the default setting in PHP is Soap version 1.1.
Try adding an options array to the SoapClient with array('soap_version'=> SOAP_1_2) as the second parameter (see http://de1.php.net/manual/en/soapclient.soapclient.php for details).