PHP Soap Dont Accept Dynamic Variables - php

I need to get some data using a web service in PHP. The first function I run returns an id. If I give this id as a variable to the second function (I wrote this function clearly below), it returns null. But if I write statically, the data comes. What could be the problem?
$tc = "xxxxxxxxxxx";
$bireyId = firstFunc($tc); //Get user uniqId
// second function codes
$client = new SoapClient("URL/Service.asmx?WSDL");
try{
$authHeader = array(
"Username" => "Username",
"Password" => "Password"
);
$requestData = array(
"InstructorId" => $bireyId
);
$header = new SoapHeader("http://tempuri.org/","AuthHeader",$authHeader,false);
$client->__setSoapHeaders($header);
$result = $client->GetInstructorCourses($requestData);
print_r($result);
}catch (Exception $ex){
return $ex->faultstring;
}
If I manually write 1111 to the InstructorId value, the data comes. But if I write as above, the data is not coming.

Hey I found out what the problem is. The first function sends me xml data, not a string value. I solved the problem when I shredded this data

Related

Navigating forms and grabbing DOM-Elements from a website using Guzzle/Goutte (PHP, Debugging)

I'm fairly new to PHP and playing around with Goutte/Guzzle to grab some basic information from a website after filling out a few forms.
However I have problems finding issues (there might be a ton of them) since I could not find a way to display or console log any of the results or problems. The script finishes with Code 0 but does not return anything. A tip on how to print out what is currently stored in $client would already go a long way.
Here is the whole code I'm trying to run with a bunch of comments for clarification. I'm sorry for using such a large block, but any of this could have issues.
<?php
use Goutte\Client;
use GuzzleHttp\Client as GuzzleClient;
class grabPlate
{
// WKZ
public function checkPlate
{
$goutteClient = new Client();
$guzzleClient = new GuzzleClient(array(
'cookies' => true,
'timeout' => 60,
));
$goutteClient->setClient($guzzleClient);
$crawler = $goutteClient->request('GET', 'https://kfz-portal.berlin.de/kfzonline.public/start.html?oe=00.00.11.000000');
//Click the first "Start" in the top left
$link = $crawler
->filter('a:contains("Start")')
->eq(0)
->link()
;
$crawler = $client->click($link);
//Check checkbox, fill in name and press the button
$buttonCrawlerNode = $crawler->selectButton('Weiter');
$form = $buttonCrawlerNode->form();
$form['gwt-uid-1']->tick();
$form['select2-hidden-accessible']->select('Herr');
$form['gwt-uid-4'] = 'John';
$form['gwt-uid-5'] = 'Doe';
$client->submit($form);
//Fill some Data into the forms and search
$buttonCrawlerNode = $crawler->selectButton('Button-3616');
$form = $buttonCrawlerNode->form();
$form['.kfzonline-KennzeichenGrossEb'] = 'AB';
$form['.kfzonline-KennzeichenGrossEn'] = '123';
$client->submit($form);
//Extract collection
$info = $crawler->extract('.collection');
//return 1 if something is inside collection, 0 if it's empty
if($info == NULL) {
return 1;
} else {
return 0;
}
}
}
?>
As I said just running the script in PHPStorm returns the status 0. However when plugging it into an API and accessing it, I get a server timeout response.
You should either use a Debugging. Install xDebug to do so in PHP. This is also easy to integrate into Phpstorm.
Alternatively use var_dump() for printing out debug information about variables of any type to console.
You can display the requested page inside your php page, you have to add this snippet :
$client = new GuzzleHttp\Client();
$res = $client->request('GET', 'https://www.facebook.com/');
echo $res->getBody();

how to convert a json response to a text output.?

I am using a platforme call ideamart to create some sms based applications.
They provide a api called subscription api.
deatils about ideamart subscription API
Guid to work with subscription API
I use below first code to request BaseSize details.is that code is correct.?
can I Display response using PHP echo() Function .? or any other way.?
<?php
include_once "definitions.php";
include_once "subscription.php";
$sub = new Subscription();
$AppId = "APP_00001";
$Password = "yuhst345";
$baseSize = $sub->getBaseSize($AppId,$Password);
?>
here is the getBaseSize function that includes in subscription.php
public function getBaseSize($applicationId, $password){
$arrayField = array(
"applicationId" => $applicationId,
"password" => $password);
$jsonObjectFields = json_encode($arrayField);
$resp=$this->sendBaseRequest($jsonObjectFields);
$response = json_decode($resp, true);
$statusDetail = $response['statusDetail'];
$statusCode = $response['statusCode'];
$status =$response['baseSize'];
return $status;
}
So, it looks like your getBaseSize() is returning an simply the base size. So, you should be able to do a
print $baseSize;
OR
echo $baseSize;
And you'll print out the string.

