In our previous post, we created an invoice. And with the order item id obtained, we will find out how to create a shipment using Magento 2 API. Specify the order item id here.
In our example, the order item id for Argus All-Weather Tank is 47, and Fusion Backpack is 48. If the shipment is called successfully, the status of the order will change to Complete.
Generate Admin access token
POST <host>/rest/V1/integration/customer/token
Enter your admin username and password in Body sections, then click Send.
{
"username": "string",
"password": "string"
}
Response: access token
Create A Shipment
Create a new request and enter the admin access token
Authorization: Bearer token
POST <host>/rest/V1/order/19/ship
19 is the order id.
Payload
{
"items": [
{
"order_item_id": 47,
"qty": 1
},
{
"order_item_id": 48,
"qty": 1
}
],
"tracks": [
{
"track_number": "1Y-9876543210",
"title": "United Parcel Service",
"carrier_code": "ups"
}
]
}
Response: a shipment id
Verify the result
Log in to your admin and check the shipment the admin panel Sales order grid. Goes to Sales > Shipments. Then go to Orders, the status should be Complete.
With the order item id, you can create a partial shipment using Magento API. For more information, please leave a comment below or refer to Magento DevDocs.