Array Mapping Issue: How to Create Single Shopify Order with Multiple Line Items

Describe the problem/error/question:

My incoming data contains a single item with an array of line item objects, accessible at {{ $json.line_items }}.
This array contains all the necessary fields (variant_id, quantity, price, title, etc.) for multiple products.

Since the Shopify node UI does not expose a single field to map the entire line_items array in JSON mode, I tried to use parallel .map() expressions in each individual sub-field.

For example, in the Variant ID field, I used: {{ $json.line_item.map(item => item.variant_id) }}. I did the same for Quantity, Price, and Title.

This results in the Shopify node producing the following error, indicating the parallel arrays are not being correctly zipped or the structure is being rejected by the underlying API call.

422 - {"errors":{"line_items":["line item price not found, 'price' must provided."]}}

What is the correct way to create order with multiple items?

This is not only related to Shopify node but also occurs in other nodes, where mapping an entire array is not possible.

Information on your n8n setup

  • n8n version: 1.119.1
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default: own, main
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Linux

@endrust Use Split Out node for line_items

@bhavyshekhaliya, thanks for your reply.

When I use split out - I get a separate order created for each line item.

Can you share workflow for better idea. pin main nodes data.

Sure!

Hi @endrust, I dont think the Shopify node currenly supports adding a dynamic list of line items to an order. You are probably better off calling the shopify API directly using the HTTP Request node

Hey @Wouter_Nigrini

Yeah, HTTP will solve this but is there a common approach in n8n to map such structures?
From what I saw - this is not only related to Shopify node.

Not if the node doesnt support using json specifically. For example, if you look at the form node as an EXAMPLE, it allows you to create form fields using either the editor or json. In the case of the Shopify node, there is no such support built in, hence the node will not do as you hope it will. In this case you will need to use the api directly to gain the flexibility you need.

UNLESS, you feel like either enhancing the current node or building a new one which will cater for this so other users can use the same node for similar challenges. This of course will take longer to build than just using the api directly.

IF this is a tedious problem because you might want to use this in many places, then I would suggest you build a new workflow which does the API calls to Shopify, and then re-use the workflow as a sub-workflow in your other flows where you need to repeatedly use the same functionality, thus in a way creating a simplified re-usable workflow for creating orders with dynamic line items

Thanks for the detailed answer @Wouter_Nigrini

If you need more help with the direct integration, let us know and we can try and help you further. I see the documentation states that the rest APIs are being deprecated in favour of the GraphQL APIs which seems a little bit more complex to use, but comes with a lot more flexibility