magento : how to add parameter with soap request

I am new to Magento I tried calling a category level using the Magento SOAP API with parent category id. I used the following code:
<?php
$proxy = new SoapClient('http://domain/index.php/api/soap/?wsdl');
$session = $proxy->login('user', 'password');
$result = $proxy->call($session,'catalog_category.level');
echo json_encode($result);
?>
For the above code "Default Category" details are coming, I tried to call some other category by using the following code:
$result = $proxy->call($session,'catalog_category.level',12);
This is not working:
$arguments = array( 'parentCategory' => 12);
$result = $proxy->call($session,'catalog_category.level',$arguments);
This is also not working:
Then I tried calling category tree using following code:
<?php
$proxy = new SoapClient('http://domain/index.php/api/soap/?wsdl');
$session = $proxy->login('user', 'password');
$result = $proxy->call($session,'catalog_category.tree');
echo json_encode($result);
?>
It shows the entire category tree so it means API is working but whenever I try to pass an argument it shows server not found error.
Can anyone please tell me how to pass arguments with the request.
You will need to call it like
$proxy->call($sessionId, 'category.level', array(null, null, 12));
For more information about the function check class
Mage_Catalog_Model_Category_Api
function level($website = null, $store = null, $categoryId = null)
If you want to pass particular website and store you can pass it instead of null parameter.
i manage to get output using soapv2. but it is slow compare to soapv1 but it is giving the required out put. the code i use to pass parameter is given as below.
<?php
$proxy = new SoapClient('http://domain/index.php/api/v2_soap/?wsdl=1');
$session = $proxy->login((object)array('username' => 'user', 'apiKey' => 'password'));
$result = $proxy->catalogCategoryTree((object)array('sessionId' => $session->result, 'parentId' => '12'));
echo json_encode($result);
?>

Amazon MWS (PHP) - Report Request API functions return without data, no error thrown

I am currently working with the Amazon MWS to integrate some features into wordpress via a plugin. I am using the client libraries provided by amazon found here:
https://developer.amazonservices.com/api.html?group=bde&section=reports&version=latest
Using these client libraries and the sample php files included I have set up my plugin to make two API calls. The first is requestReport
public function requestInventoryReport() {
AWI_Amazon_Config::defineCredentials(); // Defines data for API Call
$serviceUrl = "https://mws.amazonservices.com";
$config = array (
'ServiceURL' => $serviceUrl,
'ProxyHost' => null,
'ProxyPort' => -1,
'MaxErrorRetry' => 3,
);
$service = new MarketplaceWebService_Client(
AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
$config,
APPLICATION_NAME,
APPLICATION_VERSION);
$request = new MarketplaceWebService_Model_RequestReportRequest();
$request->setMerchant(MERCHANT_ID);
$request->setReportType('_GET_MERCHANT_LISTINGS_DATA_');
self::invokeRequestReport($service, $request);
}
private function invokeRequestReport(MarketplaceWebService_Interface $service, $request) {
try {
$response = $service->requestReport($request);
if ($response->isSetRequestReportResult()) {
// Print Out Data
}
} catch (MarketplaceWebService_Exception $ex) {
// Print Out Error
}
}
and the second is getReportRequestList which has code similar to the first function. I am able to run these functions without any errors. The issue that I am having is that $response->isSetRequestReportResult() returns false. From my understanding and looking into the response object, this would suggest that the response object does not have the result. (Upon printing out the response object I can see that the FieldValue of the result array is NULL.) The call, however, does not throw an error but neither does it have the result.
I did some digging through the code and found that the result does actually get returned from the api call but never gets set to the return object when the library attempts to parse it from XML. I've tracked the error down to this block of code (This code is untouched by me and directly from the amazon mws reports library).
private function fromDOMElement(DOMElement $dom)
{
$xpath = new DOMXPath($dom->ownerDocument);
$xpath->registerNamespace('a', 'http://mws.amazonaws.com/doc/2009-01-01/');
foreach ($this->fields as $fieldName => $field) {
$fieldType = $field['FieldType'];
if (is_array($fieldType)) {
if ($this->isComplexType($fieldType[0])) {
// Handle Data
} else {
// Handle Data
}
} else {
if ($this->isComplexType($fieldType)) {
// Handle Data
} else {
$element = $xpath->query("./a:$fieldName/text()", $dom);
$data = null;
if ($element->length == 1) {
switch($this->fields[$fieldName]['FieldType']) {
case 'DateTime':
$data = new DateTime($element->item(0)->data,
new DateTimeZone('UTC'));
break;
case 'bool':
$value = $element->item(0)->data;
$data = $value === 'true' ? true : false;
break;
default:
$data = $element->item(0)->data;
break;
}
$this->fields[$fieldName]['FieldValue'] = $data;
}
}
}
}
}
The data that should go into the RequestReportResult exists at the beginning of this function as a node in the dom element. The flow of logic takes it into the last else statement inside the foreach. The code runs its query and returns $element however $element->length = 13 in my case which causes it to fail the if statement and never set the data to the object. I have also looked into $element->item(0) to see what was in it and it appears to be a dom object itself matching the original dom object but with a bunch of empty strings.
Now, I'm new to working with the MWS and my gut feeling is that I am missing a parameter somewhere in my api call that is messing up how the data is returned and is causing this weird error, but I'm out of ideas at this point. If anyone has any ideas or could point me in the right direction, I would greatly appreciate it.
Thanks for your time!
** Also as a side note, Amazon Scratchpad does return everything properly using the same parameters that I am using in my code **
These works for me, check if you are missing anything.
For RequestReportRequest i am doing this:
$request = new MarketplaceWebService_Model_RequestReportRequest();
$marketplaceIdArray = array("Id" => array($pos_data['marketplace_id']));
$request->setMarketplaceIdList($marketplaceIdArray);
$request->setMerchant($pos_data['merchant_id']);
$request->setReportType($this->report_type);
For GetReportRequestList i am doing this:
$service = new MarketplaceWebService_Client($pos_data['aws_access_key'], $pos_data['aws_secret_access_key'], $pos_data['config'], $pos_data['application_name'], $pos_data['application_version']);
$report_request = new MarketplaceWebService_Model_GetReportRequestListRequest();
$report_request->setMerchant($pos_data["merchant_id"]);
$report_type_request = new MarketplaceWebService_Model_TypeList();
$report_type_request->setType($this->report_type);
$report_request->setReportTypeList($report_type_request);
$report_request_status = $this->invokeGetReportRequestList($service, $report_request, $report_requestID);

