List item group in a single json after a loop

Hello!!!

I am using Split Batches after dividing the list of products of an order to ask 1 to 1 for API a value. Here is the detail of the process:

json before listing

[
{
“id”: 32845031702767,
“order_number”: 32845031702767,
“total_price”: “28630.00”,
“currency”: “ARS”,
“event_items”: [
{
“product_id”: 111111111,
“title”: “title_1”
},
{
“product_id”: 222222222,
“title”: “title_2”
},
{
“product_id”: 333333333,
“title”: “title_3”
},
{
“product_id”: 444444444,
“title”: “title_4”
}
]
}
]

After listing I am left with 4 separate items, here is the detail of one:

[
{
“product_id”: 111111111,
“title”: “title_1”
}
]

I then use Split Batches to api (get) the url of each product image.

Once I have the URL, I use a set to save the URL and then a Merge to add the property to the product, leaving this json

[
{
“product_id”: 111111111,
“title”: “title_1”,
“product_image”: “https://cdn.shopify.com/s/files/1/0248/9188/3595/products/BESTIAKAWAIVOL12711.jpg?v=1652809049
}
]

My problem is that I have 4 separate json files and to send the data as an event I need this structure:

[
{
“id”: 32845031702767,
“order_number”: 32845031702767,
“total_price”: “28630.00”,
“currency”: “ARS”,
“event_items”: [
{
“product_id”: 111111111,
“title”: “title_1”
“product_image”: “https://cdn.shopify.com/s/files/1/0248/9188/3595/products/BESTIAKAWAIVOL12711.jpg?v=111111111
},
{
“product_id”: 222222222,
“title”: “title_2”
“product_image”: “https://cdn.shopify.com/s/files/1/0248/9188/3595/products/BESTIAKAWAIVOL12711.jpg?v=222222222
},
{
“product_id”: 333333333,
“title”: “title_3”
},
{
“product_id”: 444444444,
“title”: “title_4”
“product_image”: “https://cdn.shopify.com/s/files/1/0248/9188/3595/products/BESTIAKAWAIVOL12711.jpg?v=444444444
}
]
}
]

How can I get 4 json together and not separated?

1 Like

Hi @David_Alejandro_Carr

Don’t think you need the split in batches node here.
And I think you are looking for the aggregate function in the item lists node.
This will put the items back into an array which you can then use.
If using the split in batches node this will do it per batch. (if in the split in batch loop of course)

1 Like

Here is what you can do to achieve the result you wanted. Hope it helps

Thank you very much for the reply!

Unfortunately I am not getting the expected result

I leave here the flow, to have more detail

*pause the get request that brings the url of the product, leave a function node that what is obtained from the request as an example

Add a final note with the expected result

