Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

REST API fulfillment splitting

REST API fulfillment splitting

agustin_boleda
Shopify Partner
12 0 5

Hello,

 

We are a logistics company and some of our clients use Shopify.

We manage the connection between our systems and Shopify using custom apps, so all the code is really in our systems.

The Rest API is used for this and I have found out that the /orders/fulfillments endpoints will no longer work on april of this year (2023).

 

We are having problems splitting fulfillments.

In our orders, some items might be out of stock partially.

E.g. you might have an order for 4 items A and 10 items B but you only have 6 items B.

 

So what we do is "split the fulfillment":
- we cancell the original fulfillment

- we create 2 fulfillments, 1 for 4 items A and 6 items B, and 1 for 4 items B

 

We changed the endpoints to create the fulfillments, but no matter what line items we send, the fulfillment is always created for all the items on the order.

 

{
	"fulfillment": {
		"order_id": xxx,
		"location_id": xxx,
		"status": "open",
		"notify_customer": false,
		"line_items_by_fulfillment_order": [{
			"fulfillment_order_id": xxx,
			"fulfillment_order_line_item": [{
				"id": xxx,
				"quantity": 4
			}, {
				"id": xxx,
				"quantity": 6
			}]
		}]
	}
}

this call creates a fulfillment for all items (not just 4 and 6)

 

{
	"fulfillment": {
		"order_id": xxx,
		"location_id": xxx,
		"status": "open",
		"notify_customer": false,
		"line_items_by_fulfillment_order": [{
			"fulfillment_order_id": xxx,
			"fulfillment_order_line_item": [{
				"id": xxx,
				"quantity": 4
			}]
		}]
	}
}

this calls fails with error

{
	"errors": ["Fulfillment order xxx has an unfulfillable status= closed."]
}

 

Tu sum this up: I need to split the order items into 2 fulfillments (or fulfillment orders), both for the same locations but different items, any help?

 

Thanks in advance.

 

 

Replies 2 (2)

garyrgilbert
Shopify Partner
431 41 186

 

I think you are going about it the wrong way...there is an easier way

 

get the fulfillment orders for the order using the order/[orderid]/fulfillment_orders.json endpoint.  With the fulfillment_order id/fulfillmentorderlineitem ids you then fulfill those items that are available this will automatically set the order to partially fulfilled. The line_items in the fulfillment order will indicate how many items were ordered, and how many are on-hand .

 

When the other items are available to be shipped you once again request the fulfillment orders for the order and then fulfill the remaining items. Use the fulfillment_order_line_items array and specify which fulfillment order line items should be fulfilled and their quantity. Caution shopify will throw an error if you specify 0 for the quantity.

 

 

"fulfillment_order_line_items" : [
      {
        "id" : 1058737504, //fulfillment order line_item id
        "quantity" : 1
      }
    ]

 

 

Cheers,

 

Gary

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
agustin_boleda
Shopify Partner
12 0 5

Hi Gary,

 

Thank you for your response.

We found our problem, it had to do with the name of the "fulfillment_order_line_items" field and also with id inside that array. We were using the line_item_id and we found out that we should use the id from the fulfillment_order line items.

This is a bit confusing in the documentation.

Also, if we cancel a fulfillment, the fulfillment_order gets closed and a new one is created automatically, and so the the id from the fulfillment_order line items might change.

 

Again, thank you for your response.