How do you build a command to use the API?

I’m trying to use the OpenVPN API to connect to a VPN.

This is what I have so far:


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

The API requires two parameters, enableovpn and ovpnclientid. Using the /list API I see the vpn im interested in has a client id of ovpn1. enableovpn is a string, but I’m not sure what I should put there for connect/disconnect. But even if I did, I don’t know where to put these parameters. Can someone show me the way to build this command?

I kinda figured it out. I think. I added force_client because I was getting errors. It’s not documented so :man_shrugging:

This connects to ovpn1 To disconnect, change enableovpn to zero.

curl -X POST -H 'Content-Type: application/json' \
             -H 'Authorization: MYTOKEN' \
             -d 'enableovpn=1' \
             -d 'ovpnclientid=ovpn1' \
             -d 'force_client=1' \
             http://ROUTERIP/cgi-bin/api/ovpn/client/set

It looks like you have found a way. We are sorry that our documentation does not describe the parameters in detail.
For 3.x firmware, you can use this function on the web UI while opening the browser’s developer tools (Ctrl + Shift + I / F12) to view the network request to find the parameters. We will provide full API documentation for the 4.x firmware.

No problem. Got another issue. How long do the tokens last? Is there a way to make one last indefinitely?

If I remember correctly, the expiry date is refreshed every time the API is called. You can try getting the device status every 5 minutes.
If that doesn’t work, I’ll confirm the code logic later.

For now I just get a new token before I use the API. Seems to work. Now I can use google home to turn on the VPN in front of my streamer setup. Nice.