phpmagento2magento-rest-api

Magento REST API tracking number not being updated


I am using Magento 2.2.2 version. I am trying to update tracking information through their rest API. Here is my code:

$tracking_str   =   
        '{
         "items": [
            {
              "extension_attributes": {},
              "order_item_id": "'.$orderItemId.'",
              "qty": "'.$qty_invoiced.'"
            }
          ],
          "notify": false,
          "appendComment": true,
          "comment": {
            "extension_attributes": {},
            "comment": "Item(s) has been shipped",
            "is_visible_on_front": 0
          },
          "tracks": [
            {
              "extension_attributes": {},
              "track_number": "'.$TrackingNumber.'",
              "title": "'.$ShipTitle.'",
              "carrier_code": "'.$carrierCode.'"
            }
          ],
          "packages": [
            {
              "extension_attributes": {}
            }
          ],
          "arguments": {
            "extension_attributes": {}
          }

        }';

I am passing the above things to php curl and for the first time, I am getting a response of shipment id. And the Order status is changing to 'complete' over the Magento API. However, tracking information like carrier code and tracking number are not being updated. When I run the code again, I am getting response as:

 res is: stdClass Object
(    [message] => Shipment Document Validation Error(s):
The order does not allow a shipment to be created.
You can't create a shipment without products.
)

I don't know, where I am going wrong.


Solution

  • Finally it worked!!!

    $tracking_str = [ "items"=> [ [ "order_item_id"=>$orderItemId, "qty"=> $qty_invoiced ] ], "notify" => true, "appendComment" => true, "comment" => [ "extension_attributes" => [], "comment" => "Item(s) has been shipped", "is_visible_on_front" => 0 ], "tracks" => [ [ "extension_attributes" => [], "track_number" => $TrackingNumber, "title" => $ShipTitle, "carrier_code" => $carrierCode ] ] ]
    

    The above code, i have used. some one in github forum's helped me. Thanks to them. Now tracking number, carrier code and title are being updated.