Magento 2.3 REST API: How to update shipment?
-
09-03-2021 - |
Question
I need to add carrier code and tracking number to the shipment by REST API.
For this, I am trying 2 different codes which I found from the search as below. But it doesn't update anything, not display any error and return the same array.
I don't know what should be order_id, parent_id and entity_id. I am using different ids from the order and shipment URL.
$shiptrack = [ "entity" => [ "order_id" => 6298, "parent_id" => 6298, "entity_id" => 12594, "weight"=> 0, "qty"=> 0, "description"=> "Tracking code Description", "track_number"=> "1234567", "title"=> "Custom Tracking Code", "carrier_code"=> "custom" ] ];
2.Tried all ids from the order and shipment URL.
$shiptrack = [
"items"=> [
[
"order_item_id"=>5813,
"qty"=> 0
]
],
"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
]
]
];
Solution
Inorder to add tracking information to a shipment you need to make a POST call to the following link
{base_url}/V1/shipment/track
Sample Body :
{ "entity": { "order_id": 291, "parent_id": 121, "description": "Tracking code Descripton", "track_number": "123456789", "title": "FEDEX", "carrier_code": "fedex" } }
Here order_id
is the one you see when you open Order View Page in Admin. See Ref Image, here Red marked is order id.
And parent_id
is the one you see when you open Shipment View Page in Admin (for which you are going to add tracking info). See Ref Image, here Red marked is parent id.
Make sure you do not forget to add Authentication Bearer to header of your request. Hope if finds you helpful.