Nodal http

My HTTP node sometimes returns an array and sometimes an object, and it breaks my expressions randomly. Why is it inconsistent?

Describe the problem/error/question

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • 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

Hi @Abcryptttoo Welcome!
Let me clarify, as you are getting inconsistent results from the API not from the HTTP node, so i believe that this is an issue related to the API, and for this kind of issue, i would say that consider all the possible output you get from the HTTP node and then configure a code node after that so now you can pick some specific elements reshape them and then pass it down.

One thing we can try with the HTTP node is by setting Response Format → JSON explicitly in the HTTP request node options.

1 Like

welcome to the n8n community @Abcryptttoo
I would normalize the HTTP response right after the HTTP Request node with an Edit Fields or Code node so it always outputs one predictable structure, because in n8n each node passes data as items but the API response body itself can legitimately be either an object or an array depending on what that endpoint returns.

1 Like

hey abcrypto

This is caused by api inconsitency issues

you can fix with this

if (!Array.isArray($json.data)) {
$json.data = [$json.data];
}
return item;

the best thing is to Always standardize external API responses before continuing your workflow.

2 Likes