Cannot save Fulfillment => undefined method 'each' for nil

Solved

Cannot save Fulfillment => undefined method 'each' for nil

doughty
Shopify Partner
20 1 6
Does anybody know what might be causing this problem? I’m trying to save a Fulfillment and getting this error
NoMethodError (undefined method `each' for nil:NilClass)
Code is this
fulfillment = ShopifyAPI::Fulfillment.new
        fulfillment.message = "The package will ship within 1 business day."
        fulfillment.notify_customer = true
        fulfillment.tracking_info = {
          "number" => tn,
          "company" => tc
        }
        fulfillment.line_items_by_fulfillment_order = [
          {
            "fulfillment_order_id" => fulfillment_order.id
          }
        ]
        fulfillment.save!
Accepted Solution (1)

doughty
Shopify Partner
20 1 6

This is an accepted solution.

Figured it out. The issue was that the FulfillmentOrder was not accepted yet. Once I accepted it, the error went away and the Fulfillment was able to save.

View solution in original post

Replies 4 (4)

IP1999
Shopify Partner
118 8 12

In the

fulfillment.line_items_by_fulfillment_order 

You need to add 

 

"fulfillment_order_line_items" => [
{
"id" => ,
"quantity" => 
}

 

https://shopify.dev/api/admin-rest/2022-10/resources/fulfillment#post-fulfillments

doughty
Shopify Partner
20 1 6

This is an accepted solution.

Figured it out. The issue was that the FulfillmentOrder was not accepted yet. Once I accepted it, the error went away and the Fulfillment was able to save.

lytiuha
Shopify Partner
1 0 0

hi @doughty  I have same problem, I have a question.

What do you mean "FulfillmentOrder was not accepted yet"?

How can I confirm and accept it?

Thank you.

ShopifyDevSup
Shopify Staff
1453 238 497

Hi @lytiuha 👋

 

You'll need to first accept the fulfillment order as shown in this doc here using POST fulfillment_request/accept in REST or fulfillmentOrderAcceptFulfillmentRequest mutation with GraphQL. 

 

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