fillup / walmart-partner-api-sdk-php

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

Bad Request from Shipping API #34

Closed cralls closed 7 years ago

cralls commented 7 years ago

Hi,

Maybe you can see something wrong with my XML here? I've tried changing src/Order.php to ns2 and adding the other namespace for http://walmart.com/ like the partner api documentation says but then I saw the closed Issue on this where someone mentioned try using otherCarrier but nothing seems to work. I always get Bad Request back from the API.

<?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>2016-12-15T21:12:45Z</ns3:shipDateTime>
                        <ns3:carrierName>
                            <ns3:carrier>USPS</ns3:carrier>
                        </ns3:carrierName>
                        <ns3:methodCode>Standard</ns3:methodCode>
                        <ns3:trackingNumber>9400110200864272098003</ns3:trackingNumber>
                        <ns3:trackingURL>https://tools.usps.com/go/TrackConfirmAction.action?tRef=fullpage&tLc=1&text28777=&tLabels=9400110200864272098003</ns3:trackingURL>
                    </ns3:trackingInfo>
                </ns3:orderLineStatus>
            </ns3:orderLineStatuses>
        </ns3:orderLine>
    </ns3:orderLines>
</ns3:orderShipment>

I'm also unsure what the lineNumber should be? Where does that number come from? I'm assuming it would be 1 for the first product in the order then 2, 3 etc...

fillup commented 7 years ago

Hi @cralls the lineNumber should be the number from the order details of the order for the item shipping. Since an order can have multiple items/lines, each has a given number, so you want to make sure you are updating the shipping for each line appropriately. Your XML looks fine to me as far as I can tell. Can you show me the array you passed into the client to generate this?

Have you Acknowledged the order before attempting to ship it?

cralls commented 7 years ago

Thanks for such a quick reply. I'll try to pull an order and look for the lineNumber.

Here's the array I passed, I just copied it from the OrderTest.php and added my variables and yes the order is Acknowledged:

$orderXml = [ 
    'orderShipment' => [ 
        'orderLines' => [ 
            [ 
            'lineNumber' => 1,
                'orderLineStatuses' => [ 
                    [ 
                    'status' => 'Shipped',
                    'statusQuantity' => [ 
                        'unitOfMeasurement' => 'Each',
                        'amount' => number_format ( $item->getQtyOrdered (), 0 ) 
                    ],
                    'trackingInfo' => [ 
                        'shipDateTime' => date ( "Y-m-d" ) . 'T' . date ( "H:m:s" ) . 'Z',
                        'carrierName' => [ 
                            'carrier' => 'USPS' 
                        ],
                        'methodCode' => 'Standard',
                        'trackingNumber' => $tracknum->getNumber (),
                        'trackingURL' => 'https://tools.usps.com/go/TrackConfirmAction.action' 
                    ] 
                ] 
            ] 
        ] 
    ] 
] 
];
solasus commented 7 years ago

I'm seeing a the same issue here. Also tried switching between ns2

any thoughts....?

Here's the code I'm using to generate:

$movementDate = date('Y-m-d', $movementDateRaw).'T14:30:00.000Z';
$trackingNos = explode(',',$orders['trackingno']);

$client = new Order([
        'consumerId' => $app_consumerId,
        'privateKey' => $app_privateKey,
        'wmConsumerChannelType' => $app_walmartChannelType,             
        ], 
        Order::ENV_PROD  
        );

$purchaseOrderId = $orders['poreference'];
$order = [
    'orderShipment' => [
        'orderLines' => [
             [
                'lineNumber' => $orders['orderitemreference'],
                'orderLineStatuses' => [
                     [
                        'status' => 'Shipped',
                        'statusQuantity' => [
                            'unitOfMeasurement' => 'Each',
                            'amount' => $orders['movementqty']
                        ],
                        'trackingInfo' => [
                            'shipDateTime' => $movementDate,
                            'carrierName' => [
                                'carrier' => $orders['carriername']
                            ],
                            'methodCode' => 'Ground',
                            'trackingNumber' => $trackingNos[0],
                            'trackingURL' => 'https://www.ups.com',
                        ]
                    ]
                ]
            ]
        ]
    ]
];
// print_r($order);
$response = $client->ship($purchaseOrderId, $order);
print_r($response,true);

Here's the resulting xml


