"TypeError: Cannot read property '0' of undefined"

Have a look at this - https://nodered.org/docs/user-guide/messages
to see how to find the correct path to the data you want.

Also see this post on how to share code and debug so that it is easier to read and import - How to share code or flow json