SOAP error. Not getting correct structure returned

I have a website that contains a form that makes various SOAP requests at certain points. One of these requests gets a list of induction times returned and displays them to the user in order for them to pick one.
I am getting results returned fine from the SOAP service but unfortunately it seems to be not showing information correctly and even not displaying returned object keys at all.
I have liased with one of the devs at the SOAP end and he says the service is fine and spitting out the cirrect information. He has provided a screentshot:
Here is my code to pull call the method I need for this information:
public function getInductionTimes($options) {
$client = $this->createSoapRequest();
$inductionTimes = $client->FITinductionlist($options);
//die(print_r($inductionTimes));
return $inductionTimes;
}
private function createSoapRequest() {
$url = 'https://fitspace.m-cloudapps.com:444/FITSPACE/MHservice.asmx?WSDL';
$options["connection_timeout"] = 25;
$options["location"] = $url;
$options['trace'] = 1;
$options['style'] = SOAP_RPC;
$options['use'] = SOAP_ENCODED;
$client = new SoapClient($url, $options);
//die(print_R($client->__getFunctions()));
return $client;
}
As you can see I print_r the code right after I have received it to check what I am getting returned and it is this:
As you can see this IDdtstring field is getting completely ignored.
Does anyone have any ideas as to why this may be happening? Is it something to do with encoding? I can't seem to get anywhere on this issue!
Thanks
I was able to retrieve the fields correctly, including IDdtstring, using your basic code. Perhaps you are not sending the parameters correctly?
function getInductionTimes($options) {
$client = createSoapRequest();
$inductionTimes = $client->FITinductionlist($options);
die(print_r($inductionTimes));
return $inductionTimes;
}
function createSoapRequest() {
$url = 'https://fitspace.m-cloudapps.com:444/FITSPACE/MHservice.asmx?WSDL';
$options["connection_timeout"] = 25;
$options["location"] = $url;
$options['trace'] = 1;
$options['style'] = SOAP_RPC;
$options['use'] = SOAP_ENCODED;
$client = new SoapClient($url, $options);
//die(print_R($client->__getFunctions()));
return $client;
}
getInductionTimes(array("IDDate" => "2013-06-28T13:00:00+01:00", "GYMNAME" => "Bournemouth"));
I managed to solve this issue by adding the line of code into my SOAP options array which I then presume was an issue with my WSDL being cached in PHP:
$options['cache_wsdl'] = WSDL_CACHE_NONE;

Categories