# Need help with curl

**URL:** <https://discourse.nodered.org/t/need-help-with-curl/38279>\
**Category:** General\
**Created:** [30 December 2020 12:32 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279 "2020-12-30T12:32:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigmac5753](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigmac5753/32/15733_2.png) [@bigmac5753](https://discourse.nodered.org/u/bigmac5753)\
**Post date:** [30 December 2020 12:32 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/1 "2020-12-30T12:32:18Z")

</div>

I have this curl command that I need to somehow run in node-red:

`curl -X POST --data-urlencode "url={{url}}" http://{{host}}:8080/youtube-dl/q`

I know it's best to use http rather than exec but can't figure out how to do it.

If it helps, i'm also able to run this fetch command instead:

```auto
fetch(`http://${host}:8080/youtube-dl/q`, {
  method: "POST",
  body: new URLSearchParams({
    url: url,
    format: "bestvideo"
  }),
});

```

Thanks for reading.

---

<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:** [30 December 2020 12:57 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/2 "2020-12-30T12:57:17Z")

</div>

Not sure where host and url are set so had to guess

example http request

```auto
[{"id":"63f3e144.1f0478","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":110,"y":2480,"wires":[["dbf18da0.3fef08"]]},{"id":"a808fae1.564ae","type":"http request","z":"8d22ae29.7df6d","name":"","method":"POST","ret":"txt","paytoqs":"body","url":"http://{{host}}:8080/youtube-dl/q","tls":"","persist":false,"proxy":"","authType":"","x":410,"y":2440,"wires":[["d82a6daf.bc593"]]},{"id":"d82a6daf.bc593","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":600,"y":2460,"wires":[]},{"id":"dbf18da0.3fef08","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload.url","pt":"msg","to":"http://youtube.com/h455ggghhss","tot":"str"},{"t":"set","p":"host","pt":"msg","to":"youtube.com","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":210,"y":2440,"wires":[["a808fae1.564ae"]]}]

```

the payload body has to be a json set in msg.payload.i.e msg.payload.url

---

<div class="post-metadata">

**Author:** ![bigmac5753](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigmac5753/32/15733_2.png) [@bigmac5753](https://discourse.nodered.org/u/bigmac5753)\
**Post date:** [30 December 2020 13:53 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/3 "2020-12-30T13:53:34Z")

</div>

Thanks for your reply.  
`{{url}}` is a link to a youtube video I want to download.  
`{{host}}` is the IP of the server running the youtube-dl software.

Therefore a better command to use would be: `curl -X POST --data-urlencode "url={{url}}" http://192.168.0.2:8080/youtube-dl/q`

Hope this helps, thanks again.

---

<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:** [30 December 2020 14:11 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/4 "2020-12-30T14:11:49Z")

</div>

What i posted should work. Export the section of the flow so we can see how you used it.

---

<div class="post-metadata">

