I have problem with send SOAP query. For some reason my code [numerNadania] isn't good. I guess it's some problem with structure.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:e=http://e-nadawca.poczta-polska.pl
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<e:addReklamacje>
<reklamowanaPrzesylka
dataNadania="2018-05-22"
urzadNadania="260578"
powodReklamacjiOpis="TEST TEST TEST"
odszkodowanie="0" oplata="0" oczekiwaneOdszkodowanie="0">
<przesylka
guid="262A34BA2C1111116237B659B312F5EB"
numerNadania="00159007738099827991"
opis="TEST"
planowanaDataNadania="2018-05-22"
xsi:type="e:przesylkaBiznesowaType"/>
<powodReklamacji
idPowodGlowny="4"
powodGlownyOpis="TEST TEST TEST">
<powodSzczegolowy
idPowodSzczegolowy="9" powodSzczegolowyOpis="TEST TEST TEST"/>
</powodReklamacji>
</reklamowanaPrzesylka>
</e:addReklamacje>
</soapenv:Body>
</soapev:Envelope>
$options["login"] = "***";
$options["password"] = "***";
$options["soap_version"] = SOAP_1_2;
$wsdl = 'en.wsdl';
try {
$client = new SoapClient($wsdl,$options);
}
catch(Throwable $e) {
echo 'Wystąpił problem z połączniem API';
}
$params = array(
'reklamowanaPrzesylka' => array (
'przesylka' => array (
'guid' => getGuid(),
'numerNadania' => $id,
),
'powodReklamacji' => "Czas dostawy",
)
);
$problem = $client->addReklamacje($params);
stdClass Object ( [errorNumber] => 13250 [errorDesc] => Numer nadania dla składanych reklamacji jest wymagany [guid] => F8CF816CDF4DD8151116C0EE340C4031 )
Numer nadania dla składanych reklamacji jest wymagany - Send number is required [TRANSLATE]
In the past i have been using wsdl2php converters to create client code that resolves most of this type of issues.
See this one for example: https://github.com/rquadling/wsdl2php
They all work pretty much the same, you need to provide ?wsdl endpoint, run script and it will produce client code and output it in to file. Than you can include file and use generated classes and methods.
Hope this helps.
Related
I have been struggling for hours now on a SOAP connection and can't get it to work, this is what I have:
$url = 'https://xxx/connector.svc?singleWsdl';
$user = 'user';
$pass = 'pass';
$options = array(
'uri'=>'http://schemas.xmlsoap.org/soap/envelope/',
'style'=>SOAP_RPC,
'use'=>SOAP_ENCODED,
'soap_version'=>SOAP_1,
'cache_wsdl'=>WSDL_CACHE_NONE,
'connection_timeout'=>15,
'trace'=>true,
'encoding'=>'UTF-8',
'exceptions'=>true,
);
try {
$soapclient = new SoapClient($url, $options);
# $soapclient = new SoapClient($url);
}
catch(Exception $e) {
die($e->getMessage());
}
I tried '?wdsl' but then I get:
PHP Fatal error: SOAP-ERROR: Parsing WSDL: <message> 'IConnector_GetProduct_ServiceFaultFault_FaultMessage' already defined
A request with no parameters works fine:
$result = $soapclient->GetVersionInfo();
$last_request = $soapclient->__getLastRequest();
$last_response = $soapclient->__getLastResponse();
print "Request: ".$last_request ."\n";
print "Response: ".$last_response."\n";
print_r($result);
Result:
Request: <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="Unit4.AgressoWholesale.Connectors"><SOAP-ENV:Body><ns1:GetVersionInfo/></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><GetVersionInfoResponse xmlns="Unit4.AgressoWholesale.Connectors"><GetVersionInfoResult xmlns:a="http://schemas.datacontract.org/2004/07/Unit4.AgressoWholesale.Common.Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><a:FullVersion>14.4.18.0</a:FullVersion><a:Release>14</a:Release><a:ServicePack>4</a:ServicePack><a:Fix>18</a:Fix><a:Version>0</a:Version><a:CustomCode/><a:AWBuild>38</a:AWBuild><a:AWFix>003</a:AWFix><a:AWCustomBuild/><a:AWCustomFix/><a:AWCustomCustomerCode/></GetVersionInfoResult></GetVersionInfoResponse></s:Body></s:Envelope>
stdClass Object
(
[GetVersionInfoResult] => stdClass Object
(
[FullVersion] => 14.4.18.0
[Release] => 14
[ServicePack] => 4
[Fix] => 18
[Version] => 0
[CustomCode] =>
[AWBuild] => 38
[AWFix] => 003
[AWCustomBuild] =>
[AWCustomFix] =>
[AWCustomCustomerCode] =>
)
)
So far so good, but the trouble begins trying to log in, which is a must.. In SoapUI it works with:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:unit="Unit4.AgressoWholesale.Connectors" xmlns:unit1="http://schemas.datacontract.org/2004/07/Unit4.AgressoWholesale.Common.Contracts">
<soapenv:Header/>
<soapenv:Body>
<unit:Login>
<unit:SecurityContext>
<unit1:SessionToken></unit1:SessionToken>
<unit1:UserId>user</unit1:UserId>
<unit1:Password>pass</unit1:Password>
</unit:SecurityContext>
</unit:Login>
</soapenv:Body>
</soapenv:Envelope>
But converting this to PHP, I'm stranding here.. this is what I have tried:
$data = array( 'SecurityContext' => array( 'SessionToken' => ''
,'Password' => $user
,'UserId' => $pass)
);
$data = array( 'SessionToken' => ''
,'Password' => $user
,'UserId' => $pass
);
$data = new stdClass;
$data->SecurityContext = new stdClass;
$data->SecurityContext->SessionToken = '';
$data->SecurityContext->UserId = $pass;
$data->SecurityContext->Password = $user;
#$result = $soapclient->__call('Login',array($data));
#$result = $soapclient->Login($data);
$result = $soapclient->__soapCall('Login',array($data));
But no matter what I try, event without parameters or an empty array or stdClass, I get:
PHP Fatal error: Uncaught SoapFault exception: [s:ServiceFault] An exception occurred
It's driving me nuts, I can't find anything on the internet about the fatal exeption '[s:ServiceFault]'
What am I doing wrong? Any help will be greatly appreciated!
OK, writing out the problem sometimes is enough to get to an anwer!
The solution was two-fold:
1) get better error reporting by using a try{} catch:
try {
$result = $soapclient->__call('Login',array($data));
#$result = $soapclient->Login($data);
#$result = $soapclient->__soapCall('Login',array($data));
} catch (SoapFault $e) {
$error = $e->faultcode;
echo str_replace('>',">\n",$error) ;
}
$last_request = $soapclient->__getLastRequest();
$last_response= $soapclient->__getLastResponse();
print "\nRequest: " .str_replace('>',">\n",$last_request);
print "\nResponse: ".str_replace('>',">\n",$last_response);
That way I got just that litle more information I needed! to:
2) enter password in the password field and the username in the user field
It works!
For those interested
Using the array structure and the 'new stdClass' both work
all three ways of parsing the call work (also the two commented out ones, use which one you like)
I'm working on a flight booking API. I'm sending the data to the server in following way:
$location_URL = "http://59.162.33.102/ArzooWS/services/DOMFlightBooking?wsdl";
$action_URL ="http://booking.flight.arzoo.com";
$client = new SoapClient('http://59.162.33.102/ArzooWS/services/DOMFlightBooking?wsdl', array(
'soap_version' => SOAP_1_1,
'location' => $location_URL,
'uri' => $action_URL,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'trace' => 1,
));
I've also mentioned XML SOAP Body below edited parsed XML Formatted Request:
<?xml version="1.0" encoding="utf-8"?>
<Bookingrequest>
<onwardFlights>
<OriginDestinationOption>
<FareDetails>
<ChargeableFares>
<ActualBaseFare>5060</ActualBaseFare>
<Tax>4380</Tax>
<STax>32</STax>
<SCharge>0</SCharge>
<TDiscount>0</TDiscount>
<TPartnerCommission>0</TPartnerCommission>
</ChargeableFares>
<NonchargeableFares>
<TCharge>0</TCharge>
<TMarkup>300</TMarkup>
<TSdiscount>0</TSdiscount>
</NonchargeableFares>
</FareDetails>
<FlightSegments>
<FlightSegment>
<AirEquipType>321</AirEquipType>
<ArrivalAirportCode>DEL</ArrivalAirportCode>
<ArrivalDateTime>2013-10-20T08:00:00</ArrivalDateTime>
<DepartureAirportCode>BOM</DepartureAirportCode>
<DepartureDateTime>2013-10-20T06:00:00</DepartureDateTime>
<FlightNumber>6019</FlightNumber>
<OperatingAirlineCode>AI</OperatingAirlineCode>
<OperatingAirlineFlightNumber>6019</OperatingAirlineFlightNumber>
<RPH>
</RPH>
<StopQuantity>0</StopQuantity>
<airLineName>Air India</airLineName>
<airportTax>4380</airportTax>
<imageFileName>http://live.arzoo.com/FlightWS/image/AirIndia.gif</imageFileName>
<viaFlight>
</viaFlight>
<BookingClass>
<Availability>4</Availability>
<ResBookDesigCode>U</ResBookDesigCode>
</BookingClass>
<BookingClassFare>
<adultFare>5060</adultFare>
<bookingclass>U</bookingclass>
<classType>Economy</classType>
<farebasiscode>fjyS3YyUlEusLfJ4bwgPvQ==</farebasiscode>
<Rule>This fare is Refundable <br> Baggage : 25K<br>Booking Class : U|Re-Schedule Charges: Rs. 750 per sector + Fare difference (If any) +admin fee 500 + Service Fee of Rs. 250
Sector .|Cancellation Charges : Basic fare +Airline administration fee 500 + Service Charges 250 Per Passenger Per Sector .
|</Rule>
<adultCommission>0</adultCommission>
<childCommission>0</childCommission>
<commissionOnTCharge>0</commissionOnTCharge>
</BookingClassFare>
<Discount>0</Discount>
<airportTaxChild>0</airportTaxChild>
<airportTaxInfant>0</airportTaxInfant>
<adultTaxBreakup>2950,147,1283</adultTaxBreakup>
<childTaxBreakup>0,0,0</childTaxBreakup>
<infantTaxBreakup>0,0,0</infantTaxBreakup>
<octax>0</octax>
</FlightSegment>
</FlightSegments>
<id>arzoo11</id>
<key>wtZcSVMY/gphWFSOTFWg8nkII1434EZIGjnpJNQzayEK8sDjVS91GicTJzH+TWN+pNURIyTJYKOW
O8yH8+0tzpA4t8aEEvzaOE6ZnTtBotFDwLtSiN0xXiTOGgS0siJI1l7d9ata/3rxTgfh9d8ZSmFY
VI5MVaDyd5WrIWHlQL5zqWDbQb1E1IoDSY1wep73c6lg20G9RNQQnpVlWM7U0ZY7zIfz7S3O4J6m
G25LJItzqWDbQb1E1IoDSY1wep73c6lg20G9RNSKA0mNcHqe93OpYNtBvUTUpvdITjbFOR52+H1V
tJqs5kJfo6Sh44vDThgZv6ARhgviIKxphH+kbb9fDhZYRaCPm3lupCgitSmWO8yH8+0tzolfF9kG
WM+AaZ58PxEZgqCbbbGbXj1Z0D7dHS59eVX1JxMnMf5NY37ZbJ5llqmBpycTJzH+TWN+2WyeZZap
gacnEycx/k1jftlsnmWWqYGnJxMnMf5NY37ZbJ5llqmBpycTJzH+TWN+2WyeZZapgacnEycx/k1j
ftlsnmWWqYGnJxMnMf5NY36po4tljIBmEJgePqv2qP9fd/Usd8Uuz7FDwLtSiN0xXvtUK9az69O/
JxMnMf5NY37yK2PFSCI6AM2hLlYrFkYJQ8C7UojdMV7NoS5WKxZGCcr5VjCR04wgRviI6n9DzL3N
oS5WKxZGCUPAu1KI3TFezaEuVisWRglDwLtSiN0xXv4Xbn4sigRMv18OFlhFoI/cKcKe7FftvScT
JzH+TWN+2WyeZZapgacnEycx/k1jftlsnmWWqYGnJxMnMf5NY377Oxb/b44TR5Y7zIfz7S3O16CE
sDaAROm13h/OHWeGHw==</key>
</OriginDestinationOption>
</onwardFlights>
<returnFlights>
</returnFlights>
<personName>
<CustomerInfo>
<givenName>Rajnish</givenName>
<surName>Dubey</surName>
<nameReference>Mr.</nameReference>
<psgrtype>adt</psgrtype>
</CustomerInfo>
</personName>
<telePhone>
<phoneNumber>9595959595</phoneNumber>
</telePhone>
<email>
<emailAddress>rajnishdubey1988#gmail.com</emailAddress>
</email>
<creditcardno>5266474530046446</creditcardno>
<Clientid>7232326</Clientid>
<Clientpassword>*AB424E52FBBHDSFS74DFFSA7B747A9BAF61F8E</Clientpassword>
<partnerRefId>100200</partnerRefId>
<Clienttype>ArzooFWS1.1</Clienttype>
<AdultPax>1</AdultPax>
<ChildPax>0</ChildPax>
<InfantPax>0</InfantPax>
</Bookingrequest>
try
{
//$result = $client->getAvailability($dom->saveXML($request));
$result = $client->getBookingDetails($dom->saveXML($request));
$response= htmlentities($result);
echo "<h1> Client Response: </h1><pre>".htmlspecialchars($result, ENT_QUOTES)."</pre>";
}
catch(Exception $e){
echo "<h2>Exception Error!</h2>";
echo $e->getMessage();
}
Now when the data is being sent to the server I get an exception 'Wrong version'. I checked on the SERVER side, the log for this particular client isn't being hit at all. Means that the server didn't received the request. The same WSDL request format is created by AVAILABILITY API of the flight. I'm getting the available flight list by AVAILABILITY API. I converted the above code in XML, the API documentation has the same format as i'm sending the request. I checked on the internet but didn't find the solution for the same. Some says the version of SOAP i'm using is different but that's not the case. Because the Flight and Hotel Availability API Has same method of request and receiving the data from server.
Please help me. I'm stuck on this. Your help will be Appreciated.
this is working code of flight availibility by arzoo..
i also getting error while using SOAP CLIENT but when i use nusoap then they give me result..using this code if u get error like ip/password mismatch then You will call arzoo to verify your clientid and clientpassword
<?php
ini_set('max_execution_time','180');
include 'lib/nusoap.php';
$location_URL ='http://avail.flight.arzoo.com';
$action_URL ='http://demo.arzoo.com/ArzooWS/services/DOMFlightAvailability?wsdl';
$Request = '<Request>
<Origin>BOM</Origin>
<Destination>DEL</Destination>
<DepartDate>2017-02-02</DepartDate>
<ReturnDate>2017-02-02</ReturnDate>
<AdultPax>1</AdultPax>
<ChildPax>0</ChildPax>
<InfantPax>0</InfantPax>
<Currency>INR</Currency>
<Clientid>Given by Arzoo.com</Clientid>
<Clientpassword>Given by Arzoo.com</Clientpassword>
<Clienttype>ArzooFWS1.1</Clienttype>
<Preferredclass>E</Preferredclass>
<mode>ONE</mode>
<PreferredAirline>AI</PreferredAirline>
</Request>';
$clientinfo = array('soap_version'=>SOAP_1_1,
'location' =>$location_URL,
'uri' =>$action_URL,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'trace' => 1,
);
$client = new nusoap_client('http://demo.arzoo.com/ArzooWS/services/DOMFlightAvailability?wsdl', $clientinfo);
//print_r($client);
$result = $client->call('getAvailability', array($Request));
echo"<pre>";
print_r($result);
$clientInfo =simplexml_load_string(utf8_encode($result));
$flight = $clientInfo->Response__Depart->OriginDestinationOptions->OriginDestinationOption;
$error =$clientInfo->error__tag;
//echo $error;
var_dump($flight);
//exit;
//echo"<pre>";
//print_r($result);
//ECHO $error;
?>
Hi I'm trying to setup an api service with Limoanywhere system. But regardless of what I do I get invalid ApiKey & ApiID. I went into the back system and changed the ApiKey & ApiId multiple times but still no success.
Can anyone tell me if my code is correct?
<?php
$client = new SoapClient('https://qa.book.mylimobiz.com/api/ApiService.asmx?wsdl');
$options = array(
'ApiKey' => '***api key here****',
'ApiID' => '***api id here****'
);
$result = $client->__soapCall('Test', $options);
//var_dump($client->__getFunctions());
print_r($result);
?>
Here is the snippet from the service
http://qa.book.mylimobiz.com/api/ApiService.asmx?op=Test
Here is the result I get from when run my php code.
Array ( [TestResult] => Array ( [ResponseCode] => 1 [ResponseText] => Invalid ApiId or ApiKey ) )
Check this instead of test Test function not working giving error but test of the test all function are working.
<?php
$soapClient = new SoapClient("https://book.mylimobiz.com/api/ApiService.asmx?wsdl");
// Prepare SoapHeader parameters
$sh_param = array('apiId' => 'xxxxxx','apiKey' => 'xxxxxxxxxxxx');
$headers = new SoapHeader('https://book.mylimobiz.com/api/ApiService.asmx?wsdl', 'GetVehicleTypes', $sh_param);
// Prepare Soap Client
$trans = $soapClient->GetVehicleTypes($sh_param)->GetVehicleTypesResult;
echo "<pre>"; print_r($trans);
?>
I am trying to return all inventory from a certain warehouse in Netsuite. I am having some issues and was wondering if anyone could point me in the right direction. The internalId of the warehouse I am trying to query is 16. When I do the search it returns 0 items - but doesn't fail.
Here is the PHP code I am working with.
<?php
require_once 'PHPtoolkit.php';
require_once 'login_info.php';
global $myNSclient;
$internalID = '16'; //Internal ID of the warehouse I want to query to see what inventory it has
$inventorySearch = new nsComplexObject("ItemSearchBasic");
$searchValue = new nsRecordRef(array('type' => 'location', 'internalId' => $internalID ));
$multiSelect = new nsComplexObject('SearchMultiSelectField');
$multiSelect->setFields(array('operator'=>'anyOf','searchValue'=>$searchValue,"operatorSpecified" => true));
$inventorySearch->setFields(array('location'=>$multiSelect));
try
{
$searchResponse = $myNSclient->search($inventorySearch);
$totalRecords = $searchResponse->totalRecords;
if ($totalRecords > 0)
{
echo "records found";
foreach ($searchResponse->recordList as $record)
{
echo "<pre>";
print_r($record);
echo "</pre>";
}
}
else
{
echo "No result found.";
}
}
catch (Exception $e)
{
echo $e;
echo "Item is not found. Please try again.";
exit();
}
Here is the SOAP request
<?xml version="1.0" encoding="UTF-8" ?>
- <Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:core_2011_2.platform.webservices.netsuite.com" xmlns:ns2="urn:common_2011_2.platform.webservices.netsuite.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns3="urn:messages_2011_2.platform.webservices.netsuite.com">
- <Header>
- <passport actor="http://schemas.xmlsoap.org/soap/actor/next">
<email>xxxxx</email>
<password>[Content Removed for Security Reasons]</password>
<account>xxxxxx</account>
<role internalId="3" xsi:type="RecordRef" />
</passport>
</Header>
- <Bod
y>
- <search>
- <searchRecord xsi:type="ItemSearchBasic">
- <location operator="anyOf">
<searchValue internalId="16" type="location" />
</location>
</searchRecord>
</search>
</Body>
</Envelope>
$inventorySearch = new nsComplexObject("ItemSearchBasic");
$inventorySearch->setFields(array(
"location" => array(
"operator" => "anyOf",
"searchValue" => array(
"type" => "location",
"internalId" => $internalId
)
)
));
Then, do your try/catch.
But as I look at this, you are wanting to get item availability. That's a completely different call.
$filter = new nsComplexObject ( 'ItemAvailabilityFilter' );
$filter->setFields ( array (
"location" => array (
"operator" => "anyOf",
"searchValue" => new nsRecordRef ( array (
"type" => "location",
"internalId" => $internalId
) )
)
) );
I've spent significant amount of time building my own custom search using PHPToolKit v2011.2 endpoint, and got them to work after pulling my hair out as there aren't that many examples. With introduction of v2012_2 endpoint, things have changed and I have to relearn the things that I solved before. I "strongly" suggest that you use SAVED SEARCH, instead of trying to invent the way to do all your searches in PHP. Create a saved search in Netsuite, and call the SAVED SEARCH from your PHP with internalId of the search you created.
I'm attempting to get a shipping quote from an SOAP service. I've been able to successfully create authentication headers and query the SOAP service with basic requests that require no body parameters.
I'm able to create the proper structure for the request but the namespace values are not showing up in the request output.
Example code:
$client = new SoapClient("http://demo.smc3.com/AdminManager/services/RateWareXL?wsdl",
array('trace' => TRUE));
$headerParams = array('ns1:licenseKey' => $key,
'ns1:password' => $pass,
'ns1:username' => $user);
$soapStruct = new SoapVar($headerParams, SOAP_ENC_OBJECT);
$header = new SoapHeader($ns, 'AuthenticationToken', $soapStruct, false);
$client->__setSoapHeaders($header);
// Check if shipping is ready - base call
$ready_to_ship = $client->isReady();
The above works just fine and returns true if the shipping service is available.
So I use the following code to build the request body (only filling required fields):
I've also tried putting everything into an array and converting that to a SoapVar, I've tried including ns1: and ns2: in the body request creation but that hasn't worked either. I believe something needs to be adjusted in the request creation... not sure of the best approach..
$rate_request = $client->LTLRateShipment;
$rate_request->LTLRateShipmentRequest->destinationCountry = $destination_country;
$rate_request->LTLRateShipmentRequest->destinationPostalCode = $destination_postal_code;
$rate_request->LTLRateShipmentRequest->destinationPostalCode = $destination_postal_code;
$rate_request->LTLRateShipmentRequest->details->LTLRequestDetail->nmfcClass = $ship_class;
$rate_request->LTLRateShipmentRequest->details->LTLRequestDetail->weight = $ship_weight;
$rate_request->LTLRateShipmentRequest->originCountry = $origin_country;
$rate_request->LTLRateShipmentRequest->originPostalCode = $origin_postal_code;
$rate_request->LTLRateShipmentRequest->shipmentDateCCYYMMDD = $ship_date;
$rate_request->LTLRateShipmentRequest->tariffName = $tariff;
And it produces the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://webservices.smc.com">
<SOAP-ENV:Header>
<ns1:AuthenticationToken>
<ns1:licenseKey>xxxxxxxx</ns1:licenseKey>
<ns1:password>xxxxxxxx</ns1:password>
<ns1:username>xxxxxxxxm</ns1:username>
</ns1:AuthenticationToken>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:LTLRateShipment>
<LTLRateShipmentRequest>
<destinationCountry>USA</destinationCountry>
<destinationPostalCode>10001</destinationPostalCode>
<details>
<LTLRequestDetail>
<nmfcClass>60</nmfcClass>
<weight>300</weight>
</LTLRequestDetail>
</details>
<originCountry>USA</originCountry>
<originPostalCode>90210</originPostalCode>
<shipmentDateCCYYMMDD>20110516</shipmentDateCCYYMMDD>
<tariffName>DEMOLTLA</tariffName>
</LTLRateShipmentRequest>
</ns1:LTLRateShipment>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
But the output should include the namespaces (web: and web1: where appropriate). The above request returns an error code of missing tariffName.
Here's an example of what the xml request should look like:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:web="http://webservices.smc.com" xmlns:web1="http://web.ltl.smc.com">
<soapenv:Header>
<web:AuthenticationToken>
<web:licenseKey> string </web:licenseKey>
<web:password> string </web:password>
<web:username> string </web:username>
</web:AuthenticationToken>
</soapenv:Header>
<soapenv:Body>
<web:LTLRateShipment>
<web:LTLRateShipmentRequest>
<web1:LTL_Surcharge> string </web1:LTL_Surcharge>
<web1:TL_Surcharge> string </web1:TL_Surcharge>
<web1:destinationCity> string </web1:destinationCity>
<web1:destinationCountry> string </web1:destinationCountry>
<web1:destinationPostalCode> string </web1:destinationPostalCode>
<web1:destinationState> string </web1:destinationState>
<web1:details>
<!--Zero or more repetitions:-->
<web1:LTLRequestDetail>
<web1:nmfcClass> string </web1:nmfcClass>
<web1:weight> string </web1:weight>
</web1:LTLRequestDetail>
</web1:details>
<web1:discountApplication> string </web1:discountApplication>
<web1:mcDiscount> string </web1:mcDiscount>
<web1:orgDestToGateWayPointFlag> string </web1:orgDestToGateWayPointFlag>
<web1:originCity> string </web1:originCity>
<web1:originCountry> string </web1:originCountry>
<web1:originPostalCode> string </web1:originPostalCode>
<web1:originState> string </web1:originState>
<web1:rateAdjustmentFactor> string </web1:rateAdjustmentFactor>
<web1:shipmentDateCCYYMMDD> string </web1:shipmentDateCCYYMMDD>
<web1:shipmentID> string </web1:shipmentID>
<web1:stopAlternationWeight> string </web1:stopAlternationWeight>
<web1:surchargeApplication> string </web1:surchargeApplication>
<web1:tariffName> string </web1:tariffName>
<web1:weightBreak_Discount_1> string </web1:weightBreak_Discount_1>
</web:LTLRateShipmentRequest>
</web:LTLRateShipment>
</soapenv:Body>
</soapenv:Envelope>
Any suggestions / direction appreciated!
Ok... After too many hours of testing I finally have a solution..
I recreated the Authorization Token as a class and built the Soap Request without having to deal with any namespaces, SoapVars etc. it's surprisingly easy.
/* Object for holding authentication info
this could probably be accomplished using stdClass too */
class AuthHeader {
var $licenseKey;
var $password;
var $username;
function __construct($loginInfo) {
$this->licenseKey = $loginInfo['licenseKey'];
$this->password = $loginInfo['password'];
$this->username = $loginInfo['username'];
}
}
// set current soap header with login info
$client = new SoapClient("http://demo.smc3.com/AdminManager/services/RateWareXL?wsdl",
array('trace' => TRUE
));
// create header params array
$headerParams = array('licenseKey' => $key,
'password' => $pass,
'username' => $user);
// create AuthHeader object
$auth = new AuthHeader($headerParams);
// Turn auth header into a SOAP Header
$header = new SoapHeader($ns, 'AuthenticationToken', $auth, false);
// set the header
$client->__setSoapHeaders($header);
// Check if shipping is ready - base call
$ready_to_ship = $client->isReady();
// $last_request = $client->__getLastRequest();
$last_response = $client->__getLastResponse();
//print $last_request;
if ($last_response == true) {
print "Ready to ship\n";
// Create the shipping request
$d = new stdClass;
$d->nmfcClass = $ship_class;
$d->weight = $ship_weight;
$p = new stdClass;
$p->LTLRateShipmentRequest->destinationCountry = $destination_country;
$p->LTLRateShipmentRequest->destinationPostalCode = $destination_postal_code;
$p->LTLRateShipmentRequest->details = array($d);
$p->LTLRateShipmentRequest->originCountry = $origin_country;
$p->LTLRateShipmentRequest->originPostalCode = $origin_postal_code;
$p->LTLRateShipmentRequest->shipmentDateCCYYMMDD = $ship_date;
$p->LTLRateShipmentRequest->tariffName = $tariff;
$quote = $client->LTLRateShipment($p);
$last_request = $client->__getLastRequest();
$last_response = $client->__getLastResponse();
print "Request: " . $last_request;
print "\nResponse: " . $last_response;
}