Array not iterable: Difference between Shopify Trigger and Node?

Describe the issue/error/question

I’m having a relatively new problem to a workflow that has been running without a hitch for weeks now. What I’m doing is running a for…of loop inside the Function Node over the output of the Shopify Trigger Node, specifically the line_items key which is an array, and checking if the name of the product includes the word “Appointment” and if the product exists or is custom made.

One of 3 problems arises:

  1. Iterates over the array but doesn’t find the word “Appointment” although it clearly being in the name of the product (I know it iterates because the product exists and the isCustomOrder flag that I default to true is then set to false) and therefore blasts through any IF Node checks I’ve put in place leading to an Error. This happens in the only in the Error Logs when coming from the Shopify Trigger.

  2. It says that items[0].json.line_items is not iterable despite being an array, and working in the past. So far only seen on the Shopify Node.

  3. It works…flawlessly. Which I kinda expect/hope for.
    Screen Shot 2022-04-06 at 16.39.27

The line_items array output:

Is there a difference between the output of the Shopify Trigger Node and the Shopify Node? Running my own test with diff shows no difference between the Order Created Trigger and the Get Order Node but there may be some difference under the hood which I’ve encountered in the Read PDF Node output before.

Please share the workflow

Posting the reduced version for testing, whole thing is a bit too sensitive to be able to share.
Shopify Get Order into Function Node with for…of loop.
Having a dickens of a time trying to edit this code, ignore the last line, won’t post as code without it for some reason:

