SMSA Tracking status [duplicate] - opencart2.3

I'm making my first attempt to connect to a SOAP server from PHP, and I'm not understanding how to log in and get the data I need. The service I'm trying to connect to is the Hawley USA service http://hawleyusa.com/thcServices/StoreServices.asmx). I've been looking at a few posts on how to connect, and I get the basics. I've verified that I have SOAP enabled in my PHP, and I'm just trying to get an inventory list. Here's the code I'm using:
<?php
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$wsdl_path = "http://hawleyusa.com/thcServices/StoreServices.asmx?WSDL";
$login_id = 'mylogin_id';
$password = 'mypassword';
$client = new SoapClient($wsdl_path);
try {
echo "<pre>\n";
print($client->InventoryList(array("LoginID" => $login_id, "Password" => $password)));
echo "\n";
}
catch (SoapFault $exception) {
echo $exception;
}
However, when I run this code, I get this error:
SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in /Users/steve/Sites/mysite/hawley_client.php:12
When debugging, I can see the $client instance initiated, so I'm not sure why I'm getting this error.
Second question: Am I passing the user ID and password correctly?
Thanks.
Update: I threw in $client->__getLastRequest, and this is what I got:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://hawleyusa.com/thcServices/">
<SOAP-ENV:Body>
<ns1:InventoryList/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
So I can see that I'm missing my login ID and password. How do I add them to my InventoryList call?

