Fulfillment API returns error

ironpro
Shopify Partner
21 0 2

Hi there!

I have been trying to create a fulfillment via API for several days but it returns error.

{"errors":{"fulfillment":"Required parameter missing or invalid"}}

 

Here I attach the code. ( I am using Signifly/Laravel package )

 

    'fulfillment' => array(
        'message' => 'The order has been send',
        'notify_customer' => true,
        'location_id' => 61480337591,
        'tracking_info' => array(
            'number' => 5858371,
            'url' => 'dhl.com',
            'company' => 'DHL - Parcel'
        ),
        'line_items_by_fulfillment_order' => array(
            array(
                'fulfillment_order_id' => 6655267897673,
                "fulfillment_order_line_items" => array(
                    "id" => "14645454864713",
                    "quantity" => 1
                )
            )
        )
    )
);

$url = 'https://xxx.myshopify.com/admin/api/2023-07/orders/5618380079433/fulfillments.json';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$res = curl_exec($ch);
curl_close($ch);

echo $res; 

The location_id, fulfillment_order_id, line_item_id are all correct since I got them via API before executing above code.

Since I couldn't proceed fulfillment_request API, tracking_info values are random ones at the moment.

 

 

Developer
Replies 6 (6)

ironpro
Shopify Partner
21 0 2

I've tried with real tracking information that had been created by merchant but it returned same error.

Developer

Tipsa
Shopify Partner
1 0 0

I have the same problem with the same error, if someone could help us I would greatly appreciate it

Liam
Shopify Staff
2731 301 778

Hi Ironpro,

 

Was this same code working previously or is this a new implementation that you're building?

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

ironpro
Shopify Partner
21 0 2

Hi Liam.

This is the first time for me to implement.
We are building our own order management system using Shopify API.
Fulfillment implementation is just last step.

Developer
Liam
Shopify Staff
2731 301 778

It's possible this could be happening because the "tracking_info" number is an integer, while Shopify expects a string. Could you switch to a string and see if the error is being returned? 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

ironpro
Shopify Partner
21 0 2

Hi Liam!
Thank you for your help!
Yes, here I changed the number to string.

$data = array(
'fulfillment' => array(
        "location_id" => $rfill['assigned_location']['location_id'],
        "message"=>"The Jewllery Room fulfilled 1 item.",
        "notify_customer"=> false, 
        "tracking_info"=> array(
            "number" => "YMT29GRM",
            "company" => "GLS"  
        ),
        "line_items_by_fulfillment_order"=> array(
            "fulfillment_order_id" => $rfill['id'],
            "filfillment_order_line_items" => array(
                "id" => "14794802299209",
                "quantity" => 1
            )
        )
    )
);

so when I echo the json it shows as follows.

{
  "fulfillment": {
    "location_id": 61480337591,
    "message": "The Jewllery Room fulfilled 1 item.",
    "notify_customer": false,
    "tracking_info": {
      "number": "YMT29GRM",
      "company": "GLS"
    },
    "line_items_by_fulfillment_order": {
      "fulfillment_order_id": 6661985730889,
      "filfillment_order_line_items": {
        "id": "14794802299209",
        "quantity": 1
      }
    }
  }
}


And it returns error.

Response Code: 400
Response Body: {"errors":{"line_items_by_fulfillment_order":"expected Hash to be a Array"}}

Developer