Access a key from the OpenAI node output

I have an OpenAI node that returns me in the following format:

{
"content": "Lorem Ipsum.... 249591623",
"signal": {
"aborted": false,
"onabort": null
},
"timeout": 10000,
"output": "Lorem ipsum...",
"runId": "XXX",
"threadId": "XXX"
}

After this node, I created a custom code and I need to access the content key, however, the code I created returns the error “Cannot convert undefined or null to object”:

return items.map(item => {
  item.content
})

My question is how do I access the output “content” of the OpenAI node.

Information on your n8n setup

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

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

Please post your workflow so it is easier for us to visualize.
Follow as instructed in the tooltip: Tip: Insert your workflow by clicking '</>' and pasting in the workflow's code

Ready. The descriptions are in Portuguese because I’m from Brazil. If you don’t understand something I’ll answer

I’m from Brazil too :slight_smile:

Try changing the code from you code node to:

return items.map(item => {
  return {
    content: item.json.content
  }
})

Edit:
I wouldn’t personally do it like this, I would use an Edit Fields (Set) node, like this:

1 Like

Thanks a lot, man. It works.

Obrigado, irmão. Vou experimentar dessa outra forma também.

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