Description of problem: When invoking SET_UNSET_ENVIRONMENT_VARIABLES API to operate on a batch of user-defined env vars, environment_variables_controller fails to parse the params of YAML format, which is officially documented in the description of the API: { "default_value": null, "description": "Add/Update/Delete application environment variables, e.g. Add/Update: [{'name':'FOO', 'value':'123'}, {'name':'BAR', 'value':'abc'}], {Delete: [{'name':'FOO'}, {'name':'BAR'}]}", "name": "environment_variables", "type": "array", "valid_options": [] } Version-Release number of selected component (if applicable): devenv_4224 How reproducible: always Steps to Reproduce: 1. create an app 2. look up its SET_UNSET_ENVIRONMENT_VARIABLES API 3. add some env vars with the API using the example given in its description curl -k -u user:password https://<BROKER_DNS>/broker/rest/application/52d64852afb999beeb000007/environment-variables -XPATCH -d environment_variables="[{'name':'FOO', 'value':'123'}, {'name':'BAR', 'value':'abc'}]" | python -m json.tool Actual results: When adding the BAR and FOO env vars in the example, it fails with the error below: "api_version": 1.6, "data": null, "messages": [ { "exit_code": 186, "field": "environment_variables", "index": null, "severity": "error", "text": "Invalid environment variables: expected array of hashes" } ], Expected results: Operating on a batch of env vars with SET_UNSET_ENVIRONMENT_VARIABLES API should be successful, with the param format given in the example. Otherwise, we need to update the documentation of this API. Additional info:
Similar problem also exists in the following APIs: ADD_APPLICATION (with multiple env vars) e.g., curl -k -u user:password https://<BROKER_DNS>/broker/rest/domain/stg621/applications -XPOST -d name=py273 -d cartridges[][name]=python-2.7 -d environment_variables=[{'name':'FOO', 'value':'123'}, {'name':'BAR', 'value':'abc'}] | python -m json.tool ADD_CARTRIDGE (with multiple env vars): e.g., curl -k -u user:password https://<BROKER_DNS>/broker/rest/application/52d635f96993b9bb88000007/cartridges -d name=mongodb-2.2 -d environment_variables="[{'name':'FOO', 'value':'123'}, {'name':'BAR', 'value':'abc'}]" | python -m json.tool
I also tried with the following format, but none of these succeeded. Maybe we need to change the type of environment_variables to string, or change the description somehow. 1. without white spaces in the value of environment_variables -d environment_variables=[{'name':'BAR','value':'123'},{'name':'FOO','value':'abc'}] curl -k -u user:password https://<BROKER>/broker/rest/application/52d68ddd819d378008000007/environment-variables -d environment_variables=[{'name':'BAR', 'value':'123'},{'name':'FOO', 'value':'abc'}] -XPATCH | python -m json.tool 2. -d environment_variables[]=[{'name':'BAR', 'value':'123'},{'name':'FOO', 'value':'abc'}] 3. -d environment_variables[0]={'name':'BAR', 'value':'123'} 4. using escaping chars -d environment_variables=\[\{\'name\'\:\'BAR\'\,\'value\'\:\'123\'\}\,\{\'name\'\:\'FOO\'\,\'value\'\:\'abc\'\}\] 5. using a json obj: {'environment_variables': [{'name':'BAR','value':'123'},{'name':'FOO','value':'abc'}]}
You have to post as valid JSON curl -X PATCH -H "Content-Type: application/json" -d "{'environment_variables': [{'name':'BAR','value':'123'},{'name':'FOO','value':'abc'}]}" That works for me. -d environment_variables=[...] is not a valid JSON document, you'd have to be using: environment_variables[][name]=a&environment_variables[][value]=b&....