Developers Staff
Developers Staff

Reputation: 71

shopify error "line_items":"expected Hash to be a Array" when trying to create fulfillment

I am trying to create line items fulfillment by passing the following params to /admin/api/2020-07/orders/{order_id}/fulfillments.json

{
  "fulfillment": {
    "location_id": 905684977,
    "tracking_number": null,
    "line_items": [
      {
        "id": 466157049
      },
      {
        "id": 518995019
      },
      {
        "id": 703073504
      }
    ]
  }
}

The above params are directly from the shopify doc(https://shopify.dev/docs/admin-api/rest/reference/shipping-and-fulfillment/fulfillment). When i execute it using the above parameters i am getting the following response

 [response] => {"errors":{"line_items":"expected Hash to be a Array"}} 

The issue is only when the line_items is in the array otherwise it will work. I would like to fulfill a few items in the order. Does anyone have any idea? Is this an issue on the Shopify end?

Upvotes: 2

Views: 4931

Answers (1)

Freddy Urbina
Freddy Urbina

Reputation: 31

Hello you must set this in the headers and send the parameters as a json Try this :

$request_headers[] = "X-Shopify-Access-Token: " . $token;
$request_headers[] = "Content-Type: application/json" ;

curl_setopt($curl, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($curl, CURLOPT_POSTFIELDS,  json_encode($query) );

Upvotes: 2

Related Questions