Solved

Creating a Fulfillment - Error "line_items_by_fulfillment_order":"expected Hash to be a Array"

ChrisWHG
Shopify Partner
5 0 2

I have set up a FulfillmentService, and can receive an AssignedFulfillmentOrder and Accept the request without a problem. But once the goods are shipped I need to create a Fulfillment.

 

I am working with /admin/api/2022-07/fulfillments.json and sending a POST request with

{
    "fulfillment":{
        "message":"The package was shipped this morning.",
        "line_items_by_fulfillment_order":[{
            "fulfillment_order_id":6171140030771
        }]
    }
}

Which is almost identical to the example in the API reference. I am not including tracking yet, I plan on updating that later. But the response I get is

{"errors":{"line_items_by_fulfillment_order":"expected Hash to be a Array"}}

 

I have tried for hours to solve this, tried many different variations. Hoping someone can help with this.

Accepted Solution (1)
ShopifyDevSup
Shopify Staff
1363 228 476

This is an accepted solution.

Thanks for sharing the X-Request-ID! 

 

Our logs show that the request resulted in a 400 error, suggesting that there maybe an issue with how your app is sending this request. I'd recommend testing with a curl request similar to the below instead. If the curl request to fulfill is successful, I would review how your app is making the request. I've seen similar errors when the header `Content-Type` isn't set to `application/json`, so that may be a good place to start. 

 

curl -L -X POST 'https://YOUR_STORE.myshopify.com/admin/api/2023-01/fulfillments.json' \
-H 'X-Shopify-Access-Token: YOUR_TOKEN' \
-H 'Content-Type: application/json' \
--data-raw '{
    "fulfillment": {
        "message": "The package was shipped this morning",
        "line_items_by_fulfillment_order": [
            {
                "fulfillment_order_id": 5580299141238,
                "fulfillment_order_line_items": [
                    {
                        "id": 1234,
                        "quantity": 1
                    }
                ]
            }
        ]
    }
}'

Hope that helps!

 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

View solution in original post

Replies 7 (7)

ShopifyDevSup
Shopify Staff
1363 228 476

Hi @ChrisWHG 👋

 

The `line_items_by_fulfillment_order` in your payload is missing the `fulfillment_order_line_items` field. Properly formatted, it would look similar to the below. I'd recommend reviewing step 4 of this guide on how to create fulfillments.

 

{
    "fulfillment": {
        "message":"The package was shipped this morning.",
        "line_items_by_fulfillment_order": [{
            "fulfillment_order_id": "6171140030771",
            "fulfillment_order_line_items": [{
                "id": "9876543210",
                "quantity": "1"
            }]
        }]
    }
}

 

Hope that helps!

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

ChrisWHG
Shopify Partner
5 0 2

Hi,

Thanks for your reply. I did try it with the line items too. The API reference says it can be left undefined and then all items will be fulfilled. But even with them in I am getting the same error.

{
    "fulfillment":{
        "message":"The package was shipped this morning.",
        "line_items_by_fulfillment_order":[{
            "fulfillment_order_id":6171140030771,

            "fulfillment_order_line_items":[{

                "id":13686305358131,
                "quantity":1

            }]
        }]
    }
}

return is still {"errors":{"line_items_by_fulfillment_order":"expected Hash to be a Array"}}

 

This is the complete return. Hoping I can solve this as this is almost the final piece in the App.

 

