magento2: Rest salesShipOrderV1 API w/ Bundles error: "You can't create a shipment without products"

Preconditions

  1. Magento v2.1.4

Steps to reproduce

  1. Create an order containing a bundle of multiple simple products.
  2. Call the REST salesShipOrderV1 API (POST /V1/order/{orderId}/ship) and send a shipment for the individual items. Example:
{
        "appendComment": 1,
        "notify": 1,
        "comment": {
            "comment": "Your order has been shipped, login to view tracking information.",
            "is_visible_on_front": 1
        },
        "items": [
            {
                "order_item_id": 516,
                "qty": 1
            },
            {
                "order_item_id": 517,
                "qty": 1
            }
        ],
        "tracks": [
            {
                "title": "Netherlands Post Ground Parcel",
                "carrier_code": "custom",
                "track_number": "3SCEMW182389201"
            }
        ]
}

Expected result

  1. Order gets mark completed

Actual result

{
        "status": 400,
        "headers": {},
        "body": {
            "message": "Shipment Document Validation Error(s):\nYou can't create a shipment without products."
        }
}

Additional info

Reproduced it via Swagger. Applied admin token and used the POST/V1/order/{orderId}/ship Used the following query body

{
  "items": [
    {
      "extension_attributes": {},
      "order_item_id": 6,
      "qty": 1
    }
  ],
  "notify": true,
  "appendComment": true,
  "comment": {
    "extension_attributes": {},
    "comment": "Your order has been shipped, login to view tracking information.",
    "is_visible_on_front": 1
  },
  "tracks": [
    {
      "extension_attributes": {},
      "track_number": "3SCEMW182389201",
      "title": "Netherlands Post Ground Parcel",
      "carrier_code": "fixed"
    }
  ],
  "packages": [
    {
      "extension_attributes": {}
    }
  ],
  "arguments": {
    "extension_attributes": {}
  }
}

Where :

  • orderId can be found in Sales - Orders sales_orders
  • track_number is set while Shiping the order ship Add a tracking number track_number
  • order_item_id I’m sure that there is an easier way, but I used GraphQL to verify the order item id order_item_id

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 31 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Hello,

I’m curious myself when this issue will be solved?

Kind regards, Reijer

Just tested this, and yes, it seems you have to pass the parent_item_id if the product is a child of a configurable product, otherwise you get an error

see code example:

if($orderItem->getParentItemId() == null) {
    $setOrderItemId = $orderItem->getItemId();
}
else {
    $setOrderItemId = $orderItem->getParentItemId();
}
$shipmentItem->setOrderItemId($setOrderItemId);
$shipmentItem->setQty($deliveryNoteItem->getQuantity());
$shipmentItems[] = $shipmentItem;

This should definitely be fixed, since logically it would make sense to create shipments for the single product and not the configurable product.

Hi everyone, this is the solution:

{ “appendComment”: true, “notify”: true, “comment”:{
“comment”:“shipment creado via webservice”, “is_visible_on_front”:1 },

    "tracks": [
        {
            "track_number":"3SCEMW182389201",
             "title":"UPS",
             "carrier_code":"Carrier code n"
        }
    ]

}

remove items, it worked for me.

I have recently determined that the item visibility has something to do with this issue. One of my clients has items that are only visible via sku search and I can not add tracking to these items.

If possible the actual error logs sometimes have more information. You normally need access to the server to see these but it could offer insights

Dan

Sent from my iPhone

On Mar 29, 2019, at 7:58 AM, Juliano Vargas notifications@github.com wrote:

@magento-engcom-team Any solution to this. I having to end up using 2 call. 1- to create ship /V1/shipment 2- to add tracking /V1/shipment/track

As /V1/shipment has an option to add Tracks but also not adding ? ref:https://devdocs.magento.com/redoc/2.3/admin-rest-api.html#operation/salesShipmentRepositoryV1SavePost Thanks

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

As a shipper I’m physically shipping the individual simple products, not the bundle SKU. The bundle SKU is just a virtual SKU representing the simple products. So I’m just telling Magento 2 what was actually shipped. It seems Magento 2 should be able to handle this and be smart enough to know once all the simple products are shipped then the bundle is shipped also. This is how it works in Magento 1 when sending shipments. We only ever send shipments for simple products and it works just fine.

How would we handle the scenario where the simple products were shipped separately? Each would have their own tracking number. If we can only mark the virtual bundle sku as shipped then it seems this scenario could not be handled.

Thanks.