<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>2016-12-16T14:30:00.000Z</ns3:shipDateTime>
            <ns3:carrierName>
              <ns3:carrier>UPS</ns3:carrier>
            </ns3:carrierName>
            <ns3:methodCode>Ground</ns3:methodCode>
            <ns3:trackingNumber>1Z9643630390001878</ns3:trackingNumber>
            <ns3:trackingURL>https://www.ups.com</ns3:trackingURL>
          </ns3:trackingInfo>
        </ns3:orderLineStatus>
      </ns3:orderLineStatuses>
    </ns3:orderLine>
  </ns3:orderLines>
</ns3:orderShipment>
cralls commented 7 years ago

Still not working, I tried matching the API Documentations Sample XML Request and I still get a 400 Bad Request error with the following XML:

<!xml version="1.0" encoding="UTF-8" standalone="yes">
<ns2:ordershipment xmlns:ns2="http://walmart.com/mp/v3/orders" xmlns:ns3="http://walmart.com/">
  <ns2:orderlines>
    <ns2:orderline>
      <ns2:linenumber>1</ns2:linenumber>
      <ns2:orderlinestatuses>
        <ns2:orderlinestatus>
          <ns2:status>Shipped</ns2:status>
          <ns2:statusquantity>
            <ns2:unitofmeasurement>Each</ns2:unitofmeasurement>
            <ns2:amount>1</ns2:amount>
          </ns2:statusquantity>
          <ns2:trackinginfo>
            <ns2:shipdatetime>2016-12-20T00:12:51Z</ns2:shipdatetime>
            <ns2:carriername>
              <ns2:carrier>USPS</ns2:carrier>
            </ns2:carriername>
            <ns2:methodcode>Standard</ns2:methodcode>        
            <ns2:trackingnumber>9405510200864280952178</ns2:trackingnumber>
          </ns2:trackinginfo>
        </ns2:orderlinestatus>
      </ns2:orderlinestatuses>
    </ns2:orderline>
  </ns2:orderlines>
</ns2:ordershipment>
solasus commented 7 years ago

How did you get your xml line to include: standalone="yes"

cralls commented 7 years ago

I added it to the code On Dec 20, 2016 11:55 AM, "solasus" notifications@github.com wrote:

How did you get your xml line to include: standalone="yes"

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/fillup/walmart-partner-api-sdk-php/issues/34#issuecomment-268326223, or mute the thread https://github.com/notifications/unsubscribe-auth/AIH0kT7Ga-c6RVPZ-1yqzZxmDghKeuwyks5rKCSogaJpZM4LOkaN .

solasus commented 7 years ago

where did you add that? and was it actually attempted against the api or did you just add here.

The reason I ask is that may be the key as it should tell the process to not be too depended on the DTD - whereas if that line is missing, then the default is "no" and it means strict adherence to a DTD.

cralls commented 7 years ago