{"headers":{"status":"HTTP\/2 400 \r","date":"Wed, 04 Jan 2023 20","content-type":"application\/json; charset=utf-8","x-sorting-hat-podid":"306","x-sorting-hat-shopid":"66804154675","referrer-policy":"origin-when-cross-origin","x-frame-options":"DENY","x-shopid":"66804154675","x-shardid":"306","x-stats-userid":"","x-stats-apiclientid":"20111261697","x-stats-apipermissionid":"423845101875","x-shopify-api-version":"2022-07","http_x_shopify_shop_api_call_limit":"1\/40","x-shopify-shop-api-call-limit":"1\/40","strict-transport-security":"max-age=7889238","x-shopify-stage":"production","content-security-policy":"default-src 'self' data","x-content-type-options":"nosniff","x-download-options":"noopen","x-permitted-cross-domain-policies":"none","x-xss-protection":"1; mode=block; report=\/xss-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Ffulfillments&source%5Bsection%5D=admin_api&source%5Buuid%5D=dafbe2db-04c7-4008-a5e1-075cea303053","x-dc":"gcp-australia-southeast1,gcp-us-east1,gcp-us-east1","x-request-id":"dafbe2db-04c7-4008-a5e1-075cea303053","cf-cache-status":"DYNAMIC","report-to":"{\"endpoints\"","nel":"{\"success_fraction\"","server-timing":"cfRequestDuration;dur=340.000153","server":"cloudflare","cf-ray":"7846bbf84e39a814-SYD","alt-svc":"h3=\""},"response":"{\"errors\":{\"line_items_by_fulfillment_order\":\"expected Hash to be a Array\"}}"}

ShopifyDevSup
Shopify Staff
1363 228 476

This is an accepted solution.

Thanks for sharing the X-Request-ID! 

 

Our logs show that the request resulted in a 400 error, suggesting that there maybe an issue with how your app is sending this request. I'd recommend testing with a curl request similar to the below instead. If the curl request to fulfill is successful, I would review how your app is making the request. I've seen similar errors when the header `Content-Type` isn't set to `application/json`, so that may be a good place to start. 

 

curl -L -X POST 'https://YOUR_STORE.myshopify.com/admin/api/2023-01/fulfillments.json' \
-H 'X-Shopify-Access-Token: YOUR_TOKEN' \
-H 'Content-Type: application/json' \
--data-raw '{
    "fulfillment": {
        "message": "The package was shipped this morning",
        "line_items_by_fulfillment_order": [
            {
                "fulfillment_order_id": 5580299141238,
                "fulfillment_order_line_items": [
                    {
                        "id": 1234,
                        "quantity": 1
                    }
                ]
            }
        ]
    }
}'

Hope that helps!

 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

ChrisWHG
Shopify Partner
5 0 2

Thank you, you are right. I just made the request from Postman and the fulfillment was created. I am using a php curl function in my app so I need to revisit how the data is being sent.

Swetha09
Shopify Partner
1 0 0

Hi ChrisWHG, we are having the issue as above. Can you please let us know how u fixed the issue. We are getting the same error.

{"errors":{"line_items_by_fulfillment_order":"expected Hash to be a Array"}}
ShopifyDevSup
Shopify Staff
1363 228 476

Hey @Swetha09

I took a closer look, and was able to replicate the error noted in your post. This error is returned for a syntax issue in the request body, specifically related to the line_items_by_fulfillment_order parameter. Below are some insights on the required formatting for a request body on the REST Fulfillment endpoint, and a simplified example with some comment notes that you are welcome work from:

{
 "fulfillment": {
   "line_items_by_fulfillment_order": [   // This should be an array, required.
     {
       "fulfillment_order_id": FULFILLMENT_ORDER_ID 
       "fulfillment_order_line_items": [   // This should be an array, required if included.
         {
           "id": ID,   // fulfillment_order.line_item.id 
           "quantity": QUANTITY 
         },
         // ...Additional line items go here...
       ]
     }
   ],
   "tracking_number": "TRACKING_NUMBER",
   "tracking_company": "TRACKING_COMPANY", 
   "location_id": LOCATION_ID 
 }
}

Note: both line_items_by_fulfillment_order and fulfillment_order_line_items should be arrays.

 

If the intention is to fulfill all line items in a fulfillment order, pass only the line_items_by_fulfillment_order array with a fulfillment_order_id. To fulfill specific line items, include the relevant details in the fulfillment_order_line_items array. For more information, refer to the Fulfillment API's documentation.

 

Hope this helps clarify why this error would be generated, and how to approach resolving it!

Cheers, 
@awwdam | Shopify Developer Support

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

ChrisWHG
Shopify Partner
5 0 2

Hi, I am sorry I can't help. I can't remember what I did to correct the problem.

Chris