Curl command to openDTU

Hello,
I have tried for two days to post a curl command to a openDTU, but I was not sucessful :frowning:
I want to set a limit and send it to the openDTU (to set a limit in an microinverter). I can set the limit with a curl command on the commandline, but not from red node.
Can somebody help me?
curl command:

curl -u "admin:password" http://192.168.178.70/api/limit/config -d 'data={"serial":"11418295xxxx", "limit_type":1, "limit_value":20}'

Here is my code:

[
    {
        "id": "3fbcc579.1dc12a",
        "type": "inject",
        "z": "12358896a07574c6",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 100,
        "y": 760,
        "wires": [
            [
                "acdcd415afc52c74"
            ]
        ]
    },
    {
        "id": "261e81ee.00f02e",
        "type": "debug",
        "z": "12358896a07574c6",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 630,
        "y": 760,
        "wires": []
    },
    {
        "id": "acdcd415afc52c74",
        "type": "change",
        "z": "12358896a07574c6",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "data",
                "pt": "msg",
                "to": "{\"serial\":\"11418295xxxx\", \"limit_type\":1, \"limit_value\":20}",
                "tot": "json"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 280,
        "y": 760,
        "wires": [
            [
                "ee69209909c23b7c"
            ]
        ]
    },
    {
        "id": "ee69209909c23b7c",
        "type": "http request",
        "z": "12358896a07574c6",
        "name": "",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "http://192.168.178.70/api/limit/config",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "basic",
        "senderr": false,
        "headers": [],
        "x": 470,
        "y": 760,
        "wires": [
            [
                "261e81ee.00f02e"
            ]
        ]
    }
]

The data needs to be in msg.payload, not msg.data, and set your user and password in th http request node (guessing you probably have, just incase)

Tried to set the data in msg.payload, the same result.
User and password I have set in the http request node.

Any errors?
Have you tried Postman for testing?
Add debug nodes and maybe a catch node set to the http request node.

I think there is a wrong syntax in my data string but I can't find the error...
Any idea? Has someone successful post a curl string?

just sent the curl to a http in node and msg.payload returned

{
  "data": "{\"serial\":\"11418295xxxx\", \"limit_type\":1, \"limit_value\":20}"
}

try posting that as msg.payload to your api.

also the data sent to the Http request didnt have data= which is how its expected based on the curl?

if your data is a JS object without data= prepended then you could also use a Function node to JSON stringify it and construct the string

msg.payload = `data=${JSON.stringify(msg.payload)}`;
return msg;

Flow:

[{"id":"3fbcc579.1dc12a","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":1900,"wires":[["acdcd415afc52c74"]]},{"id":"261e81ee.00f02e","type":"debug","z":"54efb553244c241f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":990,"y":1900,"wires":[]},{"id":"acdcd415afc52c74","type":"change","z":"54efb553244c241f","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"serial\":\"11418295xxxx\",\"limit_type\":1,\"limit_value\":20}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":1900,"wires":[["381d208eb03b93ae","1dbcc6404940802c"]]},{"id":"ee69209909c23b7c","type":"http request","z":"54efb553244c241f","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://192.168.178.70/api/limit/config","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"basic","senderr":false,"headers":[],"x":830,"y":1900,"wires":[["261e81ee.00f02e"]]},{"id":"1dbcc6404940802c","type":"function","z":"54efb553244c241f","name":"prepare data","func":"msg.payload = `data=${JSON.stringify(msg.payload)}`;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":630,"y":1900,"wires":[["ee69209909c23b7c","492cdb836e9d1b9b"]]},{"id":"381d208eb03b93ae","type":"debug","z":"54efb553244c241f","name":"debug 29","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":560,"y":1820,"wires":[]},{"id":"492cdb836e9d1b9b","type":"debug","z":"54efb553244c241f","name":"debug 30","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":1820,"wires":[]}]

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