You're close. Looking at the WSDL the InventoryList method takes an object called "request". Modify your call line slightly:
$client->InventoryList(array("request" => array("LoginId" => $login_id, "Password" => $password));

Probably it's not the same case but it also gives the same error if you don't specify empty strings in fields you don't need to use, taken from http://www.sitepoint.com/forums/showthread.php?755549-SOAP-XML-Object-reference-not-set-to-an-instance-of-an-object

I my case the problem was in typo:
In given docs the filed name was documentShipmentAddress (and I was using this)
but in wdsl (schema) was:
shipmentAddress
So that could be the problem with this error message.
I have changed the field name to shipmentAddress and it solved the problem.

Related

Getting "A service address has not been specified..." when using Perl SOAP::Lite to do call using wsdl

I'm trying to do a SOAP call to http://www.webservicex.net/ConvertSpeed.asmx using the WSDL.
My code is as follows
use SOAP::Lite;
my $client = SOAP::Lite->new;
$client = $client->service( "http://www.webservicex.net/ConvertSpeed.asmx?wsdl" );
my $soapResp = $client->call( "ConvertSpeed", 100, "kilometersPerhour", "milesPerhour" );
if ( $soapResp->fault ) {
print $soapResp->faultstring;
}
else {
print $soapResp->result;
}
This gives me the following error
A service address has not been specified either by using SOAP::Lite->proxy() or a service description)
I believe that the WSDL is supposed to provide the service address, but it does not seem to be doing that here.
I have tried setting the service address to http://www.webservicex.net/ConvertSpeed.asmx via $client->proxy("http://www.webservicex.net/ConvertSpeed.asmx") after $client->service(), but that just gives me an error saying:
Server did not recognize the value of HTTP header SOAPAction: #ConvertSpeed
I assumed the WSDL was supposed to provide the service address and so omitted the $client->proxy() bit and tried other stuff.
This ranged from chaining methods differently and eventually chaining as little as possible (the code above) to changing the way the call is made.
From this answer I tried
$client->ConvertSpeed(100, "kilometersPerhour", "milesPerhour")
which just seems to return nothing.
This is running on Perl 5.10 and version 0.714 of SOAP::Lite.
I'm not sure what else to try, but I have confirmed that the same SOAP call works from Python(see edit).
EDIT:
from zeep import Client
client = Client('http://www.webservicex.net/ConvertSpeed.asmx?wsdl')
result = client.service.ConvertSpeed(100, 'kilometersPerhour', 'milesPerhour')
print(result)
I posted this question to PerlMonks as well since it didn't seem to be doing well here. According to the answer I received there SOAP::Lite isn't ideal for a complex service using the WSDL. Instead everything should be specified using the uri() and proxy() methods. If the WSDL is to be used then XML::Compile::WSDL11 is the module to look at.
The answer supplies working code for the call using SOAP::Lite without the WSDL as follows :
$client = SOAP::Lite->new(
uri => 'http://www.webserviceX.NET/',
proxy => 'http://www.webservicex.net/ConvertSpeed.asmx',
);
$client->on_action(sub {"http://www.webserviceX.NET/ConvertSpeed"});
$client->autotype(0);
$sheader = SOAP::Header->new('');
$sheader->type(xml => '');
$client->ns('http://www.webserviceX.NET/','web');
$client->envprefix('soapenv');
push #request, SOAP::Data->name(speed => 100)->prefix('web');
push #request, SOAP::Data->name(FromUnit => 'kilometersPerhour')->prefix('web');
push #request, SOAP::Data->name(ToUnit => 'milesPerhour')->prefix('web');
$soapResp = $client->ConvertSpeed($sheader,#request);
print $soapResp->result,"\n";
If I get a working example using XML::Compile::WSDL11 I will post it here. As I am unsure if I am going to look into it soon I decided to at least post this since the question is more focused on using a WSDL with SOAP::Lite

Getting the error "Number of packages exceeds maximum" from FedEX API

I am getting "FedEx Ship Error: (8522) Number of packages exceeds maximum" error. I am trying to send a multiple-package shipment request to fedEX, but it is getting failed in first package request only.
For sending multiple shipment request to FedEX, we have to send separate request for each package, the master tracking information will be returned in reply from the first package requested. That master tracking information is then inserted into the requests for each additional package requested for that multiple-package shipment.
The example below is first package request.
Below is the XML request Body I am sending to FedEX API "https://wsbeta.fedex.com:443/xml"
The code is just preparing the data structure, converting it into XML and hitting the fedEX API with XML request.
my $http_request = HTTP::Request->new('POST', $config->{'URL'});
$http_request->content_type('application/x-www-form-urlencoded');
$http_request->content(Encode::encode_utf8($xml_request_body));
my $http_response;
eval {
$http_response = $ua->request($http_request);
};
return errorShipResponse($p) if (!defined $http_response || !$http_response->is_success);
my $response;
eval {
$response = XML::Simple::XMLin(
$http_response->content,
ForceArray => 1,
NSExpand => 1
);
};
$xml_request_body
<?xml version="1.0" encoding="UTF-8"?>
<ProcessShipmentRequest xmlns="http://fedex.com/ws/ship/v12">
<WebAuthenticationDetail>
<UserCredential>
<Key>aaaaaaaaaaa</Key>
<Password>aaaaaaaaaaaaaaaa</Password>
</UserCredential>
</WebAuthenticationDetail>
<ClientDetail>
<AccountNumber>111111111</AccountNumber>
<MeterNumber>111111111111</MeterNumber>
</ClientDetail>
<Version>
<ServiceId>ship</ServiceId>
<Major>12</Major>
<Intermediate>0</Intermediate>
<Minor>0</Minor>
</Version>
<RequestedShipment>
<ShipTimestamp>2016-09-06T06:42:41-04:00</ShipTimestamp>
<DropoffType>REGULAR_PICKUP</DropoffType>
<ServiceType>SMART_POST</ServiceType>
<PackagingType>YOUR_PACKAGING</PackagingType>
<TotalWeight>
<Units>LB</Units>
<Value>15.00</Value>
</TotalWeight>
<Shipper>
<AccountNumber>111111111111</AccountNumber>
<Tins>
<TinType>BUSINESS_STATE</TinType>
<Number444444444444</Number>
</Tins>
<Contact>
<CompanyName>aaaaaaaaaaaa</CompanyName>
<PhoneNumber>11111111</PhoneNumber>
</Contact>
<Address>
ADDRESS HERE
</Address>
</Shipper>
<Recipient>
<Contact>
<PersonName>mukta jain</PersonName>
<PhoneNumber>1234567899</PhoneNumber>
</Contact>
<Address>
<StreetLines>lwehcfkwdjh</StreetLines>
<City>NY</City>
<StateOrProvinceCode>NY</StateOrProvinceCode>
<PostalCode>12345</PostalCode>
<CountryCode>US</CountryCode>
<Residential>true</Residential>
</Address>
</Recipient>
<ShippingChargesPayment>
<PaymentType>SENDER</PaymentType>
<Payor>
<ResponsibleParty>
<AccountNumber>444444444</AccountNumber>
<Tins>
<TinType>BUSINESS_STATE</TinType>
<Number>4444444444</Number>
</Tins>
<Contact>
<CompanyName>aaaaaaaaa</CompanyName>
<PhoneNumber>111111111</PhoneNumber>
</Contact>
<Address>
<ADDRESS HERE>
</Address>
</ResponsibleParty>
</Payor>
</ShippingChargesPayment>
<SmartPostDetail>
<Indicia>PARCEL_SELECT</Indicia>
<AncillaryEndorsement>ADDRESS_CORRECTION</AncillaryEndorsement>
<SpecialServices>USPS_DELIVERY_CONFIRMATION</SpecialServices>
<HubId>1234</HubId>
<CustomerManifestId>123456</CustomerManifestId>
</SmartPostDetail>
<LabelSpecification>
<LabelFormatType>COMMON2D</LabelFormatType>
<ImageType>EPL2</ImageType>
<LabelStockType>STOCK_4X6</LabelStockType>
</LabelSpecification>
<RateRequestTypes>LIST</RateRequestTypes>
<PackageCount>3</PackageCount>
<RequestedPackageLineItems>
<SequenceNumber>1</SequenceNumber>
<GroupPackageCount>1</GroupPackageCount>
<Weight>
<Units>LB</Units>
<Value>5</Value>
</Weight>
<Dimensions>
<Length>7</Length>
<Width>7</Width>
<Height>7</Height>
<Units>IN</Units>
</Dimensions>
<CustomerReferences>
<CustomerReferenceType>INVOICE_NUMBER</CustomerReferenceType>
<Value>E2315141</Value>
</CustomerReferences>
<CustomerReferences>
<CustomerReferenceType>CUSTOMER_REFERENCE</CustomerReferenceType>
<Value>E2315141</Value>
</CustomerReferences>
</RequestedPackageLineItems>
</RequestedShipment>
</ProcessShipmentRequest>
You give us almost nothing to work with, so it's hard to be any help at all. But there's one thing that seems strange in your request body. Assuming that you're showing us a dump of a Perl data structure, it seems weird that all of your scalar values are implemented as anonymous arrays. For example, the line defining the package count is:
'PackageCount' => [ 3],
Where I'd expect to see:
'PackageCount' => 3,
It's possible that you have access to some documentation that tells you to do it this way, but it seems strange to me.
It would also explain the error message as the array reference would be interpreted as an integer which would almost certainly be far greater than any number expected by the API!
Update: When I wrote this answer, the question included what looked like a large Perl data structure which exhibited the weirdness that I discuss above. Now that has been changed to an XML document which seems to have the correct values. I have no idea where the original data structure came from or how it was used. And, in the absence of any feedback from the original poster, I have no idea how useful this answer is.

Cant tell if phpactiverecord is connecting to database

I am writing a web service for a droid app adn trying to use phpactiverecord. I am not using an mvc. I cannot tell whether it is connecting to my database correctly because I don't know what it returns when it fails or if it just can't be used without an mvc.
<?php
require_once '../libs/php-activerecord/ActiveRecord.php';
ActiveRecord\Config::initialize(function($cfg)
{
$cfg->set_model_directory('../libs/php-activerecord/models');
$cfg->set_connections(array(
'development' => 'mysql://username:password#localhost/dbname'));
});
//$json=$_GET ['json'];
$json = file_get_contents('php://input');
$obj = json_decode($json);
//echo $json;
$data = Users::all();
$user_name = $data->user_name;
echo($data);
$password = $data->password;
$posts = array(name =>$user_name,
password =>$password
);
header('Content-type: application/json');
echo json_encode(array('posts'=>$posts));
?>
It throws a 500 error when I try to go to the page which isn't very helpful.
I figured it out but thanks for trying to help. My hosting server has a wierd structure that required my path to include a bunch of extra stuff that would be unlikely to happen to anyone else... basically my include pat was wrong. turning on error reporting pointed out the problem quickly.

jasper Rest client - uuid not found in session

I have to code a PHP front end for my Jasper reports. I could successfully connect to the server, authenticate and view the repositories using the jasper REST calls. However, when I try to access a report, I get the following error in the response body:
Report not found (uuid not found in session)
The php code is given below:
$uri = "http://localhost:8080/jasperserver/rest/report/samples/Client_Information_Report?RUN_OUTPUT_FORMAT=html";
//PUT request to run the report
$response = Httpful\Request::put($uri, $payload)
->authenticateWith("jasperadmin", "jasperadmin")
->send();
$xml = new SimpleXMLElement($response->body);
$uuid = (String)$xml->uuid; //The uuid is successfully returned
$uri = "http://localhost:8080/jasperserver/rest/report/$uuid?file=report";
$report = Httpful\Request::get($uri)
->authenticateWith("jasperadmin", "jasperadmin")
->send();
I am able to confirm that a uuid is returned with the first PUT. Is there anything I am missing here? Any help is appreciated.
Janenz,
First check the info that is coming from the PUT response to see if there is actually a report being generated and that is not empty, you should receive something like this:
<report>
<uuid>d7bf6c9-9077-41f7-a2d4-8682e74b637e</uuid>
<originalUri>/reports/samples/AllAccounts</originalUri>
<totalPages>43</totalPages>
<startPage>1</startPage>
<endPage>43</endPage>
<file type="image/png">img_0_0_0</file>
<file type="image/gif">px</file>
<file type="text/html">report</file>
<file type="image/jpeg">img_0_42_27</file>
<file type="image/png">img_0_42_26</file>
</report>
Notice the number of pages and the files available.
I have not used the Httpful library, but another thing to check is the way that library uses the Basic Authentication. It may happen that the second call is logging you in again and creating a new session; that is why you cannot find the UUID of the current session.
I have a full JasperServer and PHP sample in GitHub that you can check, it has the repository browsing and input control rendering implemented.
I'm not sure what version of JasperReports Server you are using but in the new version there is a new REST API that makes requesting reports a lot easier; check the JasperReports Server Web Services Guide (Section 3.2). I have that implemented in the JRS-Wrapper Branch of my project.
Hope this helps!!
MarianoL

receiving this msg from zend: 'Zend_Soap_Client_Exception' with message 'Invalid URN'

does anyone know what this means
im doing a pretty simple call here in my indexAction -
private $wsdl = "https://mywsdlserver.com/open?wsdl";
$options = array(
"location"=>$this->wsdl,
"uri"=>$this->wsdl
);
$client = new Zend_Soap_Client($this->wsdl, $options);
print_r($client);
fyi i have tried this with and without the options
when i set the options i get the error
when i dont set the options i get an empty client
what id like to get back
is the xml i get when i just put https://mywsdlserver.com/open?wsdl in the addressbar
thanks for your help
The error indicates that the URL you are passing in the options is not valid. The one in your example is fine, so presumably this is not what you are really using.
However, the location and URI options don't apply in WSDL mode, so you're best off omitting them completely. See the docs for the Zend_Soap_Client constructor at: http://framework.zend.com/manual/en/zend.soap.client.html