UPS TimeInTransit API not working without destination city

506 views Asked by At

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 )

1

There are 1 answers

3
Doug Bertlesman On

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.