Magento 2 – Create Shipment via REST API

apimagento2rest

I'm trying to create a shipment via the REST API. I'm able to edit existing shipments via /rest/V1/shipment, but I can't seem to figure out how to add one. I consistently get a "Could not save shipment" response from the API.

Here are the parameters I'm posting to the endpoint:

        $post = ['entity' => ['customerId' => 3,
                          'billingAddressId' => 16,
                          'orderId' => 8,
                          'shippingAddressId' => 15,
                          'storeId' => 5,
                          'totalQty' => 1,
                          'packages' => [],
                          'items' => [],
                          'tracks' => [],
                          'comments' => [],
                         ]
            ];

For this given order, those are definitely the right address entity_id's, the order_id is correct, etc, etc. If I post similar parameters to another order and include that order's shipment's entity_id, I can update that existing shipment. I just can't seem to create a new shipment for an order that doesn't have a shipment yet.

Help! 🙂

Thanks….

Best Answer

It seems that you are not passing any items. While creating shipment you must mark atleast one item as shipped.

{
    "entity": {
        "order_id": 8,
        "items": [{
            "order_item_id": 123,
            "qty": 1
        }]
    }
}

An extra note that you can only pass items as of now. Comments and tracks are not working due a Magento bug. Have a look at git issue.

Related Topic