Creates a fulfillment

Hi!

I need to create a fulfillment.

I’m trying to do this via postman but fail. i am following this
https://shopify.dev/docs/api/admin-rest/2022-10/resources/fulfillment#post-fulfillments
documentation but it doesn’t work.

In my case:

Get https://xxxxx:xxxxx@mywebsite.myshopify.com/admin/api/2023-04/orders/5577727934792/fulfillment_orders.json

{
    "fulfillment_orders": [
        {
            "id": {{fulfillment_order_id}},
            "shop_id": {{shop_id}},
            "order_id": {{order_id}},
            "assigned_location_id": {{location_id}},
            "request_status": "unsubmitted",
            "status": "open",
            "supported_actions": [
                "create_fulfillment",
                "hold"
            ],
            "destination": {

            },
            "line_items": [
                {
                    "id": {{id}},
                    "shop_id": {{shop_id}},
                    "fulfillment_order_id": {{fulfillment_order_id}},
                    "quantity": 1,
                    "line_item_id": {{line_item_id}},
                    "inventory_item_id": xxxxxxxx,
                    "fulfillable_quantity": 1,
                    "variant_id": xxxxxxx
                }
            ],
            "fulfill_at": "2023-04-27T15:00:00+02:00",
            "fulfill_by": null,
            "international_duties": null,
            "fulfillment_holds": [],
            "merchant_requests": []
        }
    ]
}

now i create a fulfillment:

endpoint->

Post https://xxxxx:xxxxx@mywebsite.myshopify.com/admin/api/2023-04/fulfillments.json

{"fulfillment":
    {
        "message":"The package was shipped this morning.",
        "notify_customer":false,
        "tracking_info":
            {
            "number":1562678,
            "url":"https://www.my-shipping-company.com",
            "company":"my-shipping-company"
            },
            "line_items_by_fulfillment_order":
                [
                    {"fulfillment_order_id":{{fulfillment_order_id}},
                    "fulfillment_order_line_items":
                        [{"id":{{line_item_id}},"quantity":1}]
                    }
                ]
    }
}

It not work and i not understand the problem.

Please help

Alessandro

Hi Alessandro,

What are you receiving as a response?

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:

{“errors”:{“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']; 

Can anyone please help to to solve this issue?

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']; 
1 Like

@MuneebAhmad

Please don’t hijack someone elses question with your own.. its better to start your own thread.. be that as it may the error indicates there is an issue with your json object. Im not a php guy so dont know how you build the correct structure with php but it needs to have this form

"line_items_by_fulfillment_order":[{ 
            "fulfillment_order_id":"12345678",
            "fulfillment_order_line_items": [
                    {
                    "id" : "254154654",    
                    "quantity" : "1"
                    }
                ] 
        }]

so before sending it to shopify ensure that its being serialized correctly.

Cheers,

Gary