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>
getroute
payload = '{"route": {"network": "10.0.50.0/24", "gateway": "LAN_DHCP", "descr": "vlan50", "disabled": "0"}}'200 OK{ "result": "saved" }
<Response [200]>
How do I get a more verbose response?
#/usr/bin/python# import librariesimport jsonimport requests# define endpoint and credentialsapi_key = ''api_secret = ''url = 'https://127.0.0.1/api/routes/routes/addroute'headers = {'content-type': 'application/json'}payload = '{"route": {"network": "10.0.50.0/24", "gateway": "LAN_DHCP", "descr": "vlan50", "disabled": "0"}}'# Make the api callr = requests.post(url, data=payload, verify=False, auth=(api_key, api_secret), headers=headers)# Check responseif r.status_code == 200: print r.text response = json.loads(r.text) if response['result'] == 'saved': print ('The payload was successfully saved !') print (response['result'])else: print ('Connection / Authentication issue, response received:') print r.text