1

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
    )

)

0

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

  • I dont think you do need the items, if left blank it assumes all items are delivered. Which works fine. But if i try using tracks i then get the error. – James Barr Dec 12 '18 at 8:30
  • Please check reference url – Aaditya Dec 12 '18 at 8:38
  • I did follow that but it still doesnt work – James Barr Dec 12 '18 at 9:45
  • The full error is this: [2018-12-12 09:50:26] main.CRITICAL: Could not save shipment {"exception":"[object] (Magento\\Framework\\Exception\\CouldNotSaveException(code: 0): Could not save shipment at /public_html/vendor/magento/module-sales/Model/Order/ShipmentRepository.php:147, Magento\\Framework\\Exception\\LocalizedException(code: 0): Cannot save track: Number can not be empty Carrier Code can not be empty at /public_html/vendor/magento/module-sales/Model/ResourceModel/Order/Shipment/Track.php:90)"} [] – James Barr Dec 12 '18 at 9:52
  • track_number and track_number shouldn't be empty. – Aaditya Dec 12 '18 at 10:31

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.