Home
Help
Search
Login
Register
OPNsense Forum
»
English Forums
»
General Discussion
»
Problem with api for Unbound AddHostOverride
« previous
next »
Print
Pages: [
1
]
Author
Topic: Problem with api for Unbound AddHostOverride (Read 2006 times)
Yves.degauquier
Newbie
Posts: 1
Karma: 0
Problem with api for Unbound AddHostOverride
«
on:
April 20, 2022, 12:29:22 am »
Hi,
I try to use the API to manage the Unbound DNS by adding new host override.
On this topic Google was not my friend.
I found the API but I still have issue on how to feed the API with data
.
curl -X POST -d '{"host":{"enabled":"1","hostname":"test","domain":"testdomain.com","rr":{"A":{"value":"A (IPv4 address)","selected":1},"AAAA":{"value":"AAAA (IPv6 address)","selected":0},"MX":{"value":"MX (Mail server)","selected":0}},"mxprio":"","mx":"","server":"10.0.1.1","description":""}}' -H "Content-Type: application/json" -k -u $OPNS_KEY:$OPNS_SECRET https://$IPFW/api/unbound/settings/AddHostOverride
The result is:
{"errorMessage":"/usr/local/opnsense/mvc/app/controllers/OPNsense/Base/ApiControllerBase.php:155: Error at /usr/local/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php:345 - Array to string conversion (errno=8)","errorTrace":"#0 /usr/local/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php(345): OPNsense\\Base\\ApiControllerBase->APIErrorHandler(8, 'Array to string...', '/usr/local/opns...', 345, Array)\n#1 /usr/local/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php(446): OPNsense\\Base\\FieldTypes\\BaseField->__toString()\n#2 /usr/local/opnsense/mvc/app/controllers/OPNsense/Base/ApiMutableModelControllerBase.php(218): OPNsense\\Base\\BaseModel->performValidation()\n#3 /usr/local/opnsense/mvc/app/controllers/OPNsense/Base/ApiMutableModelControllerBase.php(383): OPNsense\\Base\\ApiMutableModelControllerBase->validate(Object(OPNsense\\Base\\FieldTypes\\ContainerField), 'host')\n#4 /usr/local/opnsense/mvc/app/controllers/OPNsense/Unbound/Api/SettingsController.php(142): OPNsense\\Base\\ApiMutableModelControllerBase->addBase('host', 'hosts.host')\n#5 [internal function]: OPNsense\\Unbound\\Api\\SettingsController->addHostOverrideAction()\n#6 [internal function]: Phalcon\\Dispatcher\\AbstractDispatcher->callActionMethod(Object(OPNsense\\Unbound\\Api\\SettingsController), 'addHostOverride...', Array)\n#7 [internal function]: Phalcon\\Dispatcher\\AbstractDispatcher->dispatch()\n#8 /usr/local/opnsense/www/api.php(26): Phalcon\\Mvc\\Application->handle('/api/unbound/se...')\n#9 {main}","errorTitle":"An API exception occured"}
Does someone can give me some hints?
Thanks in advance :-)
Logged
isjo-org
Newbie
Posts: 1
Karma: 0
Re: Problem with api for Unbound AddHostOverride
«
Reply #1 on:
May 02, 2022, 11:18:54 am »
Hey, i got the same problem with creating aliases (ansible + uri module)
failed: [test-opn02] (item={'name': 'TEST', 'type': 'host', 'content': ['172.18.0.21', '172.18.100.21'], 'description': 'TEST'}) => {"alias": {"content": ["172.18.0.21", "172.18.100.21"], "description": "TEST", "name": "TEST", "type": "host"}, "ansible_loop_var": "alias", "changed": false, "connection": "close", "content_length": "1555", "content_type": "application/json;charset=utf-8", "date": "Mon, 02 May 2022 09:07:56 GMT", "elapsed": 0, "json": {"errorMessage": "/usr/local/opnsense/mvc/app/controllers/OPNsense/Base/ApiControllerBase.php:155: Error at /usr/local/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php:345 -
Array to string conversion (errno=8)", "errorTitle": "An API exception occured"
, "errorTrace": "#0 /usr/local/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php(345): OPNsense\\Base\\ApiControllerBase->APIErrorHandler(8, 'Array to string...', '/usr/local/opns...', 345, Array)\n#1 /usr/local/opnsense/mvc/app/models/OPNsense/Base/BaseModel.php(446): OPNsense\\Base\\FieldTypes\\BaseField->__toString()\n#2 /usr/local/opnsense/mvc/app/controllers/OPNsense/Base/ApiMutableModelControllerBase.php(218): OPNsense\\Base\\BaseModel->performValidation()\n#3 /usr/local/opnsense/mvc/app/controllers/OPNsense/Base/ApiMutableModelControllerBase.php(383): OPNsense\\Base\\ApiMutableModelControllerBase->validate(Object(OPNsense\\Base\\FieldTypes\\ContainerField), 'alias')\n#4 /usr/local/opnsense/mvc/app/controllers/OPNsense/Firewall/Api/AliasController.php(98): OPNsense\\Base\\ApiMutableModelControllerBase->addBase('alias', 'aliases.alias')\n#5 [internal function]: OPNsense\\Firewall\\Api\\AliasController->addItemAction()\n#6 [internal function]: Phalcon\\Dispatcher\\AbstractDispatcher->callActionMethod(Object(OPNsense\\Firewall\\Api\\AliasController), 'addItemAction', Array)\n#7 [internal function]: Phalcon\\Dispatcher\\AbstractDispatcher->dispatch()\n#8 /usr/local/opnsense/www/api.php(26): Phalcon\\Mvc\\Application->handle('/api/firewall/a...')\n#9 {main}"}, "msg": "Status code was 500 and not [200]: HTTP Error 500: Internal Server Error", "redirected": false, "server": "OPNsense", "status": 500, "url": "
https://172.18.128.11/api/firewall/alias/addItem
"}
any idea?
edit:
solved
! newline fixed it
'content': '172.18.0.21
\n
172.18.100.21'
«
Last Edit: May 02, 2022, 11:31:22 am by isjo-org
»
Logged
eltrophy
Newbie
Posts: 1
Karma: 0
Re: Problem with api for Unbound AddHostOverride
«
Reply #2 on:
November 07, 2023, 02:41:02 pm »
Instead of
curl -X POST -d '{"host":{"enabled":"1","hostname":"test","domain":"testdomain.com","rr":{"A":{"value":"A (IPv4 address)","selected":1},"AAAA":{"value":"AAAA (IPv6 address)","selected":0},"MX":{"value":"MX (Mail server)","selected":0}},"mxprio":"","mx":"","server":"10.0.1.1","description":""}}' -H "Content-Type: application/json" -k -u $OPNS_KEY:$OPNS_SECRET https://$IPFW/api/unbound/settings/AddHostOverride
this will do the job:
curl -X POST -d '{"host":{"enabled":"1","hostname":"test","domain":"testdomain.com","rr":"A","mxprio":"","mx":"","server":"10.0.1.1","description":""}}' -H "Content-Type: application/json" -k -u $OPNS_KEY:$OPNS_SECRET https://$IPFW/api/unbound/settings/AddHostOverride
Logged
Print
Pages: [
1
]
« previous
next »
OPNsense Forum
»
English Forums
»
General Discussion
»
Problem with api for Unbound AddHostOverride