skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. this solution it works for me.

    {
      "appendComment": true,
      "notify": true,
      "comment": {
        "comment": "shipment creado via webservice",
        "is_visible_on_front": 1
      },
      "tracks": [
        {
          "track_number": "3SCEMW182389201",
          "title": "UPS",
          "carrier_code": "Carrier code n"
        }
      ]
    }
    

    remove items.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search