Can’t execute a simple curl command?

I’m SSHing into my router to try and run some simple curl commands. To whit


curl -X POST -H "Content-Type: application/json" \
    -d '{"Token": "MyToken"}' \
    http://192.168.8.1/cgi-bin/api/ovpn/client/list

This gives me an error msg:

{“code”:-1,“msg”:“Token is null”}

What am I doing wrong? I’m fairly certain I have the correct Authorization code in my command.

You’re about to mix up two communications.

  1. connect per ssh and execute local commands.
  2. connect per curl and use the well documented API

It is not useful to login remote to send a http request.
In the API documentation is the very first part ‘Authentication’ (okay, the second, after ‘Prepare the Environment’).

Maybe the API differs from your device. It is useful to know against what device/firmware you are executing the curl-request.

Did you get the token like so?

curl 192.168.8.1/cgi-bin/api/router/login -d "pwd=YOUR_ROUTER_PASS"

The token you get from the above login command you use bellow

curl 192.168.8.1/cgi-bin/api/ovpn/client/list -X POST -H "Content-Type: application/json" -d '{"Token": "TOKEN_HERE"}' 

Yes, I tried that and get

{"code":-1,"msg":"Token is null"}

I’ll get the same at my Beryl (snapshot Firmware).

Does ‘router/hello’ works for you?

lupus@kira:~$ curl -k https://192.168.8.1/cgi-bin/api/router/hello -X GET -H "Content-Type: application/json"
{"init":true,"connected":true,"configured":true,"version":"3.215","firmware_user":"","firmware_type":"","model":"mt1300","mac":"94:83:c4:xx:xx:xx","type":"router","name":"","code":0}

I don’t think it is a SSL issue, because http:// give the same result.

On my SlateAX, I get as result only ‘403 Forbidden’. But I have no time to find the right switch, right now. I’ll try this weekend, again.


Edit:
HINT: Don’t use !! in your Password. At least Linux Bash will expand !! to ‘last command’. Very disturbing.

Else it is working on Beryl with the explaination from @alzhao.

curl -X POST -H "Content-Type: application/json" \
             -H "Authorization: YOUR-ACTUAL-TOKEN" \
             -d '{""}' \
             http://192.168.8.1/cgi-bin/api/ovpn/client/list
1 Like

Where does the actual token (assume ABCDEFG) go?

My ultimate goal is to connect/disconnect to one of the defined OpenVPN or WireGuard clients

I modified my answer. Hope it is clear now.

Please remove the brackets and change text to caps, ie


   -H "Authorization: YOUR-ACTUAL-TOKEN" \

So the next guy that sees this won’t include the brackets.

1 Like

Changed. Thanks for your suggestions.