Restore opnsense's configuration via API

Started by annduy, December 06, 2023, 06:57:42 AM

Previous topic - Next topic
December 06, 2023, 06:57:42 AM Last Edit: December 06, 2023, 08:57:52 AM by annduy
Hi all,
Now, I am able to download the latest configuration of an Opnsense box by using API at /core/backup/download/this. However, I haven't found the API for the restoration in Opnsense's document, even though in GUI we can select the area for restoration. Is there any way to make restoration (fully or partially) via API?
Thanks in advance for your advices.

AN 

Hi all,
please be updated the status of my asking: after some days of googling, chatGPT, Bard,... I decide to go with another approach for restoring an opnsense backup:
1. create config.xml file on local machine
2. use scp to override config.xml of destination opnsense
3. call API from local machine to reboot the destination opnsense.
It works as my expectation. See the clip for how it works

https://youtu.be/Wz0CVxiWaw8

Merry Xmas to all, :)

Annduy   

Hi there! Like you, I've been experimenting with the API for a while now, and I initially had no idea how to proceed due to the poorly written/generated documentation.

If the URL of the page you're on includes "/ui/" and doesn't end in ".php," it's actually using their own API for configuration. To discover which API they're using, you can press F12 to open the Network Tab. There, you can observe the different POST methods being called, understand what the payload should look like, and anticipate the response. This process isn't documented anywhere, and often you'll find API calls that aren't listed in their official documentation.

Best regards
- Vangsguard

Hi Vangsguard.
Thanks bro for the advice. However, unfortunately, the page "System: Configuration: Backups" is a .php file, therefore no API capability on this, :( . See the attached photo for more info about this page. Anyway, I have worked around and have been able to restore a backup file (full restore) as shared in previous post. I may do some extra work for partial restoration then share with you all in this forum.
Once again, thank you so much for the advice. It should be applicable in many other situations.
Merry Xmas and Happy New Year.

Annduy