UPS Shipping API - ShipmentConfirmRequest Error

。_饼干妹妹 提交于 2019-12-07 00:39:41

问题


Hello I am creating a wordpress website for a client using WooCommerce. The site is complete but the client wants the ability to create shipments from the shop_order page. I have most of this figured out, the problem is my XML request to the UPS API. I have checked and recheck, and I cant seem to find the error:

<ShipmentConfirmResponse><Response><ResponseStatusCode>0</ResponseStatusCode><ResponseStatusDescription>Failure</ResponseStatusDescription><Error><ErrorSeverity>Hard</ErrorSeverity><ErrorCode>10002</ErrorCode><ErrorDescription>The XML document is well formed but the document is not valid</ErrorDescription></Error></Response></ShipmentConfirmResponse>

Below is my xml mark up with sensitive info hidden.

<?xml version="1.0" ?>
<AccessRequest xml:lang='en-US'>
    <AccessLicenseNumber>******</AccessLicenseNumber>
    <UserId>********</UserId>
    <Password>********</Password>
</AccessRequest>
    <?xml version="1.0" ?>
    <ShipConfirmRequest xml:lang='en-US'>
    <Request>
    <TransactionReference>
        <CustomerContext>Customer Context</CustomerContext>
        <XpciVersion>1.0</XpciVersion>
    </TransactionReference>
     <RequestAction>ShipConfirm</RequestAction>
     <RequestOption>validate</RequestOption>
 </Request>
 <Shipment>
     <Shipper>
        <ShipperNumber>*******</ShipperNumber>
         <Name>Canyon Werks, LLC</Name>
         <Address>
             <AddressLine>2941 Brookspark Drive</AddressLine>
            <AddressLine></AddressLine>
            <City>North Las Vegas</City>
            <StateProvinceCode>NV</StateProvinceCode>
            <PostalCode>89030</PostalCode>
            <CountryCode>US</CountryCode>
        </Address>
        <Phone>
            <Number>7022552222</Number>
        </Phone>
    </Shipper>
    <ShipTo>
        <Name>Justin Walker</Name>
        <Address>
            <AddressLine>2675 Windmill Pkwy</AddressLine>
            <AddressLine>3024</AddressLine>
            <City>Henderson</City>
            <StateProvinceCode>NV</StateProvinceCode>
            <PostalCode>89074</PostalCode>
            <CountryCode>US</CountryCode>
        </Address>
        <Phone>
            <Number>7024609485</Number>
        </Phone>
    </ShipTo>
    <ShipFrom>
        <Name>Canyon Werks, LLC</Name>
        <Address>
            <AddressLine>2941 Brookspark Drive</AddressLine>
            <AddressLine></AddressLine>
            <City>North Las Vegas</City>
            <StateProvinceCode>NV</StateProvinceCode>
            <PostalCode>89030</PostalCode>
            <CountryCode>US</CountryCode>
        </Address>
        <Phone>
            <Number>7022552222</Number>
        </Phone>
    </ShipFrom>
    <PaymentInformation>
        <ShipmentCharge>
            <Type>01</Type>
            <BillShipper>
                <AccountNumber>*******</AccountNumber>
            </BillShipper>
        </ShipmentCharge>
    </PaymentInformation>
    <Service>
        <Code>03</Code>
    </Service>
    <Package>
        <Packaging>
            <Code>02</Code>
            <Description>Customer Supplied</Description>
        </Packaging>
        <Dimensions>
            <UnitOfMeasurement>
                <Code>IN</Code>
            </UnitOfMeasurement>
            <Length>16</Length>
            <Width>12</Width>
            <Height>6</Height>
        </Dimensions>
        <PackageWeight>
            <UnitOfMeasurement>
                <Code>LBS</Code>
            </UnitOfMeasurement>
            <Weight>6.07</Weight>
        </PackageWeight>
    </Package>
</Shipment>
<LabelSpecification>
    <LabelImageFormat>
        <Code>GIF</Code>
    </LabelImageFormat>
</LabelSpecification>
</ShipConfirmRequest>

I am almost there on this, but I am stuck at this road block. If anyone can shed some light into this it would be much appreciated.


回答1:


It was the service code container it must be included in the package container. I had it before it. Took me quite a while to figure out this dumb mistake on my part.

Before:

...
<Service>
    <Code>03</Code>
</Service>
<Package>
    ...

After:

...
<Package>
    <Service>
        <Code>03</Code>
    </Service>
    ...

Thanks for the help, and yes UPS requires a strange XML format.




回答2:


The XML processing instruction appears twice:

<?xml version="1.0" ?>

This indicates the presence of two distinct XML documnents:

<?xml version="1.0" ?>
<AccessRequest xml:lang='en-US'>
  <AccessLicenseNumber>******</AccessLicenseNumber>
  <UserId>********</UserId>
  <Password>********</Password>
</AccessRequest>

and

<?xml version="1.0" ?>
<ShipConfirmRequest xml:lang='en-US'>
  <Request>
    <TransactionReference>
      <CustomerContext>Customer Context</CustomerContext>
      <XpciVersion>1.0</XpciVersion>
    </TransactionReference>
    <RequestAction>ShipConfirm</RequestAction>
    <RequestOption>validate</RequestOption>
  </Request>
  <!-- ... -->
</ShipConfirmRequest>


来源:https://stackoverflow.com/questions/20294168/ups-shipping-api-shipmentconfirmrequest-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!