Magento 2.3 REST API – Creating Shipment with Products from MSI Source

magento2.3msirestshipment

I am using MSI.

When trying to create a shipment with a source code, the shipment uses the "default source" instead of the one I'm providing.

My Request:
[POST] /rest/default/V1/order/5/ship

{
    "items": [
        {
            "order_item_id": 14,
            "qty": 1
        }
    ],
    "extension_attributes" : {
        "source_code" : "3"
    }
}

I've used this documentation to create my request:
https://devdocs.magento.com/swagger/index_23.html#/salesShipmentRepositoryV1/salesShipmentRepositoryV1SavePost

The source "3" has sufficient stock, so this shouldn't be the issue

  • When "default source" has stock, the shipment is created uses stock from "default source"

  • When "default source" has no stock, I get the following: Shipment Document Validation Error(s):\nThe order does not allow a shipment to be created.\nYou can't create a shipment without products.

So it definitely tries to use the default source, which is what I don't want.

My question:
How can I tell Magento to use my source code? Do I need to provide the source code in a different way?

Best Answer

The issue lies in the JSON structure. You should use arguments.extension_attributes.source_code, instead of extension_attributes.source_code as shown below:

{
    "items": [
        {
            "order_item_id": 14,
            "qty": 1
        }
    ],
    "arguments": {
        "extension_attributes" : {
            "source_code" : "3"
        }
    }
}

Then, it will create the shipment (using the specified source) and return the shipment_id as the response.

I have tested this in Magento 2.3.2-p2

Related Topic