"typeError: Cannot Read Properties of undefined (reading '0')"

Having issues with my node RED Code

trying pull information from Watson but getting an error in my function node

CODE:
msg.payload = {

    chatId : msg.chatId,
    type : "message",
    content : msg.payload.output.text[0]

};
return msg;

ERROR:

"TypeError: Cannot read properties of undefined (reading '0')"

Hello @Drewdrops, welcome to the forum.

Can you put a debug node to show the data coming from Watson?
Set it to display the complete msg, so we can see the values of msg.chatId and msg.payload.

I have attached a debug to the Watson node. Getting this

object

output: object

intents: array[1]

0: object

intent: "Howdy"

confidence: 1

skill: "main skill"

entities: array[0]

generic: array[1]

0: object

response_type: "text"

text: "Howdy"

please use the "copy value" button when copying a msg or its payload
image

Also, use the forum </> code button BEFORE pasting the copied value.

What you have pasted is unusable.

{"output":{"intents":[{"intent":"Howdy","confidence":1,"skill":"main skill"}],"entities":[],"generic":[{"response_type":"text","text":"Howdy"}]},"user_id":"4f5c2d04-d992-4dd4-8eb2-f8a217f32760","context":{"global":{"system":{"session_start_time":"2022-10-04T09:55:23.307Z","turn_count":1,"user_id":"4f5c2d04-d992-4dd4-8eb2-f8a217f32760","state":"eyJpZCI6IjM1M2ZhZjIwLWNmODMtNGYzNy04MDA3LTQ2ZmU0MDhlN2FhZSIsInNraWxscyI6W3siY29uZmlnIjp7ImFjdGlvbnMiOmZhbHNlLCJ3b3Jrc3BhY2VfaWQiOiIwYWYyODBhZi0yZDBlLTQ3OTYtYmE2NS1iYWRkNmZkOWRkNzciLCJza2lsbF9yZWZlcmVuY2VfaWQiOm51bGx9LCJkaXNhYmxlZCI6ZmFsc2UsImxhbmd1YWdlIjoiZW4iLCJza2lsbF90eXBlIjoiZGlhbG9nIiwic2tpbGxfcmVmZXJlbmNlIjoibWFpbiBza2lsbCIsInNraWxsX3NuYXBzaG90X2lkIjpudWxsLCJza2lsbF9zbmFwc2hvdF9uYW1lIjpudWxsLCJ3b3JrZXJfZGVmaW5pdGlvbl9pZCI6IjBhZjI4MGFmLTJkMGUtNDc5Ni1iYTY1LWJhZGQ2ZmQ5ZGQ3NyJ9LHsiY29uZmlnIjp7Im1lc3NhZ2UiOm51bGwsInZlcnNpb24iOiIyMDE4LTEyLTAzIiwiaGlnaGxpZ2h0IjpudWxsLCJpbnN0YW5jZV9pZCI6bnVsbCwiY29sbGVjdGlvbl9pZCI6bnVsbCwiZGlzY292ZXJ5X3VybCI6bnVsbCwiZXJyb3JfbWVzc2FnZSI6bnVsbCwiZW52aXJvbm1lbnRfaWQiOm51bGwsInJlc3VsdHNfcGVyX3BhZ2UiOm51bGwsIm1heF90b3RhbF9yZXN1bHRzIjpudWxsLCJub19yZXN1bHRfbWVzc2FnZSI6bnVsbCwicGFnaW5hdGlvbl9lbmFibGVkIjpmYWxzZSwic2NoZW1hX21hcHBpbmdfdXJsIjpudWxsLCJtYXhfcHJpbWFyeV9yZXN1bHRzIjpudWxsLCJzY2hlbWFfbWFwcGluZ19ib2R5IjpudWxsLCJiYXNpY19hdXRoZW50aWNhdGlvbiI6bnVsbCwic2NoZW1h..."},"session_id":"4f5c2d04-d992-4dd4-8eb2-f8a217f32760"},"skills":{"main skill":{"system":{}}}},"session_id":"4f5c2d04-d992-4dd4-8eb2-f8a217f32760"}

This is not a valid path (given your data)

The safest way to determine the path to an item is to use the built in tools - in this case, "copy path"
chrome_hspz14YGHn

That results in : msg.payload.output.generic[0].text

1 Like

Thank you so much

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