fillup / walmart-partner-api-sdk-php

PHP client for Walmart Partner APIs
MIT License
37 stars 51 forks source link

Ship fails when multiple items exist #56

Closed goosehub closed 7 years ago

goosehub commented 7 years ago

I can't seem to ship on orders that contain multiple items, even when I attempt to do each item individually, or together. This is what I have. It works when there is one item in the order, but not when there is multiple. Below is what I have for shipping a single item. I loop through this when there are multiple items. lineNumber is correct, shipDateTime is parsing correctly, I'm pretty certain my variables are correct, especially as they work on orders with 1 item.

$ship_array = 
[
    'orderShipment' => [
        'orderLines' => [
            [
                'lineNumber' => (int) $item['vendor_item_id'],
                'orderLineStatuses' => [
                    [
                        'status' => 'Shipped',
                        'statusQuantity' => [
                            'unitOfMeasurement' => 'Each',
                            'amount' => (int) $item['quantity']
                        ],
                        'trackingInfo' => [
                            'shipDateTime' => date('Y-m-d\TH:i:s\Z', strtotime($ship_datetime)),
                            'carrierName' => [
                                'carrier' => $carrier_code
                            ],
                            'methodCode' => $shipping_method,
                            'trackingNumber' => (string) $tracking_number,
                            'trackingURL' => 'https://www.' . strtolower($carrier_code) . '.com',
                        ]
                    ]
                ]
            ]
        ]
    ]
];
try {
    $client = $this->create_walmart_sdk_client();
    $result = $client->ship($order['po_num'], $ship_array);
}
catch (Exception $e) {
    echo $error_message = $store . ' Outbound Exception: ' . $e->getMessage() . '<br>';
}

Here is the raw request that gets sent. Only trackingNumber changed for privacy.

<?xml version="1.0" encoding="UTF-8"?>
<ns3:orderShipment xmlns:ns3="http://walmart.com/mp/v3/orders">
 <ns3:orderLines>
  <ns3:orderLine>
   <ns3:lineNumber>1</ns3:lineNumber>
   <ns3:orderLineStatuses>
    <ns3:orderLineStatus>
     <ns3:status>Shipped</ns3:status>
     <ns3:statusQuantity>
      <ns3:unitOfMeasurement>Each</ns3:unitOfMeasurement>
      <ns3:amount>1</ns3:amount>
     </ns3:statusQuantity>
     <ns3:trackingInfo>
      <ns3:shipDateTime>2017-07-26T14:49:00Z</ns3:shipDateTime>
      <ns3:carrierName>
       <ns3:carrier>USPS</ns3:carrier>
      </ns3:carrierName>
      <ns3:methodCode>Standard</ns3:methodCode>
      <ns3:trackingNumber>9400110000000000000000</ns3:trackingNumber>
      <ns3:trackingURL>https://www.usps.com</ns3:trackingURL>
     </ns3:trackingInfo>
    </ns3:orderLineStatus>
   </ns3:orderLineStatuses>
  </ns3:orderLine>
 </ns3:orderLines>
</ns3:orderShipment>

I get the response

Walmart Outbound Exception: Error executing command: Client error response [url] https://marketplace.walmartapis.com/v3/orders/2579592039315/shipping [status code] 400 [reason phrase] Bad Request

Is there anything special that has to be done when shipping orders that have multiple items. Do any examples exist? Is there a bug with the SDK perhaps? Why does Walmart not have documentation on the shipping api call? Let me know if you can replicate or if you need more information from me. Thanks!

goosehub commented 7 years ago

I have no idea what I changed to get it to work, even looking at the git diff. I am going to close this, as my code is working right now and doesn't require any goofy work arounds, so I'll assume it was something dumb. Will reopen if needed.