Order Fulfillment via rest api version 2023-01 by Using PHP

Topic summary

Issue: Creating a fulfillment via Shopify REST API v2023-01 in PHP returns “line_items_by_fulfillment_order - expected Hash to be a Array.”

Context: The poster successfully retrieves fulfillment_order_id, line_item_id, and quantity using GET /admin/api/2023-01/orders/{order_id}/fulfillment_orders.json. The failure occurs when POSTing to /admin/api/2023-01/fulfillments.json with a payload that includes line_items_by_fulfillment_order.

Likely cause: The payload structure for fulfillment_order_line_items is malformed in PHP. An extra set of parentheses wraps the array, and the API expects an array (list) rather than a single hash/object. One response suggests fixing the PHP syntax by assigning fulfillment_order_line_items directly to an array without the parentheses.

Key terms: “Hash” refers to an associative array/object; the API expects an array (list) for line_items_by_fulfillment_order and its fulfillment_order_line_items.

Status: No confirmation that the change resolves the error. Discussion remains open with a pending fix to the payload structure.

Summarized with AI on January 24. AI used: gpt-5.

I am trying to fulfill the order via shopify rest api version 2023-01 by using the PHP and got the error message as below:

line_items_by_fulfillment_order - expected Hash to be a Array

I am unable to solve the issue i am using the below code to fulfill the order.

$fulfill_data_new_1 = array(
    "fulfillment" => array(
        "message" => "The package was shipped.",    
        "notify_customer" => false,             
        "tracking_info" => array(               
                "number" => "123456TN",
                "company" => "ABC"
            ),
        "line_items_by_fulfillment_order" => array( 
            "fulfillment_order_id" => "12345678",
                "fulfillment_order_line_items" => (
                    array(                  
                    "id" => "254154654",    
                    "quantity" =>   "1"
                    )   
                )   
        )
    )
); 

$fulfill_order_new = shopify_call($token, $shop, "/admin/api/2023-01/fulfillments.json", $fulfill_data_new_1, 'POST');
$fulfill_order_success_new = $fulfill_order_new['response']; 

I have try to get fulfillment order ID, line item ID and its quantity by using the below code and its successfully return the ID. Only Issue is unable to fulfill the order by using New API version 2023-1

$get_orders_fulfill = shopify_call($token, $shop, "/admin/api/2023-01/orders/".$order_id."/fulfillment_orders.json", array(), 'GET');
// Convert product JSON information into an array
$get_orders_fulfill = json_decode($get_orders_fulfill['response'], TRUE);

$order_fulfill_id = $get_orders_fulfill['fulfillment_orders'][0]['id'];
$order_fulfill_line_item_id = $get_orders_fulfill['fulfillment_orders'][0]['line_items'][0]['id'];
$order_fulfill_line_item_qty = $get_orders_fulfill['fulfillment_orders'][0]['line_items'][0]['quantity']; 

Can anyone help me to fix the issue?

Thanks

Hi there,

I think you have an error in your php code

"fulfillment_order_line_items" => (
                    array(                  
                    "id" => "254154654",    
                    "quantity" =>   "1"
                    )   
                )

should be:

"fulfillment_order_line_items" => array(                  
   "id" => "254154654",    
   "quantity" =>   "1"
   )

But I’m no php expert :slightly_smiling_face:

Cheers,

Gary