6

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:

  • U need to pass Billing & Shipping Address – Ankit Shah Jan 13 '17 at 7:20
  • But order is already placed with a customer having billing and shipping address. Do you have any example ? – BornCoder Jan 13 '17 at 7:27
7
+50

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.

  • I am getting error while updating after following your answer: ------------------- [2017-01-16 06:41:57] main.CRITICAL: exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (m2new.sales_shipment_track, CONSTRAINT SALES_SHIPMENT_TRACK_PARENT_ID_SALES_SHIPMENT_ENTITY_ID FOREIGN KEY (parent_id) REFERENCES sales_shipment (entity_id) ON DELETE CASCADE)' in /var/www/html/m2/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:228 – BornCoder Jan 16 '17 at 6:43
  • @BornCoder see my updated code. – Khoa TruongDinh Jan 16 '17 at 8:09
  • i placed your code and run it. it is not showing any error and printing $result also but nothing is adding in sales_shipment table and sales_shipment_track table. How to check where data is inserting or updating? – BornCoder Jan 16 '17 at 9:12
  • You can open the order. Find in Shipment tab, open the shipment. – Khoa TruongDinh Jan 16 '17 at 9:15
  • In shipment tab also , It's showing 'We couldn't find any records.' – BornCoder Jan 16 '17 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.