How on earth do you use a shell curl command with username and password?

Hey gang,

I’m new to shell scripting but I’m reasonably confident it’s what i’m after, i’m just not sure how to pass auth details properly (have tried so many combinations of answers I’ve found online to date).

I have a wyze v2 camera which is supposed to work with mqtt, but it’s kinda flakey. There is a command I can use via a direct URL though, but it is behind the auth wall.

If I’m logged into the cameras web interface I can add
http://192.168.50.237/cgi-bin/action.cgi?cmd=toggle-rtsp-nightvision-on and it toggles the night vision mode.

I figured I should be able to use the below but it doesn’t work

shell_command:
  night_mode_on_dafang_shell: curl -u "root:ismart12"  http://192.168.50.237/cgi-bin/action.cgi?cmd=toggle-rtsp-nightvision-on

nothing shows up in the logs at all when i run it, but the command appears to run successfully (get a green tick) when I run it from the command line. It also doesn’t throw any errors when running it directly via SSL (but doesn’t actually work either).

If I just hit the URL http://192.168.50.237/cgi-bin/action.cgi?cmd=toggle-rtsp-nightvision-on in a browser, it pops up a dialog asking for U/P, but I imagine I have to be able to automate that process.

Tearing my hair out.

I suggest that you figure out what goes on behind the scenes rather than guessing. I’ve had luck with postman and fiddler in the past.

I am not much into curl but I would try

"curl -u 'http://root:[email protected]/cgi-bin/action.cgi?cmd=toggle-rtsp-nightvision-on'"
or
curl -u http://root:[email protected]/cgi-bin/action.cgi?cmd=toggle-rtsp-nightvision-on

Thanks Joerg, unfortunately not with either of those.

In the same way, entering the root:ismart@ prefix for auth doesn’t work on in a browser either, it just pops an entry box. I can’t believe there isn’t a solution here from an automation perspective. It just evades me.

Try -k (insecure) found here https://gist.github.com/boxgr0ve/a0d…

curl -k https://root:[email protected]/cgi-bin/action.cgi?cmd=toggle-rtsp-nightvision-off

That’s the one! Thanks so much! I swear I had tried it, but I think I also had -u in there also, and they obviously (makes sense) conflict.