I'm quite new to NodeRed. I'm trying to update a MySQL database using HTTP.
I'm using Postman as an HTTP client, sending a PUT request as follows:
The JSON outputted by the HTTP PUT request node is transformed to a Javascript Object by the JSON node. The INSERT DATA Function node takes the object and extracts the values of fields 'estado' and 'id', and uses them to construct a MySQL command in order to update the table. The code of the Function node is the following.
var obj = msg.payload[0];
var estado=obj["estado"];
var id =obj["id"];
msg.topic = "update biblioteca set estado='"+estado+"' where id="+id+";";
return msg;
However, when sending the request in Postman, I get the following error:
TypeError: Cannot read property 'id' of undefined
I'm sure the database and Postman are working properly, since the table is updated correctly when typing the values of "estado" and "id" manually in the funcion node code inesteado of extracting it from the object obj, so I must be doing something wrong when extracting the values of the fields.
However, the code worked properly for several hours after switching the JSON node property "Action" to "Always convert to javascript object". I had several blocks that worked well using similar code, the all of a sudden they all stopped working at once and outputting the same error, without me having changed their code or any other configuration.
Could it possibly be a bug in Node-Red? or am I doing something wrong?