1

I need to show estimated date and time with shipping method name. I am trying USPS api to get estimated date and time but facing some error. Below the api which i am trying and the error.

https://production.shippingapis.com/ShippingAPI.dll?API=SDCGetLocations&XML=05510755428

https://production.shippingapis.com/ShippingAPI.dll?API=PriorityMail&XML=5510755428

Array ( [Number] => 80040B19 [Description] => XML Syntax Error: Please check the XML request to see if it can be parsed.(B) [Source] => USPSCOM::DoAuth )

If anyone can help with this then please let me know.

0

For the delivery date and time, you need to use 'RateTimeInTransit' in the 'RequestOption'. By filling the appropriate details , you will get an array which will have a field 'timeintransit'. You can fetch the required information from there. Please check : https://prnt.sc/tjkkti.

    $data ="<?xml version=\"1.0\"?>  
<AccessRequest xml:lang=\"en-US\">  
    <AccessLicenseNumber>$this->AccessLicenseNumber</AccessLicenseNumber>  
    <UserId>$this->UserID</UserId>  
    <Password>$this->Password</Password>  
</AccessRequest>  
<?xml version=\"1.0\"?>  
<RatingServiceSelectionRequest xml:lang=\"en-US\">  
    <Request>
      <RequestAction>Rate</RequestAction>  
      <RequestOption>RateTimeInTransit</RequestOption>  
    </Request>
<Shipment>  
    <NumOfPieces>33</NumOfPieces>
    <Shipper>  
      <ShipperNumber>$this->shipperNumber</ShipperNumber>  
      <Address>  
        <AddressLine1>$this->ShipperAddressLine1</AddressLine1>  
        <City>$this->ShipperCity</City>  
        <PostalCode>$this->ShipperPostalCode</PostalCode>  
        <CountryCode>$this->ShipperCountryCode</CountryCode>  
      </Address>  
    </Shipper>  
    <ShipTo>  
      <CompanyName></CompanyName>
      <Address>  
        <AddressLine1>$toAddressLine1</AddressLine1>
        <City>$toCity</City>
        <PostalCode>$toZip</PostalCode>  
        <CountryCode>$toCountry</CountryCode>
      </Address>
    </ShipTo>  
   <ShipFrom>  
      <CompanyName></CompanyName>
      <Address>  
        <AddressLine1>$fromAddressLine1</AddressLine1>
        <City>$fromCity</City>
        <PostalCode>$fromZip</PostalCode>  
        <CountryCode>$fromCountry</CountryCode>
      </Address>
    </ShipFrom>         
    <Service>  
      <Code>$service</Code>  
      <Description>$serviceDesc</Description>  
    </Service>  
    <Package>  
      <PackagingType>  
        <Code>$packageTypeCode</Code>  
      </PackagingType>  
      <PackageWeight>  
        <UnitOfMeasurement>  
          <Code>$this->weightUnits</Code>  
        </UnitOfMeasurement>  
        <Weight>$weight</Weight>  
      </PackageWeight>  
      <Dimensions>  
        <UnitOfMeasurement>  
          <Code>$this->dimensionsUnits</Code>  
        </UnitOfMeasurement>  
          <Length>$length</Length>  
          <Width>$width</Width>  
          <Height>$height</Height>  
      </Dimensions>  
    </Package>  
<DeliveryTimeInformation>
  <PackageBillType>03</PackageBillType>
  <Pickup>
    <Date>$today</Date>
  </Pickup>
</DeliveryTimeInformation>
</Shipment>  
</RatingServiceSelectionRequest>";  
$ch = curl_init("https://www.ups.com/ups.app/xml/Rate");  
curl_setopt($ch, CURLOPT_HEADER, 1);  
curl_setopt($ch,CURLOPT_POST,1);  
curl_setopt($ch,CURLOPT_TIMEOUT, 60);  
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);  
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);  
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);  
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);  
$result=curl_exec ($ch);  
$data = strstr($result, '<?');
$xml = simplexml_load_string($data);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
curl_close($ch); 
| improve this answer | |
  • I need it for USPS shipping methods. Not for ups shipping methods. Looks like you have provided answer for ups shipping method. – Manish Soni Jul 18 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.