Magento 2 API Create an Shipment

As a robust, scalable and multi-featured e-commerce platform, Magento 2 allows users to create shipments of an order using API. This is a useful feature that helps you create shipments easily and quickly.

In this article, I will instruct you to create a shipment with Magento 2 API through the below steps:

Create A Shipment With Magento 2 API

To create a shipment, initially, you have to get the order_item_id of each item to be shipped. In this post, assuming that you need to create the shipments for the Sprite Yoga Companion Kit and the Radiant Tee-M-Orange. Because the Sprite Yoga Companion Kit is a bundle product, only the top-level order_item_id (5) needs to be included. The Radiant Tee-M-Orange has the order_item_id as 3.

Note:

  • If you want to create a partial shipment, define only those order_item_ids that are to be shipped now.
  • The status of an order will be automatically changed to Complete if the call is successful on a full shipment.

Endpoint

POST <host>/rest/<store_code>/V1/order/3/ship where 3 is the order id.

Headers

Content-Type application/json

Authorization Bearer <administrator token>

Payload

The tracks array optionally allows you to include one or more tracking numbers for the shipment.

The Code Sample

{
  "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"
    }
  ]
}

Response

A shipment ID, such as 3.

Verify The Results

  • Access your admin panel.
  • Navigate to Sales > Shipments, here you will see the shipment shown in the grid.
  • Navigate to Sales > Orders, here you will see the status of the order is Complete.

Conclusion

Above are the detailed instruction for creating a shipment with Magento 2 API. Hopefully, this post is helpful for you. If you have any questions or want to discuss something related to this post, don’t hesitate to leave a comment below!

Enjoyed the tutorial? Spread it to your friends!