"Code" node - Run Once for each item - Code doesn't return a single object [item 0]

Describe the problem/error/question

I’m trying to run a “Code node” using “Run Once for Each Item” but it only works for “Run Once for all items” (and returns what I need but only for the first item).

What is the error message (if any)?

The error I’m getting is this →

“Code doesn’t return a single object [item 0]
An array of objects was returned. If you need to output multiple items, please use the ‘Run Once for All Items’ mode instead.”

Please share your workflow

Share the output returned by the last node

The input I’m using for the node having problems is:

[
  {
    "outputUrl": "[\"https://api.pdfrest.com/resource/2f8d337f0-8a6b-48d8-8183-aff10704627f?format=file\",\"https://api.pdfrest.com/resource/2d95b0164-a03d-476b-86e4-70cb97968242?format=file\"]"
  },
  {
    "outputUrl": "[\"https://api.pdfrest.com/resource/22778fd97-9aad-4a7d-91d8-c2b1773bca18?format=file\",\"https://api.pdfrest.com/resource/2598d934c-4bd9-41e0-b851-bc1125eee7c9?format=file\"]"
  }
]

I need to run the code for each outputUrl as a separate item.

I expect to receive as an output something like this for each item:

[
  {
    "imageBlocks": [
      {
        "type": "image_url",
        "image_url": {
          "url": "one-url-here"
        }
      },
      {
        "type": "image_url",
        "image_url": {
          "url": "another-url-here"
        }
      }
    ]
  }
]

Information on your n8n setup

  • n8n version: 1.75.2
  • Database (default: SQLite): no DB
  • n8n EXECUTIONS_PROCESS setting (default: own, main): don’t know
  • Running n8n via (Docker, npm, n8n cloud, desktop app): npm
  • Operating system: windows 11

Sometimes I have similar errors and ChatGPT always fixes the code for me.

What I do is:

  • Explain the context (n8n code node)
  • Give an example of the input
  • Explain the desired output
  • Tell if I’m using Execute once per item or once for all items
  • Report the errors until it gets the code right

See if that can fix your code!
Let me know how it goes :muscle:

And if my reply helps with your issue, please remember to mark it as the solution.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.