Fedex API. 运输标签。多包裹运输

6

我正在使用FedEx API进行运输标签打印。对于一个包裹的标签打印成功,但是当我尝试打印多个包裹时,出现了错误:

stdClass Object
(
[Severity] => ERROR
[Source] => ship
[Code] => 2463
[Message] => The number of RequestedPackages in the RequestedShipment must be equal to 1
[LocalizedMessage] => The number of RequestedPackages in the RequestedShipment must be    equal to 1
)

我在请求中包含了“TotalWeight”和“PackageCount”,但没有起到作用。

$request['WebAuthenticationDetail'] = array('UserCredential' =>array('Key' => $auth['key'], 'Password' => $auth['password']));
$request['ClientDetail'] = array('AccountNumber' => $auth['accountNumber'], 'MeterNumber' => $auth['meterNumber']);
$request['TransactionDetail'] = array('CustomerTransactionId' => '*** Ground Domestic Shipping Request v12 using PHP ***');
$request['Version'] = array('ServiceId' => 'ship', 'Major' => '12', 'Intermediate' => '1', 'Minor' => '0');
$request['RequestedShipment'] = array('ShipTimestamp' => date('c'),
                                      'DropoffType' => 'REGULAR_PICKUP', // valid values REGULAR_PICKUP, REQUEST_COURIER, DROP_BOX, BUSINESS_SERVICE_CENTER and STATION
                                      'ServiceType' => 'FEDEX_GROUND', // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
                                      'PackagingType' => 'YOUR_PACKAGING', // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
                                      'Shipper' => $this->addShipper(),
                                      'Recipient' => $this->recipient,
                                      'ShippingChargesPayment' => $this->addShippingChargesPayment(),
                                      'LabelSpecification' => $this->addLabelSpecification(), 
                                      'RateRequestTypes' => array('LIST'), // valid values ACCOUNT and LIST
                                      'PackageCount' => count($this->packages),
                                      'TotalWeight' => array('Value' => array_sum($this->packages), 'Units' => 'LB'),
                                      'TotalShipmentWeight' => array('Value' => array_sum($this->packages), 'Units' => 'LB'),
                                      'PackageDetail' => 'INDIVIDUAL_PACKAGES',                                        
                                      'RequestedPackageLineItems' => $this->packageLineItem//array('0' => $this->packageLineItem)
);      


$this->packageLineItem[] = array('SequenceNumber'=>$i,
              'GroupPackageCount' => count($this->packages),
              'MasterTrackingID' => '123123123123',
              'TotalShipmentWeight' => array('Value' => array_sum($this->packages), 'Units' => 'LB'),
              'Weight' => array('Value' => $this->packages[$i-1], //weight!!!!!!!!!!!!!
                                'Units' => 'LB'),
              'CustomerReferences' => array('0' => array('CustomerReferenceType' => 'CUSTOMER_REFERENCE', 
                                                         'Value' => 'GR4567892'), // valid values CUSTOMER_REFERENCE, INVOICE_NUMBER, P_O_NUMBER and SHIPMENT_INTEGRITY
                                            '1' => array('CustomerReferenceType' => 'INVOICE_NUMBER', 
                                                         'Value' => 'INV4567892'),
                                            '2' => array('CustomerReferenceType' => 'P_O_NUMBER', 
                                                         'Value' => 'PO4567892')),
              'SpecialServicesRequested' => array('SpecialServiceTypes' => array('COD'),
                                                  'CodDetail' => array('CodCollectionAmount' => array('Currency' => 'USD', 'Amount' => 150),
                                                                       'CollectionType' => 'ANY')// ANY, GUARANTEED_FUNDS
                                                 )
 );

有人知道如何创建有效请求吗?

1
你有没有得到这个问题的答案?尽管我的“MasterTrackingId”是正确的,但我仍然收到相同的错误。 - user766987
3个回答

19
FedEx Rate APIFedEx Shipping API之间存在差异。您可以使用一个SOAP请求对多个包裹进行定价;然而,要运送多个物品托运(MPS),您必须为每个包裹执行一次发货请求。
第一个包裹(第一次请求中的包裹)将是您的主包裹,其中包含主跟踪号码。一旦您拥有了这个主跟踪号码,您必须将其附加到其余包裹的发货请求上。请参考最新的FedEx开发人员指南了解更多关于MPS托运的信息,并从FedEx开发人员门户下载执行国内特快快递MPS托运的示例代码。
需要注意的是,发货过程不会作为事务发生。因此,如果您正在尝试运送3个包裹,并且包裹1和2已成功提交,但由于某些未知原因包裹3失败,则您负责取消包裹1和2或重新提交包裹3。我建议任何人在创建实际运输之前都使用相同的发货API验证运输。
祝好!

