OPNsense API

Started by fraenki, January 05, 2016, 04:09:55 PM

Previous topic - Next topic
Hi,

is there any further information available regarding the OPNsense API?


  • examples on how to use the API
  • some sort of client code or example code or even a ready-to-use library (I don't want to reinvent the wheel)
  • a reference for all API calls?


Thanks
- Frank

Hi Frank,

There is some documentation available on the wiki:
https://wiki.opnsense.org/index.php/Howto_use_the_API

Although there's no complete list of commands available, the api ready components can easily be found when searching the API directories (find src/opnsense/ -name 'Api').

If you want to create your own api enabled components, just follow the howto guide here:
https://wiki.opnsense.org/index.php/Develop:Creating_the_hello_world_module

Regards,

Ad

Hi Ad,

I'm looking for an API for backups. I cloned the core branch off github and ran the search for the Api directories you mentioned. I found the seven directories:

src/opnsense/mvc/app/controllers/OPNsense/CaptivePortal/Api
src/opnsense/mvc/app/controllers/OPNsense/Core/Api
src/opnsense/mvc/app/controllers/OPNsense/Cron/Api
src/opnsense/mvc/app/controllers/OPNsense/Diagnostics/Api
src/opnsense/mvc/app/controllers/OPNsense/IDS/Api
src/opnsense/mvc/app/controllers/OPNsense/Proxy/Api
src/opnsense/mvc/app/controllers/OPNsense/TrafficShaper/Api

I did a 'grep -i backup *' in these but got no hits.

Does that mean that there is no call to download a backup configuration (yet)?

Bart...

Hi Bart,

The backup/restore code is still legacy code, without api support.
If you just want to download the config.xml from the api, it won't be very difficult to create a plugin that does something like that, but at the moment its not in there yet.

Just out of curiosity, what is your use case? 

Regards,

Ad

Thanks Ad,

I'll have a look at the plugin code sample.

I'd like to run a backup from my main filer, rather than use Google drive.

Bart...