{
  "name": "Test  abandoned checkouts copy extracto",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        740,
        -340
      ]
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "name": "SplitInBatches1",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        1380,
        -340
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "event_items",
        "options": {}
      },
      "name": "Item Lists2",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [
        1180,
        -340
      ]
    },
    {
      "parameters": {
        "mode": "mergeByIndex"
      },
      "name": "Merge1",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        2380,
        -320
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "title",
              "value": "={{$json[\"title\"]}}"
            },
            {
              "name": "name",
              "value": "={{$json[\"presentment_title\"]}}"
            },
            {
              "name": "sku",
              "value": "={{$json[\"sku\"]}}"
            },
            {
              "name": "product_id",
              "value": "={{$json[\"product_id\"]}}"
            },
            {
              "name": "product_image",
              "value": "={{$json[\"product_image\"]}}"
            },
            {
              "name": "price",
              "value": "={{$json[\"price\"]}}"
            },
            {
              "name": "vendor",
              "value": "={{$json[\"vendor\"]}}"
            },
            {
              "name": "quantity",
              "value": "={{$json[\"quantity\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set2",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        2560,
        -320
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "product_image",
              "value": "={{$json[\"images\"][0][\"src\"]}}"
            },
            {
              "name": "product_id",
              "value": "={{$json[\"images\"][0][\"product_id\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set4",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        2160,
        -220
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n{\n\"id\": 32845031702767,\n\"order_number\": 32845031702767,\n\"total_price\": \"28630.00\",\n\"financial_status\": \"\",\n\"subtotal_price\": \"28630.00\",\n\"total_tax\": \"0.00\",\n\"total_discounts\": \"0.00\",\n\"total_price_usd\": \"\",\n\"currency\": \"ARS\",\n\"gateway\": null,\n\"fulfillment_status\": \"\",\n\"order_status_url\": \"\",\n\"event_items\": [\n{\n\"applied_discounts\": [\n],\n\"discount_allocations\": [\n],\n\"key\": \"b0f206ead746d91464f1893dd033664e\",\n\"destination_location_id\": null,\n\"fulfillment_service\": \"manual\",\n\"gift_card\": false,\n\"grams\": 400,\n\"origin_location_id\": 3035280769203,\n\"presentment_title\": \"Bucito Schumacher Rosa\",\n\"presentment_variant_title\": \"Talle 2\",\n\"product_id\": 7571586515183,\n\"properties\": [\n],\n\"quantity\": 1,\n\"requires_shipping\": true,\n\"sku\": \"I221B007!RSS!2\",\n\"tax_lines\": [\n],\n\"taxable\": true,\n\"title\": \"Bucito Schumacher Rosa\",\n\"variant_id\": 42498654994671,\n\"variant_title\": \"Talle 2\",\n\"variant_price\": \"8240.00\",\n\"vendor\": \"Bestia\",\n\"user_id\": null,\n\"unit_price_measurement\": {\n\"measured_type\": null,\n\"quantity_value\": null,\n\"quantity_unit\": null,\n\"reference_value\": null,\n\"reference_unit\": null\n},\n\"rank\": null,\n\"compare_at_price\": \"10300.00\",\n\"line_price\": \"8240.00\",\n\"price\": \"8240.00\"\n},\n{\n\"applied_discounts\": [\n],\n\"discount_allocations\": [\n],\n\"key\": \"c0128c2a94e0fe31a5ef5ed633ef1551\",\n\"destination_location_id\": null,\n\"fulfillment_service\": \"manual\",\n\"gift_card\": false,\n\"grams\": 200,\n\"origin_location_id\": 3035280769203,\n\"presentment_title\": \"Gorro Ferrari Violeta\",\n\"presentment_variant_title\": \"Talle único\",\n\"product_id\": 7657168666863,\n\"properties\": [\n],\n\"quantity\": 1,\n\"requires_shipping\": true,\n\"sku\": \"I224AC006!VI!U\",\n\"tax_lines\": [\n],\n\"taxable\": true,\n\"title\": \"Gorro Ferrari Violeta\",\n\"variant_id\": 42799288156399,\n\"variant_title\": \"Talle único\",\n\"variant_price\": \"2240.00\",\n\"vendor\": \"Bestia\",\n\"user_id\": null,\n\"unit_price_measurement\": {\n\"measured_type\": null,\n\"quantity_value\": null,\n\"quantity_unit\": null,\n\"reference_value\": null,\n\"reference_unit\": null\n},\n\"rank\": null,\n\"compare_at_price\": \"3200.00\",\n\"line_price\": \"2240.00\",\n\"price\": \"2240.00\"\n},\n{\n\"applied_discounts\": [\n],\n\"discount_allocations\": [\n],\n\"key\": \"d7c6fea633d6131c7a16ad0e8719d837\",\n\"destination_location_id\": null,\n\"fulfillment_service\": \"manual\",\n\"gift_card\": false,\n\"grams\": 200,\n\"origin_location_id\": 3035280769203,\n\"presentment_title\": \"Remera Honda Negra\",\n\"presentment_variant_title\": \"Talle 2\",\n\"product_id\": 7592016085231,\n\"properties\": [\n],\n\"quantity\": 1,\n\"requires_shipping\": true,\n\"sku\": \"I221T003!NE!2\",\n\"tax_lines\": [\n],\n\"taxable\": true,\n\"title\": \"Remera Honda Negra\",\n\"variant_id\": 42564553769199,\n\"variant_title\": \"Talle 2\",\n\"variant_price\": \"4800.00\",\n\"vendor\": \"Bestia\",\n\"user_id\": null,\n\"unit_price_measurement\": {\n\"measured_type\": null,\n\"quantity_value\": null,\n\"quantity_unit\": null,\n\"reference_value\": null,\n\"reference_unit\": null\n},\n\"rank\": null,\n\"compare_at_price\": \"6000.00\",\n\"line_price\": \"4800.00\",\n\"price\": \"4800.00\"\n},\n{\n\"applied_discounts\": [\n],\n\"discount_allocations\": [\n],\n\"key\": \"1c41fb764cbe579340e9b23d24044f9e\",\n\"destination_location_id\": null,\n\"fulfillment_service\": \"manual\",\n\"gift_card\": false,\n\"grams\": 200,\n\"origin_location_id\": 3035280769203,\n\"presentment_title\": \"Remerita Kawaii Rosa\",\n\"presentment_variant_title\": \"Único\",\n\"product_id\": 7597219283183,\n\"properties\": [\n],\n\"quantity\": 1,\n\"requires_shipping\": true,\n\"sku\": \"I221R004!RS!U\",\n\"tax_lines\": [\n],\n\"taxable\": true,\n\"title\": \"Remerita Kawaii Rosa\",\n\"variant_id\": 42584094081263,\n\"variant_title\": \"Único\",\n\"variant_price\": \"4320.00\",\n\"vendor\": \"Bestia\",\n\"user_id\": null,\n\"unit_price_measurement\": {\n\"measured_type\": null,\n\"quantity_value\": null,\n\"quantity_unit\": null,\n\"reference_value\": null,\n\"reference_unit\": null\n},\n\"rank\": null,\n\"compare_at_price\": \"5400.00\",\n\"line_price\": \"4320.00\",\n\"price\": \"4320.00\"\n},\n{\n\"applied_discounts\": [\n],\n\"discount_allocations\": [\n],\n\"key\": \"9fcf9f320175ec07e56d370bd980a649\",\n\"destination_location_id\": null,\n\"fulfillment_service\": \"manual\",\n\"gift_card\": false,\n\"grams\": 370,\n\"origin_location_id\": 3035280769203,\n\"presentment_title\": \"Sweater Mercedes Benz Lila\",\n\"presentment_variant_title\": \"Talle 1\",\n\"product_id\": 7674746568943,\n\"properties\": [\n],\n\"quantity\": 1,\n\"requires_shipping\": true,\n\"sku\": \"I221S001!LI!1\",\n\"tax_lines\": [\n],\n\"taxable\": true,\n\"title\": \"Sweater Mercedes Benz Lila\",\n\"variant_id\": 42849323811055,\n\"variant_title\": \"Talle 1\",\n\"variant_price\": \"9030.00\",\n\"vendor\": \"Bestia\",\n\"user_id\": null,\n\"unit_price_measurement\": {\n\"measured_type\": null,\n\"quantity_value\": null,\n\"quantity_unit\": null,\n\"reference_value\": null,\n\"reference_unit\": null\n},\n\"rank\": null,\n\"compare_at_price\": \"12900.00\",\n\"line_price\": \"9030.00\",\n\"price\": \"9030.00\"\n}\n]\n}\n]"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        980,
        -340
      ]
    },
    {
      "parameters": {
        "url": "=url_api",
        "options": {},
        "headerParametersUi": {
          "parameter": [
            {
              "name": "token",
              "value": "token"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        1660,
        -220
      ],
      "disabled": true
    },
    {
      "parameters": {
        "functionCode": "return [\n{\n\"images\": [\n{\n\"id\": 37087744295151,\n\"product_id\": 7571586515183,\n\"position\": 1,\n\"created_at\": \"2022-03-18T11:16:54-03:00\",\n\"updated_at\": \"2022-05-17T14:37:29-03:00\",\n\"alt\": null,\n\"width\": 1500,\n\"height\": 2250,\n\"src\": \"https://cdn.shopify.com/s/files/1/0248/9188/3595/products/BESTIAKAWAIVOL12711.jpg?v=1652809049\",\n\"variant_ids\": [\n],\n\"admin_graphql_api_id\": \"gid://shopify/ProductImage/37087744295151\"\n},\n{\n\"id\": 37087742034159,\n\"product_id\": 7571586515183,\n\"position\": 2,\n\"created_at\": \"2022-03-18T11:16:51-03:00\",\n\"updated_at\": \"2022-05-17T14:37:29-03:00\",\n\"alt\": null,\n\"width\": 1500,\n\"height\": 2250,\n\"src\": \"https://cdn.shopify.com/s/files/1/0248/9188/3595/products/BESTIAKAWAIVOL12707.jpg?v=1652809049\",\n\"variant_ids\": [\n],\n\"admin_graphql_api_id\": \"gid://shopify/ProductImage/37087742034159\"\n},\n{\n\"id\": 37087744164079,\n\"product_id\": 7571586515183,\n\"position\": 3,\n\"created_at\": \"2022-03-18T11:16:53-03:00\",\n\"updated_at\": \"2022-05-17T14:37:29-03:00\",\n\"alt\": null,\n\"width\": 1500,\n\"height\": 2250,\n\"src\": \"https://cdn.shopify.com/s/files/1/0248/9188/3595/products/BESTIAKAWAIVOL12686.jpg?v=1652809049\",\n\"variant_ids\": [\n],\n\"admin_graphql_api_id\": \"gid://shopify/ProductImage/37087744164079\"\n},\n{\n\"id\": 37087742329071,\n\"product_id\": 7571586515183,\n\"position\": 4,\n\"created_at\": \"2022-03-18T11:16:51-03:00\",\n\"updated_at\": \"2022-05-17T14:37:29-03:00\",\n\"alt\": null,\n\"width\": 1500,\n\"height\": 2250,\n\"src\": \"https://cdn.shopify.com/s/files/1/0248/9188/3595/products/BESTIAKAWAIVOL12683.jpg?v=1652809049\",\n\"variant_ids\": [\n],\n\"admin_graphql_api_id\": \"gid://shopify/ProductImage/37087742329071\"\n},\n{\n\"id\": 37087744721135,\n\"product_id\": 7571586515183,\n\"position\": 5,\n\"created_at\": \"2022-03-18T11:16:55-03:00\",\n\"updated_at\": \"2022-05-17T14:37:29-03:00\",\n\"alt\": null,\n\"width\": 1500,\n\"height\": 2250,\n\"src\": \"https://cdn.shopify.com/s/files/1/0248/9188/3595/products/BESTIAKAWAIVOL12706.jpg?v=1652809049\",\n\"variant_ids\": [\n],\n\"admin_graphql_api_id\": \"gid://shopify/ProductImage/37087744721135\"\n},\n{\n\"id\": 37087740756207,\n\"product_id\": 7571586515183,\n\"position\": 6,\n\"created_at\": \"2022-03-18T11:16:49-03:00\",\n\"updated_at\": \"2022-05-17T14:37:29-03:00\",\n\"alt\": null,\n\"width\": 1500,\n\"height\": 2250,\n\"src\": \"https://cdn.shopify.com/s/files/1/0248/9188/3595/products/BESTIAKAWAIVOL12701.jpg?v=1652809049\",\n\"variant_ids\": [\n],\n\"admin_graphql_api_id\": \"gid://shopify/ProductImage/37087740756207\"\n},\n{\n\"id\": 37087742722287,\n\"product_id\": 7571586515183,\n\"position\": 7,\n\"created_at\": \"2022-03-18T11:16:52-03:00\",\n\"updated_at\": \"2022-05-17T14:37:29-03:00\",\n\"alt\": null,\n\"width\": 1500,\n\"height\": 2250,\n\"src\": \"https://cdn.shopify.com/s/files/1/0248/9188/3595/products/BESTIAKAWAIVOL12702.jpg?v=1652809049\",\n\"variant_ids\": [\n],\n\"admin_graphql_api_id\": \"gid://shopify/ProductImage/37087742722287\"\n},\n{\n\"id\": 37087740920047,\n\"product_id\": 7571586515183,\n\"position\": 8,\n\"created_at\": \"2022-03-18T11:16:49-03:00\",\n\"updated_at\": \"2022-03-18T11:21:27-03:00\",\n\"alt\": null,\n\"width\": 1500,\n\"height\": 2250,\n\"src\": \"https://cdn.shopify.com/s/files/1/0248/9188/3595/products/BESTIAKAWAIVOL12710.jpg?v=1647613287\",\n\"variant_ids\": [\n],\n\"admin_graphql_api_id\": \"gid://shopify/ProductImage/37087740920047\"\n},\n{\n\"id\": 37595917091055,\n\"product_id\": 7571586515183,\n\"position\": 9,\n\"created_at\": \"2022-05-17T14:16:10-03:00\",\n\"updated_at\": \"2022-05-17T14:16:10-03:00\",\n\"alt\": null,\n\"width\": 2000,\n\"height\": 3000,\n\"src\": \"https://cdn.shopify.com/s/files/1/0248/9188/3595/products/IMG_1757.jpg?v=1652807770\",\n\"variant_ids\": [\n],\n\"admin_graphql_api_id\": \"gid://shopify/ProductImage/37595917091055\"\n},\n{\n\"id\": 37596021883119,\n\"product_id\": 7571586515183,\n\"position\": 10,\n\"created_at\": \"2022-05-17T14:35:51-03:00\",\n\"updated_at\": \"2022-05-17T14:35:51-03:00\",\n\"alt\": null,\n\"width\": 2000,\n\"height\": 3000,\n\"src\": \"https://cdn.shopify.com/s/files/1/0248/9188/3595/products/IMG_1967.jpg?v=1652808951\",\n\"variant_ids\": [\n],\n\"admin_graphql_api_id\": \"gid://shopify/ProductImage/37596021883119\"\n}\n]\n}\n]"
      },
      "name": "Function2",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1880,
        -220
      ]
    },
    {
      "parameters": {
        "content": "Necesito obtener esto:\n\n[[\n{\n\"title\": \"Bucito Schumacher Rosa\",\n\"name\": \"Bucito Schumacher Rosa\",\n\"sku\": \"I221B007!RSS!2\",\n\"product_id\": 7571586515183,\n\"product_image\": \"https://cdn.shopify.com/s/files/1/0248/9188/3595/products/BESTIAKAWAIVOL12711.jpg?v=1652809049\",\n\"price\": \"8240.00\",\n\"vendor\": \"Bestia\",\n\"quantity\": 1\n},\n{\n\"title\": \"Gorro Ferrari Violeta\",\n\"name\": \"Gorro Ferrari Violeta\",\n\"sku\": \"I224AC006!VI!U\",\n\"product_id\": 7571586515183,\n\"product_image\": \"https://cdn.shopify.com/s/files/1/0248/9188/3595/products/BESTIAKAWAIVOL12711.jpg?v=1652809049\",\n\"price\": \"2240.00\",\n\"vendor\": \"Bestia\",\n\"quantity\": 1\n},\n{\n\"title\": \"Remera Honda Negra\",\n\"name\": \"Remera Honda Negra\",\n\"sku\": \"I221T003!NE!2\",\n\"product_id\": 7571586515183,\n\"product_image\": \"https://cdn.shopify.com/s/files/1/0248/9188/3595/products/BESTIAKAWAIVOL12711.jpg?v=1652809049\",\n\"price\": \"4800.00\",\n\"vendor\": \"Bestia\",\n\"quantity\": 1\n},\n{\n\"title\": \"Remerita Kawaii Rosa\",\n\"name\": \"Remerita Kawaii Rosa\",\n\"sku\": \"I221R004!RS!U\",\n\"product_id\": 7571586515183,\n\"product_image\": \"https://cdn.shopify.com/s/files/1/0248/9188/3595/products/BESTIAKAWAIVOL12711.jpg?v=1652809049\",\n\"price\": \"4320.00\",\n\"vendor\": \"Bestia\",\n\"quantity\": 1\n},\n{\n\"title\": \"Sweater Mercedes Benz Lila\",\n\"name\": \"Sweater Mercedes Benz Lila\",\n\"sku\": \"I221S001!LI!1\",\n\"product_id\": 7571586515183,\n\"product_image\": \"https://cdn.shopify.com/s/files/1/0248/9188/3595/products/BESTIAKAWAIVOL12711.jpg?v=1652809049\",\n\"price\": \"9030.00\",\n\"vendor\": \"Bestia\",\n\"quantity\": 1\n}\n]",
        "height": 1220,
        "width": 960
      },
      "name": "Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        2960,
        -320
      ]
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        2760,
        -320
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches1": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 0
          },
          {
            "node": "Function2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Item Lists2": {
      "main": [
        [
          {
            "node": "SplitInBatches1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge1": {
      "main": [
        [
          {
            "node": "Set2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set4": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Item Lists2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set2": {
      "main": [
        [
          {
            "node": "SplitInBatches1",
            "type": "main",
            "index": 0
          },
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Function2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function2": {
      "main": [
        [
          {
            "node": "Set4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "id": 1106,
  "tags": []
}```