https://www.fedex.com/us/developer/WebHelp/fsms/1401/dvg/DVG-WebHelp/2_7_4_1_Single_Shot_Shipping_Method.htm页面介绍了多件货物的单次发货方法,但我一直遇到同样的错误。有什么想法吗? - trss
我的意思是,你的回答暗示着这是不可能的。难道说这已经不再被支持了吗? - trss
@ozzy 我无法弄清楚在哪里将主跟踪附加到剩余包裹的发货请求中?我正在使用C#,但任何代码示例都可以。 - Morris S
1
我已经在谷歌上搜索了联邦快递开发者指南,但是没有找到任何MPS soap请求的实际示例。 - TKoL
我目前正在研究这个问题,使用的是2019年的巨兽开发指南(截至本评论时为最新版本)。SOAP没有明确说明,但191页是MPS部分的开始。查看PDF文件,MasterTrackingId应该添加到包裹中,但查看wsld文件,它实际上在Shipment直接的RequestedShipment上。PDF和wsld文件一致,看起来包裹上的RequestedPackageLineItem/SequenceNumber是SN所在的位置。如果有错误,我会进行编辑。 - ginn
显示剩余3条评论

1
我已经在测试服务器上成功使用MPS。我正在使用Python和这个美妙的封装,所以它不是SOAP的完整编写,但是货运基本上是:
SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP- ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:m0="http://fedex.com/ws/ship/v25">
<SOAP-ENV:Body>
<ProcessShipmentRequest xmlns="http://fedex.com/ws/ship/v25">
<WebAuthenticationDetail> <ParentCredential>
<Key>Hb1TfWMygUh7bbHP</Key>
<Password>u0mnYl8d6FRQK5Ot8SyxMXVqq</Password> </ParentCredential>
<UserCredential>
<Key>INPUT YOUR INFORMATION</Key>
<Password> INPUT YOUR INFORMATION </Password> </UserCredential>
</WebAuthenticationDetail> <ClientDetail>
<AccountNumber>XXXXXXXXX</AccountNumber>
<MeterNumber>XXXXXX</MeterNumber> </ClientDetail>
<TransactionDetail>
<CustomerTransactionId>ProcessShipmentRequest_2264</CustomerTransactionId> </TransactionDetail>
<Version>
<ServiceId>ship</ServiceId> <Major>25</Major> <Intermediate>0</Intermediate>
<Minor>0</Minor> </Version> <RequestedShipment>

我们需要任何必要的闭包,我们已经有了基本的装运工具等等...

(注:此处“shipment crap”为俚语,意思是“装运工具”或“装运杂物”。)
shipment.RequestedShipment.TotalWeight.Value
shipment.RequestedShipment.TotalWeight.Units
shipment.RequestedShipment.PackageCount

在您的首次发货中,请将任何要求在那个发货中的第一个包裹中,但包括 SequenceNumber = 1

<RequestedPackageLineItems>
<SequenceNumber>1</SequenceNumber> 
<Weight>
<Units>LB</Units>
<Value>20.0</Value> 
</Weight> 
<Dimensions>
<Length>12</Length> 
<Width>12</Width> 
<Height>12</Height> 
<Units>IN</Units>
</Dimensions> 
</RequestedPackageLineItems>

提交包裹请求以提交该批货物。 在该批货物的响应中,您将获取CompletedShipmentDetail.MasterTrackingId。在随后的批次中,您将像往常一样组成它们,除了您将包括一个

RequestedShipment.MasterTrackingId.TrackingIdType

并且

RequestedShipment.MasterTrackingId.MasterTrackingId

其中MasterTrackingId是从第一次运输中获取的;WDSL将列出TrackingIdType列表。我认为只使用“FEDEX”就可以了。运输重量和包裹计数将与普通运输相同--包裹重量和1。包裹行项目的编号将递增,直到达到PackageCount

希望这能补充@Ozzy Garcia的答案!他们肯定比FedEx的文档更详细!


1
FeDex手册有一个错误:“MasterTrackingID”是错误的。正确的是“MasterTrackingId”。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接