0

I am using UPS TimeInTransit API for finding Estimate shipping through the destination zip code on Magento 2 site. Yesterday It had stopped working and did not show results without giving destination city. before it had worked fine and give me the desired result according to the input zip code. Why is TimeInTransit API not working with only the destination zipcode?

Use code:

  $data ="<?xml version=\"1.0\"?>
        <AccessRequest xml:lang='en-US'>
            <AccessLicenseNumber>111112414134</AccessLicenseNumber>
            <UserId>1213243</UserId>
            <Password>13124123</Password>
       </AccessRequest>
       <?xml version='1.0'?>
        <TimeInTransitRequest xml:lang='en-US'>
          <Request>
            <TransactionReference>
            <CustomerContext>Site Name</CustomerContext>
              <XpciVersion>1.001</XpciVersion>
            </TransactionReference>
            <RequestAction>TimeInTransit</RequestAction>
          </Request>
          <TransitFrom>
            <AddressArtifactFormat>
              <PoliticalDivision2>Lake Elsinore</PoliticalDivision2>
              <PoliticalDivision1>California</PoliticalDivision1>
              <PostcodePrimaryLow>92530</PostcodePrimaryLow>
              <CountryCode>US</CountryCode>
            </AddressArtifactFormat>
          </TransitFrom>
          <TransitTo>
            <AddressArtifactFormat>
              <PoliticalDivision2></PoliticalDivision2>
              <PoliticalDivision1></PoliticalDivision1>
              <PostcodePrimaryLow>92562</PostcodePrimaryLow>
              <CountryCode></CountryCode>
            </AddressArtifactFormat>
          </TransitTo>
          <PickupDate>$today</PickupDate>
          <MaximumListSize>5</MaximumListSize>
          <InvoiceLineTotal>
            <CurrencyCode>USD</CurrencyCode>
            <MonetaryValue>1</MonetaryValue>
          </InvoiceLineTotal>
          <ShipmentWeight>
            <UnitOfMeasurement>
              <Code>$this->weightUnits</Code>
              <Description>Pounds</Description>
            </UnitOfMeasurement>
            <Weight>$packageWeight</Weight>
          </ShipmentWeight>
        </TimeInTransitRequest>";
        // This is the PRODUCTION server -- use when your testing is finished.
        // https://onlinetools.ups.com/ups.app/xml/TimeInTransit
        //This is the TESTING SERVER.
        //https://wwwcie.ups.com/ups.app/xml/TimeInTransit
        $ch = curl_init("https://onlinetools.ups.com/ups.app/xml/TimeInTransit");
        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);
        //echo '<!-- '. $result. ' -->'; // THIS LINE IS FOR DEBUG PURPOSES ONLY-IT WILL SHOW IN HTML COMMENTS
        $data = strstr($result, '<?');
        $xml = simplexml_load_string($data);
        $json = json_encode($xml);
        $dataArray = json_decode($json,TRUE);

Error Response: [Error] => Array ( [ErrorSeverity] => Hard [ErrorCode] => 270032 [ErrorDescription] => Invalid Destination Postal Code and City )

jawad ali
  • 7
  • 6

1 Answers1

0

I had the same issue with TimeInTransit and can't find anything in the UPS status page or in a changelog to explain it. The documentation clearly states that the city is optional. My code, which has been running for many years, only specified the origin zip code, the destination zip code, and the weight in the request. At first, I was getting the error "Invalid Origin Postal Code in TimeInTransit" and I resolved that by specifying the origin city in PoliticalDivision2 in the XML. But then I got reports that it still wasn't working for some addresses (but not all). For those requests, I got: "Invalid Destination Postal Code and CityFailure." Once I updated the code to specify the destination city as well in PoliticalDivision2, it worked.

  • I have only the destination zip code, not city and country information . previously It was working with destination zip code only but now it's showing an error without destination city. Is there any way it will work with destination zip code only? – jawad ali Jun 22 '22 at 06:57
  • I spoke with UPS Tech support and they confirmed that there were outages with the API starting June 20 and that they did not change the API to start requiring a city. I did a test this morning and am getting good responses without specifying city, so it looks like the issue was related to the outage. – Doug Bertlesman Jun 22 '22 at 14:29
  • I had nothing changed in the API call but now it's working without the city. so the issue is solved. – jawad ali Jun 29 '22 at 07:42