Question

I am passing data to update tracking code :

$userData = [
    "entity" => [
            "paymentStatusId" => 10
            "orderStatusId" => 8
            "tracking_code" => "237948723894789234"
            "comment" => "Neuer Kommentar"
            "transactionId" => 0
        ]
    ]

$client->put('rest/V1/orders/46',$userData); 

But it's returning below response. Please help me in passing the data for update tracking number or any order fields.

enter image description here

Error:

[2017-01-13 09:48:32] main.CRITICAL: exception 'LogicException' with message 'Property "PaymentStatusId" does not have corresponding setter in class "Magento\Sales\Api\Data\OrderAddressInterface".' in /var/www/html/m2/vendor/magento/framework/Reflection/NameFinder.php:100 Stack trace:

Was it helpful?

Solution

Go to http://devdocs.magento.com/swagger/ > salesShipmentTrackRepositoryV1

JSON:

{
  "entity": {
    "order_id": 345,
    "parent_id": 1,
    "entity_id": 1,
    "weight": 0,
    "qty": 0,
    "description": "Tracking code Descripton",
    "track_number": "1234567",
    "title": "Custom Tracking Code",
    "carrier_code": "custom"
  }
}
  • Parent Id - parent_id: is the foreign key from sales_shipment table.
  • Entity Id - entity_id(optional): is the entity id of sales_shipment_track table.
  • Carrier Code: Custom (custom), DHL (dhl), Federal Express (fedex), etc..

You can take a look some tables: sales_shipment, sales_shipment_track.

UPDATE SHIPMENT TRACK CODE:

<?php

$userData = array("username" => "admin", "password" => "test1234");
$ch = curl_init("http://mage21.loc/rest/V1/integration/admin/token");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData))));

$token = curl_exec($ch);


$shiptrack = [
    "entity" => [
        "order_id"=> 347, //can find in `sales_shipment_track` and `sales_shipment`
        "parent_id" => 145, //can find in `sales_shipment_track` and `sales_shipment`
        "entity_id"=> 1, //can find in `sales_shipment_track`. Removing it if want to create a new shipment track.
        "weight"=> 0,
        "qty"=> 0,
        "description"=> "Tracking code Description",
        "track_number"=> "1234567",
        "title"=> "Custom Tracking Code",
        "carrier_code"=> "custom"
  ]
];



$ch = curl_init("http://magen21.loc/rest/V1/shipment/track");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($shiptrack));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token)));

$result = curl_exec($ch);

$result = json_decode($result, 1);
echo '<pre>';print_r($result);

CREATE NEW SHIPMENT TRACK: If we want to create the new shipment track, we need to remove entity_id param.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top