passing custom class variable in api call - php

I am using Amazon MWS Reports PHP Library and Got badly struck when requesting api with following code
$parameters = array (
'Merchant' => MERCHANT_ID,
'MarketplaceWebService_Model_TypeList' => DEFAULT_REPORT_TYPE,
'MarketplaceWebService_Model_StatusList' => array(
'FieldValue' =>'_CANCELLED_' , )
// 'MWSAuthToken' => '<MWS Auth Token>', // Optional
);
$request = new MarketplaceWebService_Model_GetReportRequestListRequest($parameters);
in MarketplaceWebService_Model_GetReportRequestListRequestclass constructor, it is defined as
public function __construct($data = null)
{
$this->fields = array (
'ReportRequestIdList' => array('FieldValue' => null, 'FieldType' => 'MarketplaceWebService_Model_IdList'),
'ReportTypeList' => array('FieldValue' => null, 'FieldType' => 'MarketplaceWebService_Model_StatusList'),
.......
I am unable to understand how should I pass my variable value ? can't understand how 'MarketplaceWebService_Model_IdList' type of variable will be created and passed??
when I use scratchpad for this query, these two arguments are showing in the following way
&ReportRequestIdList.Id.1=49499499399 (DUMMY, INT VALUE)
&ReportTypeList.Type.1=_GET_FLAT_FILE_ORDERS_DATA_
I can't pass any of custom type (Class type variables at all, Unable to understand this)

use the IdList class in Report API to set the format of the id list.
$id_list = new MarketplaceWebService_Model_IdList();
$id_list->setId($x);

Related

Laravel 5 passing page info with array

I'm trying to pass data about the page state (navbar links having active class when you are in that exact page), page title. I do so with an indexed array $pageInfo, however I am getting a syntax error and doen't know where?
Also do you think this is a good method or should I use view->share() instead?
public function clases()
{
$pageInfo[] =
(
'page_title' => 'Clases',
'menu_active' => 'CLases',
'sub_menu_active' => '',
);
return view('clases.list', compact('pageInfo'));
}
public function domicilio()
{
$pageInfo[] =
(
'page_title' => 'Clases a domicilio',
'menu_active' => 'Clases',
'sub_menu_active' => 'Clases a domicilio',
);
return view('clases.domicilio', compact('pageInfo'));
I suggest you read PHP basic syntax.
Basically you want to do this:
$pageInfo =
[
'page_title' => 'Clases',
'menu_active' => 'CLases',
'sub_menu_active' => '',
];
Arrays have a syntax of [key => val, ...] in PHP, you're using () as it seems.
Also $someArray[] = someValue, will append the someValue to an existing array, in your case that would create another, unwanted level of your array.
And last, you're not ending the domicilio() function. But I'll assume you just didn't paste it in (you should add } at the end, if that's not the case).

Multiple elements of same name in PHP SOAP Call

I know this type of question has been asked a number of times. I have spent several hours reading and trying the offered solutions - but none appear to work for my situation.
I need to send a SOAP request to an API that can contain an element that repeats like so:
<operationNumbers>
<operationNumber>1234</operationNumber>
<operationNumber>1235</operationNumber>
<operationNumber>1236</operationNumber>
<operationNumber>1237</operationNumber>
</operationNumbers>
I did read that perhaps I could do this:
$buildRequest = Array(
'myheader' => Array(
'date' => MY_DATE,
'id' => Array(
'client' => CLIENT,
'clientRef' => MYREF
)
),
'operationNumbers' => Array (
Array('operationNumber' => '1234'),
Array('operationNumber' => '1235')
)
);
$request = $client->__soapCall( 'getMultiOpDets', array($buildRequest) );
Sadly this does not work and results in 'invalid request', if I send in a single operation number eg:
...
'operationNumbers' => Array (
'operationNumber' => '1234'
)
...
The request is successful. I've tried soapVars/soapParams but cannot get it working using this approach. Any hints/tips/help appreciated.
So, I solved it.
$operationNumbersArray = array('1234','1235');
...
'operationNumbers' => array(
'operationNumber' => $operationNumbersArray
)
During my testing and fiddling about, I had inadvertently removed another value that was mandatory. The API did not give warning of it's omission (sadly).
Here is the code I use:
$wsdl = 'https://your.api/path?wsdl';
$client = new SoapClient($wsdl);
$multipleSearchValues = [1, 2, 3, 4];
$queryData = ['yourFieldName' => $multipleSearchValues];
$results = $client->YourApiMethod($queryData);
print_r($results);

PHP SOAP WSDL How to call soap action with the same method name

I have WSDL which returns me function list which is included below
[0] => ExternalCacheAccessRsp service(ExternalCacheAccessReq $parameters)
[1] => PingRsp service(PingReq $parameters)
[2] => SystemInfoRsp service(SystemInfoReq $parameters)
[3] => TimeRsp service(TimeReq $parameters)
How I can call PingReq function by
__soapCall()
When I am trying to call __soapCall('service') it returns me first method
"ExternalCacheAccessReq"
Thank you for your answer but both solutions are incorrect for this case.
In the first case Soap returns that I didn't pass attribute "CacheName" which is obligatory for "ExternalCacheAccessRsp" (first method).
In the second solution I have message that method "PingRsp" is not valid. The valid method is "service", but as you see on the top all methods have name "service".
The only way to do this is writing the XML request manually and sending by the method SoapClient::__doRequest.
Take a look at my answer here: stackoverflow.com/a/51099774/6783224
Given a SoapClient like:
$serviceUrl = 'your service address';
$client = new SoapClient($serviceUrl, array(
'trace' => true,
'soap_version' => SOAP_1_2,
'encoding' => 'UTF-8')
);
You can call your method like:
$client->PingRsp($parameters);
Best regards!
Your web service method is overloaded and so you should set the input parameters as specified by PingReq. The only way the server can distinguish between which overload you want is by the format and structure of the input parameters. You can examine the WSDL to see what the structure of PingReq is.
$client = new SoapClient('http://wsdl'); // <-- enter your wsdl url
// set $params as defined by your WSDL for the `PingReq` structure.
$params = array(
'param1' => 'one',
'param2' => 'two'
);
$response = $client->service($params);

Get values from form in an iphone app to a php web appication in get method?

i m trying to to get the request values of form in zend framework
earlier i was using the post method
but the the iphone app is sending me data in get method .
how do i can use it has i was using the post values like
$post = array(
'id'=>'2',
'email'=>'4',
)
i want to get values also in this form value when a form is submitted .
i was using this to get post values
$post = $this->getRequest ()->getPost ();
and i tried this to get get method values
$post = $this->getRequest();
but
i get this error
Cannot use object of type Zend_Controller_Request_Http as array in
this is the full error message
"Zend_Controller_Request_Http Object ( [_paramSources:protected] =>
Array ( [0] => _GET [1] => _POST ) [_requestUri:protected] =>
/platinum-picks/p-picks/index/registration [_baseUrl:protected] =>
/platinum-picks/p-picks [_basePath:protected] => [_pathInfo:protected]
=> /index/registration [_params:protected] => Array ( [controller] => index [action] => registration [module] => default )
[_rawBody:protected] => [_aliases:protected] => Array ( )
[_dispatched:protected] => 1 [_module:protected] => default
[_moduleKey:protected] => module [_controller:protected] => index
[_controllerKey:protected] => controller [_action:protected] =>
registration [_actionKey:protected] => action ) Fatal error: Cannot
use object of type Zend_Controller_Request_Http as array in D:\Program
Files\Zend\Apache2\htdocs\platinum-picks\application\models\User.php
on line 267"
If I understand correctly, you want to get the values passed using GET method and you have done the same successfully with POST values. The only change you need to make in such a scenario is this:
$post = $this->getRequest()->getPost ();
becomes
$get = $this->getRequest()->getParams();
This will also return parameters from other sources:
Retrieves a merged array of parameters, with precedence of userland params (see setParam()), $_GET, $_POST (i.e., values in the userland params will take precedence over all others).
So refer to the manual if this may be a problem for you.
You can find the GET variables using for example:
$this->getRequest()->getParams();
Or, for a specific variable:
$this->getRequest()->getParam('myVar');
This will also search for POST values. To search the GET vars only, use:
$this->getRequest()->getQuery('myVar');

PHP SoapClient - Returning attribute values in a response

I'm attempting to get values from a webservice.
The responce is formated as..
<campaign Id="200"> <name> test </name> </campaign>
PHP Code
SoapClient( "WSDL");
$return = $client->GetCampaigns('Username', 'Password' );
Yet when I attempt to access the return, I get just a stdClass with the name attribute..
public 'Campaign' =>
array
0 =>
object(stdClass)[46]
public 'Name' => string 'chris test' (length=10)
I find that I have to supply a "classmap" to SoapClient to get it to map the objects in the response to classes that are defined in PHP. In WSDLs the type name is usually lower camel case (starting with lower case and camel case the rest).
class MY_Campaign {
private $name;
function getName () { return $this->name; }
}
$options = array(
'classmap' => array(
'campaign' => 'MY_Campaign',
);
);
$client = new SoapClient('http://example.com/yourservice?wsdl', $options);
$return = $client->GetCampaigns ();
I might be able to supply a better answer if I had the WSDL. The classmap depends on the type definitions in the WSDL file.

Categories