apikey = 'xxx'apisecret = 'xxx'url = 'https://10.0.0.254/api/routes/routes/addroute'requests.post(url, data=payload, verify=None, auth=(apikey, apisecret))
{'route': {'network': '10.0.50.0/24', 'gateway': {'Null4': {'value': 'Null4 - 127.0.0.1', 'selected': 0}, 'Null6': {'value': 'Null6 - ::1', 'selected': 0}, 'VLAN_GW': {'value': 'VLAN_GW - 10.0.0.253', 'selected': 1}, 'WAN_DHCP': {'value': 'WAN_DHCP - 192.168.107.2', 'selected': 0}}, 'descr': 'vlan50', 'disabled': '0'}}
{"errorMessage":"Error at /usr/local/opnsense/mvc/app/models/OPNsense/Routes/Route.php:59 - Undefined index: (errno=8)"}
/api/routes/routes/setroute/<uuid>
/api/routes/routes/getroute
'route': { 'descr': '' 'disabled': '1' 'gateway' : 'Null6' 'network' '::1/128'}
payload = '{"route": {"descr": "vlan40", "disabled": "0", "gateway" : "VLAN_GW", "network": "10.0.40.0/24"}}'
<Response [200]>
>>> json.loads(request.text){'result': 'failed'}
import jsonimport requestsapikey = 'xxx'apisecret = 'xxx'url = 'https://10.0.0.254/api/routes/routes/addroute'payload = '{"route":{"descr":"vlan40","disabled":"0","gateway":"VLAN_GW","network":"10.0.40.0/24"}}'res = requests.post(url, data=payload, verify=None, auth=(apikey, apisecret))print(res)print(json.loads(res.text))<Response [200]>{'result': 'failed'}
# cat /tmp/gateway_list.json {"WAN_DHCP":"WAN_DHCP - 192.168.107.2","VLAN_GW":"VLAN_GW - 10.0.0.253","Null4":"Null4 - 127.0.0.1","Null6":"Null6 - ::1"}