2

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....

4

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.

  • Thanks, that helped a ton. I can now create a shipment and then I separately add tracking for it. Is there any way to move the order to the shipped status and thus generate an email to the customer or is this bug the root of that problem: github.com/magento/magento2/issues/3307? – Tim Trampedach Apr 8 '16 at 1:32
  • Cool. Unfortunately, order status is also a bug which recently got resolved, but I guess its not released yet, you have got the right bug. I think triggering email is done via comment api, by setting "isCustomerNotified": ` [{ "entityId" : 2, "isCustomerNotified" : 1, "parentId" : 1 } ]` – Mujtaba Ahmad Apr 8 '16 at 7:15
  • OK, thanks for all your help. Hopefully the next release has some presents in it! – Tim Trampedach Apr 8 '16 at 18:38
  • 1
    Can you guide me how to get order_item_id from the order? I am always getting the message 'You can't create a shipment without products.' – Nishad Up Dec 21 '17 at 4:50
  • To ship all items, there is no need to include any items, just the tracking JSON – KolonUK Apr 17 at 13:08
1

I know the answer has been given, but I'd like to suggest to all future people to not create a shipment yourself, but to ship an order using:

http://devdocs.magento.com/swagger/#!/salesShipOrderV1

Benefit? You do not provide the store id, billing address, etc. etc. This will all be handled by Magento, as the information is on the order. I had a ton of problems to solve when I created shipments myself; when I used the /V1/order/{orderId}/ship method, everything worked out of the box.

  • can you please provide more info (JSON Payload of a working request), because i'm using this method and struggling with "You can't create a shipment without products" error – domi27 Aug 10 '17 at 16:51
  • @domi27 - see my answer where you don't have to include all the items to create a shipment – KolonUK Apr 17 at 13:02
1

If you are shipping all items in the order, there is no need to actually include the items:

{

  "tracks": [
    {
      "track_number": "1Y-9876543210",
      "title": "Custom",
      "carrier_code": "SomeCarrierCode"
    }
  ]
}

As long as you have the Magento order ID in the URL rest/V1/order/10/ship, this will work. Plus, the carrier_code can be anything if you haven't got real carriers setup...

This took me hours to find out, as Magento's documentation and API is shocking!

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.