UPS Shipping API - ShipmentConfirmRequest错误

时间:2013-11-29 22:27:51

标签: php xml api ups

您好我正在使用WooCommerce为客户创建一个wordpress网站。该网站已完成,但客户希望能够从shop_order页面创建货件。我发现大部分问题,问题是我对UPS API的XML请求。我检查并重新检查,我似乎无法找到错误:

<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>

下面是我的xml标记,隐藏了敏感信息。

<?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>

我几乎就在这,但我被困在这个路障。如果有人能够对此有所了解,那将非常感激。

2 个答案:

答案 0 :(得分:4)

服务代码容器必须包含在包容器中。我之前有它。我花了很长时间才弄清楚这个愚蠢的错误。

之前:

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

后:

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

感谢您的帮助,是的,UPS需要一种奇怪的XML格式。

答案 1 :(得分:-3)

XML处理指令出现两次:

<?xml version="1.0" ?>

这表明存在两个不同的XML文档:

<?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>
  <!-- ... -->
</ShipConfirmRequest>