1
General Discussion / Change Nginx Upstreamserver via API
« on: June 23, 2022, 02:34:35 pm »
Hi,
I would like to change the upstream server for Nginx via the API.
I'm able to change several attributes with the API, but the one thing I'd like to do doesn't work.
This (for example) works:
curl --location --request POST 'https://10.10.13.1:8443/api/nginx/settings/setupstreamserver/99bfa024-506b-4b1a-8481-bebe2d02fa41' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic YldGRXdrV3VxYXRoOVIwWmpFcWkwdng ... ZSXRXTTI=' \
--data-raw '{"upstream_server":{"description":"missrv2"}}'
This doesn't:
curl --location --request POST 'https://10.10.13.1:8443/api/nginx/settings/setupstreamserver/99bfa024-506b-4b1a-8481-bebe2d02fa41' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic YldGRXdrV3VxYXRoOVIwWmpFcWkwdng ... ZSXRXTTI=' \
--data-raw '{"upstream_server":{"no_use":{"down":{"selected":1}}}}
The error message is:
{
"errorMessage": "/usr/local/opnsense/mvc/app/controllers/OPNsense/Base/ApiControllerBase.php:159: Error at /usr/local/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php:337 - Array to string conversion (errno=8)",
"errorTrace": "#0 /usr/local/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php(337): OPNsense\\Base\\ApiControllerBase->APIErrorHandler(8, 'Array to string...', '/usr/local/opns...', 337, 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(454): OPNsense\\Base\\ApiMutableModelControllerBase->validate(Object(OPNsense\\Base\\FieldTypes\\ContainerField), 'upstream_server')\n#4 /usr/local/opnsense/mvc/app/controllers/OPNsense/Nginx/Api/SettingsController.php(155): OPNsense\\Base\\ApiMutableModelControllerBase->setBase('upstream_server', 'upstream_server', '99bfa024-506b-4...')\n#5 [internal function]: OPNsense\\Nginx\\Api\\SettingsController->setupstreamserverAction('99bfa024-506b-4...')\n#6 [internal function]: Phalcon\\Dispatcher\\AbstractDispatcher->callActionMethod(Object(OPNsense\\Nginx\\Api\\SettingsController), 'setupstreamserv...', Array)\n#7 [internal function]: Phalcon\\Dispatcher\\AbstractDispatcher->dispatch()\n#8 /usr/local/opnsense/www/api.php(26): Phalcon\\Mvc\\Application->handle('/api/nginx/sett...')\n#9 {main}",
"errorTitle": "An API exception occured"
}
I thought maybe I need to deselect the active one first or do the deactivation of the old and the activation of the new one in one step, but these two other solution approaches didn't work either.
I guess it's more of a syntax problem, but I can't see what that could be.
Can someone give me a hint?
LG,
Roland.
I would like to change the upstream server for Nginx via the API.
I'm able to change several attributes with the API, but the one thing I'd like to do doesn't work.
This (for example) works:
curl --location --request POST 'https://10.10.13.1:8443/api/nginx/settings/setupstreamserver/99bfa024-506b-4b1a-8481-bebe2d02fa41' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic YldGRXdrV3VxYXRoOVIwWmpFcWkwdng ... ZSXRXTTI=' \
--data-raw '{"upstream_server":{"description":"missrv2"}}'
This doesn't:
curl --location --request POST 'https://10.10.13.1:8443/api/nginx/settings/setupstreamserver/99bfa024-506b-4b1a-8481-bebe2d02fa41' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic YldGRXdrV3VxYXRoOVIwWmpFcWkwdng ... ZSXRXTTI=' \
--data-raw '{"upstream_server":{"no_use":{"down":{"selected":1}}}}
The error message is:
{
"errorMessage": "/usr/local/opnsense/mvc/app/controllers/OPNsense/Base/ApiControllerBase.php:159: Error at /usr/local/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php:337 - Array to string conversion (errno=8)",
"errorTrace": "#0 /usr/local/opnsense/mvc/app/models/OPNsense/Base/FieldTypes/BaseField.php(337): OPNsense\\Base\\ApiControllerBase->APIErrorHandler(8, 'Array to string...', '/usr/local/opns...', 337, 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(454): OPNsense\\Base\\ApiMutableModelControllerBase->validate(Object(OPNsense\\Base\\FieldTypes\\ContainerField), 'upstream_server')\n#4 /usr/local/opnsense/mvc/app/controllers/OPNsense/Nginx/Api/SettingsController.php(155): OPNsense\\Base\\ApiMutableModelControllerBase->setBase('upstream_server', 'upstream_server', '99bfa024-506b-4...')\n#5 [internal function]: OPNsense\\Nginx\\Api\\SettingsController->setupstreamserverAction('99bfa024-506b-4...')\n#6 [internal function]: Phalcon\\Dispatcher\\AbstractDispatcher->callActionMethod(Object(OPNsense\\Nginx\\Api\\SettingsController), 'setupstreamserv...', Array)\n#7 [internal function]: Phalcon\\Dispatcher\\AbstractDispatcher->dispatch()\n#8 /usr/local/opnsense/www/api.php(26): Phalcon\\Mvc\\Application->handle('/api/nginx/sett...')\n#9 {main}",
"errorTitle": "An API exception occured"
}
I thought maybe I need to deselect the active one first or do the deactivation of the old and the activation of the new one in one step, but these two other solution approaches didn't work either.
I guess it's more of a syntax problem, but I can't see what that could be.
Can someone give me a hint?
LG,
Roland.