**Author:** ![bigmac5753](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigmac5753/32/15733_2.png) [@bigmac5753](https://discourse.nodered.org/u/bigmac5753)\
**Post date:** [30 December 2020 20:41 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/5 "2020-12-30T20:41:20Z")

</div>

```auto
[{"id":"63f3e144.1f0478","type":"inject","z":"dee1ee38.a66f9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":130,"y":1280,"wires":[["dbf18da0.3fef08"]]},{"id":"a808fae1.564ae","type":"http request","z":"dee1ee38.a66f9","name":"","method":"POST","ret":"txt","paytoqs":"body","url":"http://192.168.0.2:8080/youtube-dl/q","tls":"","persist":false,"proxy":"","authType":"","x":530,"y":1280,"wires":[["d82a6daf.bc593"]]},{"id":"d82a6daf.bc593","type":"debug","z":"dee1ee38.a66f9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":1280,"wires":[]},{"id":"dbf18da0.3fef08","type":"change","z":"dee1ee38.a66f9","name":"","rules":[{"t":"set","p":"payload.url","pt":"msg","to":"https://www.youtube.com/watch?v=6jAb8Bzrs8U","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":1280,"wires":[["a808fae1.564ae"]]}]

```

I've changed the flow slightly as there's no need for `{{host}}`, i've put the server's IP instead.  
I've also linked a valid youtube video - but it will not work, I get this error:

````auto
  File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/usr/local/lib/python3.9/site-packages/starlette/exceptions.py", line 82, in __call__
    raise exc from None
  File "/usr/local/lib/python3.9/site-packages/starlette/exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 582, in __call__
    await route.handle(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 243, in handle
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 54, in app
    response = await func(request)
  File "/usr/src/app/./youtube-dl-server.py", line 35, in q_put
    url = form.get("url").strip()
AttributeError: 'NoneType' object has no attribute 'strip'```
````

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [30 December 2020 20:48 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/6 "2020-12-30T20:48:49Z")

</div>

Have you tried setting the `msg.payload` to be a string containing `url=http://youtube.com?xxxxx` like in your curl example...

> [@bigmac5753](#):
>
> `curl -X POST --data-urlencode "url={{url}}" http://192.168.0.2:8080/youtube-dl/q`

change node...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/3/c39c9d07ac41ab46d20938a785e578ea40e89117.png)

Also, are you certain you want to return a string from the HTTP request?

---

<div class="post-metadata">

**Author:** ![bigmac5753](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigmac5753/32/15733_2.png) [@bigmac5753](https://discourse.nodered.org/u/bigmac5753)\
**Post date:** [30 December 2020 20:54 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/7 "2020-12-30T20:54:44Z")

</div>

Just tried these, neither work:

```auto
[{"id":"cfa7c917.1c39c8","type":"inject","z":"dee1ee38.a66f9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":190,"y":1440,"wires":[["3cc4c4ab.c6acbc"]]},{"id":"b568ddb4.8c72a","type":"http request","z":"dee1ee38.a66f9","name":"","method":"POST","ret":"txt","paytoqs":"body","url":"http://192.168.0.2:8080/youtube-dl/q","tls":"","persist":false,"proxy":"","authType":"","x":590,"y":1440,"wires":[["dc2d954d.e94ba8"]]},{"id":"dc2d954d.e94ba8","type":"debug","z":"dee1ee38.a66f9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":1440,"wires":[]},{"id":"3cc4c4ab.c6acbc","type":"change","z":"dee1ee38.a66f9","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"url=https://www.youtube.com/watch?v=6jAb8Bzrs8U","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1440,"wires":[["b568ddb4.8c72a"]]},{"id":"ac55eccc.d2798","type":"inject","z":"dee1ee38.a66f9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":190,"y":1380,"wires":[["3f19ccbe.7ef084"]]},{"id":"2e0daf3.abed75","type":"http request","z":"dee1ee38.a66f9","name":"","method":"POST","ret":"txt","paytoqs":"body","url":"http://192.168.0.2:8080/youtube-dl/q","tls":"","persist":false,"proxy":"","authType":"","x":590,"y":1380,"wires":[["6326239b.c35fcc"]]},{"id":"6326239b.c35fcc","type":"debug","z":"dee1ee38.a66f9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":1380,"wires":[]},{"id":"3f19ccbe.7ef084","type":"change","z":"dee1ee38.a66f9","name":"","rules":[{"t":"set","p":"payload.url","pt":"msg","to":"url=https://www.youtube.com/watch?v=6jAb8Bzrs8U","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":1380,"wires":[["2e0daf3.abed75"]]}]

```

---

<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:** [30 December 2020 21:01 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/8 "2020-12-30T21:01:40Z")

</div>

Try urlencoding the url

```auto
[{"id":"2475a82e.f6ca18","type":"http request","z":"8d22ae29.7df6d","name":"","method":"POST","ret":"txt","paytoqs":"body","url":"http://192.168.0.2:8080/youtube-dl/q","tls":"","persist":false,"proxy":"","authType":"","x":570,"y":2600,"wires":[["123eba6a.f9aa3e"]]},{"id":"123eba6a.f9aa3e","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":2600,"wires":[]},{"id":"d92e3972.96d3e","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload.url","pt":"msg","to":"$encodeUrl(\"https://www.youtube.com/watch?v=6jAb8Bzrs8U\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":2600,"wires":[["2475a82e.f6ca18"]]},{"id":"eb12914e.a980d8","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":170,"y":2600,"wires":[["d92e3972.96d3e"]]}]

```

you could also try sendng as `application/x-www-form-urlencoded` , by setting `msg.headers["content-type"]`

---

<div class="post-metadata">

**Author:** ![bigmac5753](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigmac5753/32/15733_2.png) [@bigmac5753](https://discourse.nodered.org/u/bigmac5753)\
**Post date:** [30 December 2020 21:08 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/9 "2020-12-30T21:08:21Z")

</div>

nope, tried both and still not working.

I can confirm running this in terminal works:

```auto
curl -X POST --data-urlencode "url=https://www.youtube.com/watch?v=6jAb8Bzrs8U" http://192.168.0.2:8080/youtube-dl/q

```

---

<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:** [30 December 2020 21:18 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/10 "2020-12-30T21:18:31Z")

</div>

Did you try urlEncoding the string ìn the change node? eg.  
set `msg.payload` to  
JSONata expression `$encodeUrl("url=https://www.youtube.com/watch?v=6jAb8Bzrs8U")`

---

<div class="post-metadata">

**Author:** ![bigmac5753](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigmac5753/32/15733_2.png) [@bigmac5753](https://discourse.nodered.org/u/bigmac5753)\
**Post date:** [30 December 2020 21:21 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/11 "2020-12-30T21:21:44Z")

</div>

yes

```auto
[{"id":"cfa7c917.1c39c8","type":"inject","z":"dee1ee38.a66f9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":190,"y":1440,"wires":[["3cc4c4ab.c6acbc"]]},{"id":"b568ddb4.8c72a","type":"http request","z":"dee1ee38.a66f9","name":"","method":"POST","ret":"txt","paytoqs":"body","url":"http://192.168.0.2:8080/youtube-dl/q","tls":"","persist":false,"proxy":"","authType":"","x":590,"y":1440,"wires":[["dc2d954d.e94ba8"]]},{"id":"dc2d954d.e94ba8","type":"debug","z":"dee1ee38.a66f9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":1440,"wires":[]},{"id":"3cc4c4ab.c6acbc","type":"change","z":"dee1ee38.a66f9","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$encodeUrl(\"url=https://www.youtube.com/watch?v=6jAb8Bzrs8U\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1440,"wires":[["b568ddb4.8c72a"]]}]

```

---

<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:** [30 December 2020 22:11 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/12 "2020-12-30T22:11:38Z")

</div>

one last suggestion try appending it as a query string

```auto
[{"id":"63f3e144.1f0478","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":2180,"wires":[["a808fae1.564ae"]]},{"id":"a808fae1.564ae","type":"http request","z":"8d22ae29.7df6d","name":"","method":"POST","ret":"txt","paytoqs":"body","url":"http://192.168.0.2:8080/youtube-dl/q?url=https://www.youtube.com/watch?v=6jAb8Bzrs8U","tls":"","persist":false,"proxy":"","authType":"","x":290,"y":2180,"wires":[["d82a6daf.bc593"]]},{"id":"d82a6daf.bc593","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":2180,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![bigmac5753](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigmac5753/32/15733_2.png) [@bigmac5753](https://discourse.nodered.org/u/bigmac5753)\
**Post date:** [31 December 2020 09:56 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/13 "2020-12-31T09:56:20Z")

</div>

Unfortunately that didn't work either.

I asked the dev and got this response...

> <https://github.com/manbearwiz/youtube-dl-server/issues/75>
>
> what is the correct syntax to send a URL to ytdl-server via HTTP post in node-red?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [31 December 2020 10:00 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/14 "2020-12-31T10:00:45Z")

</div>

The dev wrote "the content type should be `application/x-www-form-urlencoded`"

@E1cid suggested that

> [@E1cid](#):
>
> also try sendng as `application/x-www-form-urlencoded` , by setting `msg.headers["content-type"]`

Did you add that header?

---

<div class="post-metadata">

**Author:** ![bigmac5753](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigmac5753/32/15733_2.png) [@bigmac5753](https://discourse.nodered.org/u/bigmac5753)\
**Post date:** [31 December 2020 10:08 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/15 "2020-12-31T10:08:49Z")

</div>

i'd previously used the header, but not with also setting payload to:

`$encodeUrl("url=https://www.youtube.com/watch?v=6jAb8Bzrs8U")`

So with the above payload combined with the header..... it works!!

Thanks for your help guys, much appreciated.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [31 December 2020 11:05 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/16 "2020-12-31T11:05:42Z")

</div>

I haven't been following this thread, but would one of the youtube nodes be an easier way of achieving this? [node-red-contrib-ytdl (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-ytdl)

---

<div class="post-metadata">

**Author:** ![bigmac5753](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigmac5753/32/15733_2.png) [@bigmac5753](https://discourse.nodered.org/u/bigmac5753)\
**Post date:** [31 December 2020 11:07 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/17 "2020-12-31T11:07:18Z")

</div>

ok, last question on this...

If I pass the URL as `msg.payload.url`, how do I enter that into `$encodeUrl()` ?

I tried `$encodeUrl("url={url}")` but it didn't work.

---

<div class="post-metadata">

**Author:** ![bigmac5753](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigmac5753/32/15733_2.png) [@bigmac5753](https://discourse.nodered.org/u/bigmac5753)\
**Post date:** [31 December 2020 11:10 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/18 "2020-12-31T11:10:51Z")

</div>

Those nodes only allow youtube videos, a standard installation of youtube-dl allows downloading and streaming of many sites - which is what I need.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [31 December 2020 11:13 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/19 "2020-12-31T11:13:28Z")

</div>

OK, that makes sense.

---

<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:** [31 December 2020 11:38 UTC](https://discourse.nodered.org/t/need-help-with-curl/38279/20 "2020-12-31T11:38:09Z")

</div>

try

`$encodeUrl("url=" & payload.url)`

[Next page](https://discourse.nodered.org/t/need-help-with-curl/38279.md?page=2)
