Http request POST form data

Would anyone have a tip on how I can create an HTTP request with node red flow?

This is Python code that I can trying to figure out how to recreate with node-red. Its an http POST with form data.

import requests

url = "http://127.0.0.1:5000/read"
read_req = {"address": "12345:2",
        "object_type": "analogValue",
        "object_instance": "302"}

print(requests.post(url, read_req).text)

Just trying to use the http request block, still learning node-red :slight_smile:

But in node red it doesnt seem like there is an easy button for an http post for form data. Would anyone have any tips? Any tips with a javascript function would be greatly appreciated if I need to go to that extent.

Hi @bbartling

Add a Function node in front of the HTTP Request node with the following:

msg.payload =  {
  "address": "12345:2",
  "object_type": "analogValue",
  "object_instance": "302"
};
return msg;

Does this look right?

msg.headers = {
    "Content-Type": "application/json"
};


msg.payload = {
    "address": "12345:2",
    "object_type": "analogValue",
    "object_instance": "302"
};
return msg;

This is what I have so far thanks for the tips, does it look right?

For some reason in the console I am getting a
image

In Python requests ill get this if the keys arent named correctly

"address": 
"object_type"
"object_instance"

You currently have the HTTP Request node configured to return a parsed JSON object. The error you're getting suggests the response to the HTTP Request isn't parsable JSON. Change the Request node configuration to return a String and see what you get.

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