Magento – Magento 2 REST API ship order tracks error

apimagento2restshipping

I can create a shipment for an order via REST API. But when i try to add tracks i get the error: Carrier Code can not be empty.

This is my code:
Array
(
[items] => Array
(
)

[notify] => 1
[appendComment] => 1
[comment] => Array
    (
        [comment] => Sent via Parcelforce
        [is_visible_on_front] => 1
    )

[tracks] => Array
    (
        [extension_attributes] => Array
            (
            )

        [track_number] => P2G9999999
        [title] => Parcelforce
        [carrier_code] => custom
    )

)

Best Answer

To create a shipment, you need the order_item_id of each item to be shipped.

Endpoint

POST http://<host>/rest/default/V1/order/3/ship

where 3 is the order id.

Headers

Content-Type application/json

Authorization Bearer <administrator token>

Body > Data

{
  "items": [
    {
      "order_item_id": 3,
      "qty": 1
    },
    {
      "order_item_id": 5,
      "qty": 1
    },
    {
      "order_item_id": 11,
      "qty": 1
    }
  ],
  "tracks": [
    {
      "track_number": "1Y-9876543210",
      "title": "United Parcel Service",
      "carrier_code": "ups"
    }
  ]
}

Reference

Related Topic