# Curl command to openDTU

**URL:** <https://discourse.nodered.org/t/curl-command-to-opendtu/76249>\
**Category:** General\
**Created:** [7 March 2023 17:11 UTC](https://discourse.nodered.org/t/curl-command-to-opendtu/76249 "2023-03-07T17:11:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andre7tyone](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andre7tyone/32/77055_2.png) [@Andre7tyone](https://discourse.nodered.org/u/Andre7tyone)\
**Post date:** [7 March 2023 17:11 UTC](https://discourse.nodered.org/t/curl-command-to-opendtu/76249/1 "2023-03-07T17:11:36Z")

</div>

Hello,  
I have tried for two days to post a curl command to a openDTU, but I was not sucessful ☹  
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:

```auto
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:

```auto
[
    {
        "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"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [7 March 2023 17:18 UTC](https://discourse.nodered.org/t/curl-command-to-opendtu/76249/2 "2023-03-07T17:18:57Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Andre7tyone](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andre7tyone/32/77055_2.png) [@Andre7tyone](https://discourse.nodered.org/u/Andre7tyone)\
**Post date:** [7 March 2023 18:04 UTC](https://discourse.nodered.org/t/curl-command-to-opendtu/76249/3 "2023-03-07T18:04:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [7 March 2023 18:28 UTC](https://discourse.nodered.org/t/curl-command-to-opendtu/76249/4 "2023-03-07T18:28:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Andre7tyone](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andre7tyone/32/77055_2.png) [@Andre7tyone](https://discourse.nodered.org/u/Andre7tyone)\
**Post date:** [7 March 2023 20:41 UTC](https://discourse.nodered.org/t/curl-command-to-opendtu/76249/5 "2023-03-07T20:41:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [7 March 2023 21:14 UTC](https://discourse.nodered.org/t/curl-command-to-opendtu/76249/6 "2023-03-07T21:14:38Z")

</div>

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

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

```

try posting that as msg.payload to your api.

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [7 March 2023 22:00 UTC](https://discourse.nodered.org/t/curl-command-to-opendtu/76249/7 "2023-03-07T22:00:42Z")

</div>

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

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

```

Flow:

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 May 2023 22:01 UTC](https://discourse.nodered.org/t/curl-command-to-opendtu/76249/8 "2023-05-06T22:01:29Z")

</div>

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