I am trying to call FreightQuote API using SoapClient for getting quote.
I am getting a response but it is a validation error. The error type is "Unknown" and message is "General error occurred".
My code:
$apiHostPath = "https://b2b.Freightquote.com/WebService/QuoteService.asmx?wsdl";
$AuthClient = new SoapClient($apiHostPath);
$xmlString = file_get_contents("temp.xml");
$soapBody = new SoapVar($xmlString, XSD_ANYXML);
$result = $AuthClient->GetRatingEngineQuote(array($soapBody));
echo get_class($result);
print_r($result);
My XML file:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetRatingEngineQuote xmlns="http://tempuri.org/">
<request>
<CustomerId>customerid</CustomerId>
<QuoteType>B2B</QuoteType>
<ServiceType>LTL</ServiceType>
<QuoteShipment>
<IsBlind>false</IsBlind>
<PickupDate>2019-02-17T00:00:00</PickupDate>
<SortAndSegregate>false</SortAndSegregate>
<UseStackableFlag>false</UseStackableFlag>
<DeclaredValue>20</DeclaredValue>
<MaxPickupDate />
<TLDeliveryDate />
<TLEquipmentType>Any</TLEquipmentType>
<TLEquipmentSize>Any</TLEquipmentSize>
<TLTarpSizeType>NoTarpRequired</TLTarpSizeType>
<ShipmentLocations>
<Location>
<LocationType>Origin</LocationType>
<HasLoadingDock>false</HasLoadingDock>
<IsConstructionSite>false</IsConstructionSite>
<RequiresInsideDelivery>false</RequiresInsideDelivery>
<IsTradeShow>false</IsTradeShow>
<TradeShow>TradeShowDesc</TradeShow>
<IsResidential>false</IsResidential>
<RequiresLiftgate>false</RequiresLiftgate>
<HasAppointment>false</HasAppointment>
<IsLimitedAccess>false</IsLimitedAccess>
<LocationAddress>
<PostalCode>60632</PostalCode>
<CountryCode>US</CountryCode>
</LocationAddress>
<AdditionalServices />
</Location>
<Location>
<LocationType>Destination</LocationType>
<HasLoadingDock>false</HasLoadingDock>
<IsConstructionSite>false</IsConstructionSite>
<RequiresInsideDelivery>false</RequiresInsideDelivery>
<IsTradeShow>false</IsTradeShow>
<TradeShow>TradeShowDesc</TradeShow>
<IsResidential>false</IsResidential>
<RequiresLiftgate>false</RequiresLiftgate>
<HasAppointment>false</HasAppointment>
<IsLimitedAccess>false</IsLimitedAccess>
<LocationAddress>
<PostalCode>44113</PostalCode>
<CountryCode>US</CountryCode>
</LocationAddress>
<AdditionalServices />
</Location>
</ShipmentLocations>
<ShipmentProducts>
<Product>
<Class>55</Class>
<Weight>1200</Weight>
<Length>0</Length>
<Width>0</Width>
<Height>0</Height>
<ProductDescription>Books</ProductDescription>
<PackageType>Pallets_48x48</PackageType>
<IsStackable>false</IsStackable>
<DeclaredValue>0</DeclaredValue>
<CommodityType>GeneralMerchandise</CommodityType>
<ContentType>NewCommercialGoods</ContentType>
<IsHazardousMaterial>false</IsHazardousMaterial>
<NMFC />
<DimWeight>0</DimWeight>
<EstimatedWeight>0</EstimatedWeight>
<PieceCount>5</PieceCount>
<ItemNumber>0</ItemNumber>
<ProductDrops />
</Product>
</ShipmentProducts>
<ShipmentContacts />
</QuoteShipment>
</request>
<user>
<Name>****</Name>
<Password>****</Password>
<CredentialType>Default</CredentialType>
</user>
</GetRatingEngineQuote>
</soap:Body>
</soap:Envelope>
I solved it and posting it here so it can be helpful to others with same problem. I refer this question and it's selected answer solved my problem. The code written in question just need one modification, $soapBody
variable was previously passed within array, which needed to be passed directly without array. The correct line is shown below:
$result = $AuthClient->GetRatingEngineQuote($soapBody);
The XML file is read and passed as an XML string so it needed to be start from its actual body, as shown below:
<GetRatingEngineQuote xmlns="http://tempuri.org/">
<request>
<CustomerId>customerid</CustomerId>
<QuoteType>B2B</QuoteType>
<ServiceType>LTL</ServiceType>
<QuoteShipment>
<IsBlind>false</IsBlind>
<PickupDate>2019-02-13T14:12:48</PickupDate>
<SortAndSegregate>false</SortAndSegregate>
<ShipmentLocations>
<Location>
<LocationName>Location</LocationName>
<LocationType>Origin</LocationType>
<HasLoadingDock>false</HasLoadingDock>
<IsConstructionSite>false</IsConstructionSite>
<IsResidential>false</IsResidential>
<RequiresInsideDelivery>false</RequiresInsideDelivery>
<IsTradeShow>false</IsTradeShow>
<RequiresLiftgate>false</RequiresLiftgate>
<HasAppointment>false</HasAppointment>
<IsLimitedAccess>false</IsLimitedAccess>
<ContactName>testuser</ContactName>
<ContactPhone>5551237777</ContactPhone>
<ContactEmail>XXXXX</ContactEmail>
<LocationAddress>
<AddressName>Address 1</AddressName>
<StreetAddress>123 Main</StreetAddress>
<City>Ohio</City>
<StateCode>OH</StateCode>
<PostalCode>30303</PostalCode>
<CountryCode>US</CountryCode>
</LocationAddress>
</Location>
<Location>
<LocationName>Location name</LocationName>
<LocationType>Destination</LocationType>
<HasLoadingDock>false</HasLoadingDock>
<IsConstructionSite>false</IsConstructionSite>
<IsResidential>false</IsResidential>
<RequiresInsideDelivery>false</RequiresInsideDelivery>
<IsTradeShow>false</IsTradeShow>
<RequiresLiftgate>false</RequiresLiftgate>
<HasAppointment>false</HasAppointment>
<IsLimitedAccess>false</IsLimitedAccess>
<ContactName>Somename</ContactName>
<ContactPhone>33333333</ContactPhone>
<ContactEmail>[email protected]</ContactEmail>
<LocationAddress>
<AddressName>Address 2</AddressName>
<StreetAddress>123 Main</StreetAddress>
<City>Atlanta</City>
<StateCode>GA</StateCode>
<PostalCode>60606</PostalCode>
<CountryCode>US</CountryCode>
</LocationAddress>
</Location>
</ShipmentLocations>
<ShipmentProducts>
<Product>
<Class>400</Class>
<Weight>200</Weight>
<Length>50</Length>
<Width>48</Width>
<Height>36</Height>
<ProductDescription>Books</ProductDescription>
<PackageType>Pallets_48x48</PackageType>
<IsStackable>false</IsStackable>
<DeclaredValue>0</DeclaredValue>
<CommodityType>Metals</CommodityType>
<ContentType>NewCommercialGoods</ContentType>
<IsHazardousMaterial>false</IsHazardousMaterial>
<DimWeight>0</DimWeight>
<EstimatedWeight>0</EstimatedWeight>
<PieceCount>1</PieceCount>
<ItemNumber>0</ItemNumber>
</Product>
</ShipmentProducts>
</QuoteShipment>
</request>
<user>
<Name>somename</Name>
<Password>somepassword</Password>
<CredentialType>Default</CredentialType>
</user>
</GetRatingEngineQuote>