Getting all items from Trello API Call

Likely in the set node, you’re referencing the first array element of each item.

Item is an object in the top level array. So when getting all cards, it works since each card is not an array, but a single object. But when you fetch checklist item for each card, you’re now getting an array of checklist items for each card.
So 1 item = card
And afterwards 1 item = 1 array of checklist items.

If you want to turn each checklist item into a sheet row, you’ll need a function node to transform the data prior to loading into a spreadsheet node.

Here is an example, I created a simple object with only two key:values but should be a good guide for your specific case:

  "nodes": [
    {
      "parameters": {
        "functionCode": "var newItems = [];\n//var length = items.length;\n\n\n//first for loop iterates over each item (an array of checklist objects)\nfor(i=0; i< items.length; i++) {\n  //Second for loop iterates over each checklist array, and pushes each checklist item to a newItems\n  for(y=0; y < items[i].json.length; y++) {\n    newItems.push({ json: items[i].json[y]});\n  }\n  \n\n}\n\n//Now each checklist item is in a flat array (no objects), and we return it, so the output of this node is this newItems array\nreturn newItems;\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        720,
        310
      ]
    },
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "items[0].json = [\n  {\n      name: \"3 tablespoons vegetable\",\n      state: \"incomplete\"\n  },\n  {\n      name: \"canola\",\n      state: \"complete\"\n  },\n  {\n      name: \"or peanut oil\",\n      state: \"incomplete\"\n  }\n\n];\nitems.push({json: [\n  {\n      name: \"5 tablespoons vegetable\",\n      state: \"incomplete\"\n  },\n  {\n      name: \"olive oil\",\n      state: \"complete\",\n  },\n  {\n      name: \"or peanut oil\",\n      state: \"incomplete\"\n  }\n\n]});\n\nreturn items;"
      },
      "name": "Mock data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        310
      ]
    },
    {
      "parameters": {
        "functionCode": "var newItems = [];\n//var length = items.length;\n\n\n//first for loop iterates over each item (an array of checklist objects)\nfor(i=0; i< items.length; i++) {\n  //Second for loop iterates over each checklist array, and pushes each checklist item to a newItems\n  for(y=0; y < items[i].json.length; y++) {\n    newItems.push({ json: items[i].json[y]});\n  }\n  \n\n}\n\n//Now each checklist item is in a flat array (no objects), and we return it, so the output of this node is this newItems array\nreturn newItems;\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        720,
        310
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Mock data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mock data": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

There are definitely cleaner shorthands for doing what I am above with the two for() loops, but hopefully it makes the “how” clearer.

Sidenote: we are working towards having some transform nodes so things like this could be achieved without a function node. Will add this case to my list!

1 Like