Sorry, I was driving when I last replied. I added it to line 20 of A2X.php as follows:

    $this->xml = sprintf('<?xml version="%s" encoding="%s"

standalone="yes"?>', $version, $encoding);

The Walmart API Documentation Sample XML Request has that in there. I've sent it with and without and still get the 400 Bad Response from the API.

Casey Ralls http://www.vectorns.com/blog?format=feed&type=rss https://twitter.com/VectorNetSol https://plus.google.com/u/0/b/111960571789264200297/111960571789264200297/posts/p/pub

https://www.facebook.com/pages/Vector-Network-Solutions-eCommerce-Custom-PHP-Development-Services/51307794206 http://www.youtube.com/user/ax10m E-Commerce Manager | cralls@vectorns.com | 208.572.0468 | www.vectorns.com http://www.vectorns.com

On Tue, Dec 20, 2016 at 12:09 PM, solasus notifications@github.com wrote:

where did you add that? and was it actually attempted against the api or did you just add here.

The reason I ask is that may be the key as it should tell the process to not be too depended on the DTD - whereas if that line is missing, then the default is "no" and it means strict adherence to a DTD.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/fillup/walmart-partner-api-sdk-php/issues/34#issuecomment-268329648, or mute the thread https://github.com/notifications/unsubscribe-auth/AIH0ke2_SnKJxZlT5vuhR9TRWtHrrJSUks5rKCfbgaJpZM4LOkaN .

solasus commented 7 years ago

ah thanks for the clarification (and quick response).

I was leary to add the declaration there as some functions in the api spec seem to have it excluded (e.g. Refund order). Sounds like we're both trying a lot of things here. Hopefully @fillup might have some insight. Also, I've opened a ticket w/ WM support. Perhaps something will come of that.

cralls commented 7 years ago

No problem, I've opened a case with WM support too which usually isn't that helpful but perhaps they will be able to see what's wrong with our XML.

Casey Ralls http://www.vectorns.com/blog?format=feed&type=rss https://twitter.com/VectorNetSol https://plus.google.com/u/0/b/111960571789264200297/111960571789264200297/posts/p/pub

https://www.facebook.com/pages/Vector-Network-Solutions-eCommerce-Custom-PHP-Development-Services/51307794206 http://www.youtube.com/user/ax10m E-Commerce Manager | cralls@vectorns.com | 208.572.0468 | www.vectorns.com http://www.vectorns.com

On Tue, Dec 20, 2016 at 1:02 PM, solasus notifications@github.com wrote:

ah thanks for the clarification (and quick response).

I was leary to add the declaration there as some functions in the api spec seem to have it excluded (e.g. Refund order). Sounds like we're both trying a lot of things here. Hopefully @fillup https://github.com/fillup might have some insight. Also, I've opened a ticket w/ WM support. Perhaps something will come of that.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/fillup/walmart-partner-api-sdk-php/issues/34#issuecomment-268343733, or mute the thread https://github.com/notifications/unsubscribe-auth/AIH0kVgkjtvZFQdjNIrlvhWuJeeQ240Cks5rKDRbgaJpZM4LOkaN .

fillup commented 7 years ago

@cralls have you used something like Charles Proxy to inspect the request and full response to see if there is anything more informative in the response body about why the request was bad? I've wanted to update this SDK to capture the error responses better but haven't had the time. During development I used Charles Proxy pretty extensively though to watch everything and see what was happening.

cralls commented 7 years ago

@fillup I haven't but I will try it and see if I can come up with some more information for us and hopefully a fix too :)

Casey Ralls http://www.vectorns.com/blog?format=feed&type=rss https://twitter.com/VectorNetSol https://plus.google.com/u/0/b/111960571789264200297/111960571789264200297/posts/p/pub

https://www.facebook.com/pages/Vector-Network-Solutions-eCommerce-Custom-PHP-Development-Services/51307794206 http://www.youtube.com/user/ax10m E-Commerce Manager | cralls@vectorns.com | 208.572.0468 | www.vectorns.com http://www.vectorns.com

On Tue, Dec 20, 2016 at 2:27 PM, Phillip Shipley notifications@github.com wrote:

@cralls https://github.com/cralls have you used something like Charles Proxy to inspect the request and full response to see if there is anything more informative in the response body about why the request was bad? I've wanted to update this SDK to capture the error responses better but haven't had the time. During development I used Charles Proxy pretty extensively though to watch everything and see what was happening.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/fillup/walmart-partner-api-sdk-php/issues/34#issuecomment-268364339, or mute the thread https://github.com/notifications/unsubscribe-auth/AIH0kQnZFMxumSaKYbxDhwqjujmMPpcSks5rKEhJgaJpZM4LOkaN .

cralls commented 7 years ago

@fillup I'm not sure the Charles Proxy is going to give us the info we need. It's only showing me the request/response between my browser and the apache web server, it's not going to show me the request/response between the web server and the API which is what we need to get at.

Casey Ralls http://www.vectorns.com/blog?format=feed&type=rss https://twitter.com/VectorNetSol https://plus.google.com/u/0/b/111960571789264200297/111960571789264200297/posts/p/pub

https://www.facebook.com/pages/Vector-Network-Solutions-eCommerce-Custom-PHP-Development-Services/51307794206 http://www.youtube.com/user/ax10m E-Commerce Manager | cralls@vectorns.com | 208.572.0468 | www.vectorns.com http://www.vectorns.com

On Tue, Dec 20, 2016 at 2:27 PM, Phillip Shipley notifications@github.com wrote:

@cralls https://github.com/cralls have you used something like Charles Proxy to inspect the request and full response to see if there is anything more informative in the response body about why the request was bad? I've wanted to update this SDK to capture the error responses better but haven't had the time. During development I used Charles Proxy pretty extensively though to watch everything and see what was happening.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/fillup/walmart-partner-api-sdk-php/issues/34#issuecomment-268364339, or mute the thread https://github.com/notifications/unsubscribe-auth/AIH0kQnZFMxumSaKYbxDhwqjujmMPpcSks5rKEhJgaJpZM4LOkaN .

solasus commented 7 years ago

ok... let's add to the bizarre... This worked for me:

`<?xml version="1.0" encoding="UTF-8"?>

36 Shipped Each 1 2016-12-19T14:30:00.000Z UPS Standard 1Z9643630399284557 https://wwwapps.ups.com/tracking/tracking.cgi?tracknum=1Z9643630399284557 ` this did NOT work (identical except for values)... ` 4 Shipped Each 1 2016-12-20T14:30:00.000Z UPS Standard 1Z9643630391811483 https://wwwapps.ups.com/tracking/tracking.cgi?tracknum=1Z9643630391811483 ` On further investigation it looks like we may have some data issues ... the order says a quantity of 3. When importing the order, there were 5 lines total (the import seems to break each multiple quantity into individual order lines). Still I'm encouraged that the first process went through... but now more confused than before - hah! WM support wrote back and asked for the request / response ... I've sent them the above + the response code/message.
cralls commented 7 years ago

Interesting, that is definitely promising though! I have a couple questions: How did you decide what the linenumber would be? Also, curious what the xmlns:ns4 is coming from?

Casey Ralls http://www.vectorns.com/blog?format=feed&type=rss https://twitter.com/VectorNetSol https://plus.google.com/u/0/b/111960571789264200297/111960571789264200297/posts/p/pub

https://www.facebook.com/pages/Vector-Network-Solutions-eCommerce-Custom-PHP-Development-Services/51307794206 http://www.youtube.com/user/ax10m E-Commerce Manager | cralls@vectorns.com | 208.572.0468 | www.vectorns.com http://www.vectorns.com

On Wed, Dec 21, 2016 at 8:59 AM, solasus notifications@github.com wrote:

ok... let's add to the bizarre... This worked for me:

<?xml version="1.0" encoding="UTF-8"?> <ns3:ordershipment xmlns:ns2=" http://walmart.com/mp/orders" xmlns:ns3="http://walmart.com/mp/v3/orders" xmlns:ns4="http://walmart.com/">

36 Shipped Each 1 2016-12-19T14:30:00.000Z UPS Standard 1Z9643630399284557 https:// wwwapps.ups.com/tracking/tracking.cgi?tracknum=1Z9643630399284557 this did NOT work... 4 Shipped Each 1 2016-12-20T14:30:00.000Z UPS Standard 1Z9643630391811483 https:// wwwapps.ups.com/tracking/tracking.cgi?tracknum=1Z9643630391811483 On further investigation it looks like we may have some data issues ... the order says a quantity of 3. When importing the order, there were 5 lines total (the import seems to break each multiple quantity into individual order lines). Still I'm encouraged that the first process went through... but now more confused than before - hah! WM support wrote back and asked for the request / response ... I've sent them the above + the response code/message. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub , or mute the thread .
solasus commented 7 years ago

for the xmlns:ns4 ... I just got from the response example (directly below the request)

The line number we got on the Get all released orders method https://developer.walmartapis.com/#get-all-released-orders

cralls commented 7 years ago

Ok, so good news. It seems to be working for me too now. So before I send the tracking number I'm now grabbing the order and using the linenumber on the order rather than assuming it would be 1 for the first time 2 for the second item etc... For the order I tested the linenumber was in fact 1 for the first item on the order. It's interesting that you got a 36? At any rate, I'm sure that linenumber needs to match up to add the tracking number correctly so the final XML that works is as follows which is the same XML I posted before without the standalone="yes" part.

<!xml version="1.0" encoding="UTF-8"> <ns2:ordershipment xmlns:ns2="http://walmart.com/mp/v3/orders" xmlns:ns3="http://walmart.com/">

1 Shipped Each 1 2016-12-20T00:12:51Z USPS Standard 9405510200864280952178 The only change to the code I've made is in the Order.php to the $schema starting on line 195 changing ns3 to ns2 and adding the ns3 namespace since that's what the Walmart API Documentation calls for but ns3 may work too? I haven't tested it. $schema = [ '/orderShipment' => [ 'namespace' => 'ns2', 'childNamespace' => 'ns2', ], '/orderShipment/orderLines' => [ 'sendItemsAs' => 'orderLine', ], '/orderShipment/orderLines/orderLine/orderLineStatuses' => [ 'sendItemsAs' => 'orderLineStatus', ], '@namespaces' => [ 'ns2' => 'http://walmart.com/mp/v3/orders', 'ns3' => 'http://walmart.com/' ], ]; *Casey Ralls* E-Commerce Manager | cralls@vectorns.com | 208.572.0468 | www.vectorns.com On Wed, Dec 21, 2016 at 9:08 AM, solasus wrote: > for the xmlns:ns4 ... I just got from the response example (directly below > the request) > > The line number we got on the Get all released orders method > https://developer.walmartapis.com/#get-all-released-orders > > — > You are receiving this because you were mentioned. > Reply to this email directly, view it on GitHub > , > or mute the thread > > . >
michaeljberry commented 7 years ago

So I'm struggling to get this to work also. I continue to receive this error:

Uncaught GuzzleHttp\Exception\ClientException: Client error response [url] https://marketplace.walmartapis.com/v3/orders/CustomerPOID/shipping [status code] 400 [reason phrase] Bad Request

Here's the code to call ship:

$tracking = $client->ship(
            $order_num,
            [
                'orderShipment' => [
                    'orderLines' => [
                        [
                            'lineNumber' => $lineNumber,
                            'orderLineStatuses' => [
                                [
                                    'status' => 'Shipped',
                                    'statusQuantity' => [
                                        'unitOfMeasurement' => 'Each',
                                        'amount' => $quantity
                                    ],
                                    'trackingInfo' => [
                                        'shipDateTime' => $date,
                                        'carrierName' => [
                                            'carrier' => $carrier
                                        ],
                                        'methodCode' => 'Standard',
                                        'trackingNumber' => $tracking_id,
                                        'trackingURL' => $trackingURL
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        );

Here's the xml that's formed from the above call:

<?xml version="1.0" encoding="UTF-8"?>
  <ns2:ordershipment xmlns:ns2="http://walmart.com/mp/v3/orders" xmlns:ns3="http://walmart.com/">
    <ns2:orderlines>
      <ns2:orderline>
        <ns2:linenumber>1</ns2:linenumber>
        <ns2:orderlinestatuses>
          <ns2:orderlinestatus>
            <ns2:status>Shipped</ns2:status>
            <ns2:statusquantity>
              <ns2:unitofmeasurement>Each</ns2:unitofmeasurement>
              <ns2:amount>1</ns2:amount>
            </ns2:statusquantity>
            <ns2:trackinginfo>
              <ns2:shipdatetime>2017-02-24T14:47:36000Z</ns2:shipdatetime>
              <ns2:carriername>
              <ns2:carrier>USPS</ns2:carrier>
            </ns2:carriername>
            <ns2:methodcode>Standard</ns2:methodcode>
            <ns2:trackingnumber>Tracking Number Is Here</ns2:trackingnumber>
            <ns2:trackingurl>https://tools.usps.com/go/TrackConfirmAction.action?tLabels=TrackingNumberIsHere</ns2:trackingurl>
          </ns2:trackinginfo>
        </ns2:orderlinestatus>
      </ns2:orderlinestatuses>
    </ns2:orderline>
  </ns2:orderlines>
</ns2:ordershipment>

Here's my adjusted Order.php $shema array:

$schema = [
        '/orderShipment' => [
            'namespace' => 'ns2',
            'childNamespace' => 'ns2',
        ],
        '/orderShipment/orderLines' => [
            'sendItemsAs' => 'orderLine',
        ],
        '/orderShipment/orderLines/orderLine/orderLineStatuses' => [
            'sendItemsAs' => 'orderLineStatus',
        ],
        '@namespaces' => [
            'ns2' => 'http://walmart.com/mp/v3/orders',
            'ns3' => 'http://walmart.com/'
            /************************ 
            I've tried the following (with no luck) to match Sample Response in the documentation found here: https://developer.walmart.com/#/apicenter/marketPlace under Orders->Shipping Updates
            'ns2' => 'http://walmart.com/mp/orders',
            'ns3' => 'http://walmart.com/mp/v3/orders'                   
            'ns4' => 'http://walmart.com/'
            *************************/
        ],
    ];

I've taken your advice to get the order before trying to push the tracking number as shown here:

$order = $client->get([
    'purchaseOrderId' => $order_num
]);

and this is the order that I retrieve:

Array ( 
    [statusCode] => 200 
    [purchaseOrderId] => Customer PO ID 
    [customerOrderId] => Customer Order ID 
    [customerEmailId] => ptdixiegal@aol.com 
    [orderDate] => 2017-02-23T23:30:50.000Z 
    [shippingInfo] => Array ( 
        [phone] => Customer Phone Number 
        [estimatedDeliveryDate] => 2017-03-09T07:00:00.000Z 
        [estimatedShipDate] => 2017-02-28T07:00:00.000Z 
        [methodCode] => Value 
        [postalAddress] => Array ( 
            [name] => Customer Name
            [address1] => Customer Address 
            [city] => Customer City 
            [state] => Customer State
            [postalCode] => Customer ZIP Code 
            [country] => USA 
            [addressType] => RESIDENTIAL 
        ) 
    ) 
    [orderLines] => Array ( 
        [orderLine] => Array ( 
            [lineNumber] => 1 
            [item] => Array ( 
                [productName] => Product Name Is Here 
                [sku] => GH2 
            ) 
            [charges] => Array ( 
                [charge] => Array ( 
                    [chargeType] => PRODUCT 
                    [chargeName] => ItemPrice 
                    [chargeAmount] => Array ( 
                        [currency] => USD 
                        [amount] => 11.45 
                    ) 
                ) 
            ) 
            [orderLineQuantity] => Array ( 
                [unitOfMeasurement] => EACH 
                [amount] => 1 
            ) 
            [statusDate] => 2017-02-23T23:46:24.000Z 
            [orderLineStatuses] => Array ( 
                [orderLineStatus] => Array ( 
                    [status] => Acknowledged 
                    [statusQuantity] => Array ( 
                        [unitOfMeasurement] => EACH 
                        [amount] => 1 
                    ) 
                ) 
            ) 
        ) 
    ) 
) 

I use the lineNumber from the get call as the lineNumber for the ship call. Any ideas on why it's not working?

solasus commented 7 years ago

The WM api (or perhaps Guzzle, or most likely my own ignorance is to blame) ... is not well documented and/or handles errors poorly. It seems that just about anything results in a "400 [reason phrase] Bad Request" error. We found that if you attempt to post a second time to the same order that you'll see this error. Because we run batch processes these errors would kill the process in the middle - especially if someone updated an order or even a part of an order mid-day. To get around this I commented out a couple of lines in /vendor/guzzlehttp/command/src/AbstractClient.php around ln 171

//        return new $cn(
//            "Error executing command: " . $transaction->exception->getMessage(),
//            $transaction,
//            $transaction->exception
//        );

hope this helps...

cralls commented 7 years ago

@solasus That's interesting that you get the Bad Request for posting multiple times. That would explain why I had such a difficult time getting this going and then all of a sudden the next few orders mysteriously were working.

@michaeljberry I guess the only part I haven't posted is my ship call so here's that for you. Hope it helps!

$orderXml = [ 
    'orderShipment' => [ 
        'orderLines' => [ 
            [ 
            'lineNumber' => $lineNumber['lineNumber'],
                'orderLineStatuses' => [ 
                    [ 
                        'status' => 'Shipped',
                        'statusQuantity' => [ 
                            'unitOfMeasurement' => 'Each',
                            'amount' => $lineNumber['qty']
                        ],
                        'trackingInfo' => [ 
                            'shipDateTime' => date ( "Y-m-d" ) . 'T' . date ( "H:m:s" ) . 'Z',
                            'carrierName' => [ 
                                'carrier' => 'USPS' 
                            ],
                            'methodCode' => 'Standard',
                            'trackingNumber' => $tracknum->getNumber (),
                            'trackingURL' => 'https://tools.usps.com/go/TrackConfirmAction.action' 
                        ] 
                    ] 
                ] 
            ] 
        ] 
    ] 
];
try {
    $response = $orders->ship ( $purchaseOrderId, $orderXml );
} catch (Exception $e) {
    Mage::log($e->getMessage());
}
fillup commented 7 years ago

Sorry I disappeared for a while, although not sure I could have added much. Glad you guys were able to figure it out. With the error handling causing the 400 it might be best to post each order shipment status individually to be able to catch when it happens.