{
    "nodes": [
        {
            "parameters": {},
            "name": "Start",
            "type": "n8n-nodes-base.start",
            "typeVersion": 1,
            "position": [
                240,
                300
            ]
        },
        {
            "parameters": {
                "functionCode": "items[0].json.isAppointment = false;\nitems[0].json.isCustomOrder = true;\n\nfor (item of items[0].json.line_items) {\n  if (item.title.includes(\"Appointment\")) {\n    items[0].json.isAppointment = true;\n  }\n  if (item.product_exists) {\n    items[0].json.isCustomOrder = false;\n  }\n}\n\nreturn items;"
            },
            "name": "Function1",
            "type": "n8n-nodes-base.function",
            "typeVersion": 1,
            "position": [
                660,
                300
            ]
        },
        {
            "parameters": {
                "operation": "get",
                "options": {}
            },
            "name": "Shopify",
            "type": "n8n-nodes-base.shopify",
            "typeVersion": 1,
            "position": [
                460,
                300
            ]
        }
    ],
    "connections": {
        "Start": {
            "main": [
                [
                    {
                        "node": "Shopify",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Shopify": {
            "main": [
                [
                    {
                        "node": "Function1",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        }
    }
}
^Copy from here upwards

Stack Trace of the Function Node

TypeError: items[0].json.line_items is not iterable
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function:4:28
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function:14:2
    at BaseHandler.apply (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/bridge.js:479:11)
    at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/vm2/lib/nodevm.js:425:23)
    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function/Function.node.js:96:31)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/src/Workflow.js:526:37)
    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/WorkflowExecute.js:451:62
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Information on your n8n setup

  • n8n version: 0.171.0
  • Database you’re using (default: SQLite): Default
  • Running n8n with the execution process [own(default), main]: default Docker Server setup
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker

Hey @ugly, I am sorry to hear you’re running into this behaviour.

Could you share an example JSON output from your Shopify node I could use to reproduce the problem? I understand that this might be sensitive information, so please feel free to redact the actual values (I only care about the data structure).

Sorry for the delay @MutedJam.

{
    "id": 0,
    "admin_graphql_api_id": "",
    "app_id": 0,
    "browser_ip": "",
    "buyer_accepts_marketing": true,
    "cancel_reason": null,
    "cancelled_at": null,
    "cart_token": "",
    "checkout_id": 0,
    "checkout_token": "",
    "client_details": {
        "accept_language": "de-DE,de;q=0.9",
        "browser_height": 718,
        "browser_ip": "",
        "browser_width": 414,
        "session_hash": null,
        "user_agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 15_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.3 Mobile/15E148 Safari/604.1"
    },
    "closed_at": null,
    "confirmed": true,
    "contact_email": "",
    "created_at": "2022-03-31T17:21:26+02:00",
    "currency": "EUR",
    "current_subtotal_price": "0.00",
    "current_subtotal_price_set": {
        "shop_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        },
        "presentment_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        }
    },
    "current_total_discounts": "0.00",
    "current_total_discounts_set": {
        "shop_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        },
        "presentment_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        }
    },
    "current_total_duties_set": null,
    "current_total_price": "0.00",
    "current_total_price_set": {
        "shop_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        },
        "presentment_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        }
    },
    "current_total_tax": "0.00",
    "current_total_tax_set": {
        "shop_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        },
        "presentment_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        }
    },
    "customer_locale": "en",
    "device_id": null,
    "discount_codes": [],
    "email": "",
    "estimated_taxes": false,
    "financial_status": "paid",
    "fulfillment_status": null,
    "gateway": null,
    "landing_site": "/products/appointment",
    "landing_site_ref": null,
    "location_id": null,
    "name": "#5064",
    "note": "",
    "note_attributes": [],
    "number": 4064,
    "order_number": 5064,
    "order_status_url": "",
    "original_total_duties_set": null,
    "payment_gateway_names": [],
    "phone": null,
    "presentment_currency": "EUR",
    "processed_at": "2022-03-31T17:21:25+02:00",
    "processing_method": "free",
    "reference": null,
    "referring_site": "",
    "source_identifier": null,
    "source_name": "web",
    "source_url": null,
    "subtotal_price": "0.00",
    "subtotal_price_set": {
        "shop_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        },
        "presentment_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        }
    },
    "tags": "",
    "tax_lines": [],
    "taxes_included": false,
    "test": false,
    "token": "",
    "total_discounts": "0.00",
    "total_discounts_set": {
        "shop_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        },
        "presentment_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        }
    },
    "total_line_items_price": "0.00",
    "total_line_items_price_set": {
        "shop_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        },
        "presentment_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        }
    },
    "total_outstanding": "0.00",
    "total_price": "0.00",
    "total_price_set": {
        "shop_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        },
        "presentment_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        }
    },
    "total_price_usd": "0.00",
    "total_shipping_price_set": {
        "shop_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        },
        "presentment_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        }
    },
    "total_tax": "0.00",
    "total_tax_set": {
        "shop_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        },
        "presentment_money": {
            "amount": "0.00",
            "currency_code": "EUR"
        }
    },
    "total_tip_received": "0.00",
    "total_weight": 0,
    "updated_at": "2022-03-31T17:21:27+02:00",
    "user_id": null,
    "billing_address": {
        "first_name": "",
        "address1": "",
        "phone": "",
        "city": "Berlin",
        "zip": "",
        "province": null,
        "country": "Germany",
        "last_name": "",
        "address2": "",
        "company": "",
        "latitude": 0,
        "longitude": 0,
        "name": "",
        "country_code": "DE",
        "province_code": null
    },
    "customer": {
        "id": 0,
        "email": "",
        "accepts_marketing": true,
        "created_at": "2021-08-03T12:34:53+02:00",
        "updated_at": "2022-03-31T17:21:27+02:00",
        "first_name": "",
        "last_name": "",
        "orders_count": 3,
        "state": "disabled",
        "total_spent": "0",
        "last_order_id": 0,
        "note": null,
        "verified_email": true,
        "multipass_identifier": null,
        "tax_exempt": false,
        "phone": null,
        "tags": "",
        "last_order_name": "#5064",
        "currency": "EUR",
        "accepts_marketing_updated_at": "2021-08-03T12:34:54+02:00",
        "marketing_opt_in_level": "single_opt_in",
        "tax_exemptions": [],
        "admin_graphql_api_id": "",
        "default_address": {
            "id": 0,
            "customer_id": 0,
            "first_name": "",
            "last_name": "",
            "company": "",
            "address1": "",
            "address2": "",
            "city": "Berlin",
            "province": null,
            "country": "Germany",
            "zip": "10245",
            "phone": "",
            "name": "",
            "province_code": null,
            "country_code": "DE",
            "country_name": "Germany",
            "default": true
        }
    },
    "discount_applications": [],
    "fulfillments": [],
    "line_items": [
        {
            "id": 0,
            "admin_graphql_api_id": "gid://shopify/LineItem/0",
            "fulfillable_quantity": 1,
            "fulfillment_service": "manual",
            "fulfillment_status": null,
            "gift_card": false,
            "grams": 0,
            "name": "Appointment - 2 Hours",
            "origin_location": {
                "id": 2069841051696,
                "country_code": "DE",
                "province_code": "",
                "name": "",
                "address1": "",
                "address2": "",
                "city": "Berlin",
                "zip": ""
            },
            "price": "0.00",
            "price_set": {
                "shop_money": {
                    "amount": "0.00",
                    "currency_code": "EUR"
                },
                "presentment_money": {
                    "amount": "0.00",
                    "currency_code": "EUR"
                }
            },
            "product_exists": true,
            "product_id": 0,
            "properties": [
                {
                    "name": "Date",
                    "value": "2022-04-13"
                },
                {
                    "name": "Time",
                    "value": "13:00"
                },
                {
                    "name": "Timezone",
                    "value": "Europe/Berlin"
                },
                {
                    "name": "Team Member",
                    "value": ""
                }
            ],
            "quantity": 1,
            "requires_shipping": false,
            "sku": "",
            "taxable": true,
            "title": "Appointment",
            "total_discount": "0.00",
            "total_discount_set": {
                "shop_money": {
                    "amount": "0.00",
                    "currency_code": "EUR"
                },
                "presentment_money": {
                    "amount": "0.00",
                    "currency_code": "EUR"
                }
            },
            "variant_id": 0,
            "variant_inventory_management": null,
            "variant_title": "2 Hours",
            "vendor": "",
            "tax_lines": [
                {
                    "channel_liable": false,
                    "price": "0.00",
                    "price_set": {
                        "shop_money": {
                            "amount": "0.00",
                            "currency_code": "EUR"
                        },
                        "presentment_money": {
                            "amount": "0.00",
                            "currency_code": "EUR"
                        }
                    },
                    "rate": 0.19,
                    "title": "DE MwSt"
                }
            ],
            "duties": [],
            "discount_allocations": []
        }
    ],
    "refunds": [],
    "shipping_lines": []
}

Hey @ugly,

That is odd, Using that data as it is I don’t have the same problem. I suspect what is happening is sometimes the data just isn’t being sent, Do you happen to have the data from the trigger that covers one of the failure events?

That data was from one of the failure events. What is even stranger is that it’s started working again with the live trigger and only bugs out when I retry the failed execution. Gonna chalk this up to sprites in the wires because I can’t really see anything beyond what has already been spat out.

1 Like

Hey @ugly,

That works for me :slightly_smiling_face:, I would be tempted to put some checks in the workflow just to check for anything odd with the data. I have seen some strange things happen and I now add in some checks into most of the workflows I make just to make life a bit easier.