JS node broken "||"?

Describe the problem/error/question

I’m running a loop, I have to keep auth code in the loop so I have a code note that has “||” statement, it doesn’t appear to be working at all.
I have very similar || config running in bunch of other workflows.

What is the error message (if any)?

ERROR: Cannot read properties of undefined (reading ‘authorization’) [line 4]

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

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

hello @Mateusz_Bijakowski

Why do you need the authorization in the count node? You can refer to the auth header in the GetDevices node by using the absolute link: $('getJWT').last().json.headers.authorization.

True I can, funny that this works but other ways didn’t.

But that’s not the issue I’m reporting. The II doesn’t work.

It works, you have some mistakes in the authorization section.

You have

items[0].json.headers.authorization || $('count').all()[0].json.authorization

but that won’t work as on the next loop there is no more headers property, so the code node won’t be able to get to the OR statement. Next is that you want to get the authorization from the count node, but it doesn’t have such property :slight_smile:
That one will work:

items[0].json.headers?.authorization || $('count').all()[0].json.auth

Plus, your page++ node looks into $('GetDevices').item.json.response.page so here the response should be the Object, but in the umfurl node we can see that the response is Array: _input.all()[0].json.response[0].devices, so the page++ won’t work and you will get every time the 1st page

1 Like

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