Update device property via NodeRED - invalid JSON content provided

Hi all

I’m simply trying to update a device property via NodeRED, but i’m struggling to find the right format.

My device property:
image

My NodeRED flow:

The code in the function:

var updatedflow = {};
updatedflow.url="https://myserver.aws.thinger.io/v3/users/"+user+"/devices/"+device+"/properties/prevInstWaterFlow";
updatedflow.headers={};
updatedflow.headers["Authorization"] = "Bearer "+token;
updatedflow.headers["content-type"] = "application/json";
updatedflow.content={
            prevInstWaterFlow:0
    }
return updatedflow;

The http component:
image

I keep getting the errors “invalid JSON content provided”. I tried already all combinations that i could think of, but it doesn’t work.
Instead of .content, i tried already .payload, .message, .body…

Any idea what i’m doing wrong?

Thanks!
Gus

Hi @gus

Is there any reason why you are not using the property write node?
screen.20231221-170822
screen.20231221-170827

I believe this will make it easier as the node handles the underlying communication and authorization with thinger

Hi

I tried this indeed, but i couldn’t figure out how to have a variable in the value field? Because this is a changing value in every event. Is it possible to make it variable?

You can pass the value field from the input msg, just as you where doing with the http request node, in the field msg.payload or msg.value. Example:

msg.value = 0;
return msg;

Try it out with a simple inject flow with an inject node
screen.20231221-175658
screen.20231221-175703

Translate it then to a function node and you would be able to use a variable.

Just note that at the moment there is a bug when using msg.payload instead of msg.value and where the value is 0, so it is not possible to pass it as:

msg.payload = 0;
return msg;

Will have it fixed for the next version of the plugin.

Okay that seems to fix it.
First i build a function like this:
image

And then i give it to the write property component:

Thanks!
Gus