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.