Forum Discussion
API RESTful - Creation a new rule by curl
- Feb 12, 2016
There are two problems. Firstly, you have double-quotes in the rule definition that aren't escaped. The shell will divide arguments on those quotes. Secondly, there is a syntax error. The use pool ... command should be simply pool .... The following works:
curl -k -u 'admin:pass' -H "Content-Type: application/json" \ -X POST https://host/mgmt/tm/ltm/rule -d \ '{ "name" : "RuleUpload", "apiAnonymous" : "when HTTP_REQUEST { if { [HTTP::uri] starts_with \"/portalCiccio\" } { pool dinonnapapera } elseif { [HTTP::uri] starts_with \"/scriptCiccio\" } { pool dinonnapapera } else { TCP::close } }" }'
All..
If you are dumbfounded with the error "", then you are not alone. I just spent the last couple of days yelling at my computer and the F5 API.
If you are using "Requests: HTTP for Humans" (https://2.python-requests.org/en/master/) module/library within Python to perform http requests to the API, and you are sending JSON objects as part of the data, then they must use the syntax:
NOT:
Example:
Perform a "Config-Sync" with the API, and using "data=postData" you will receive
{u'errorStack': [], u'message': u'Found invalid JSON body in the request.', u'code': 400, u'apiError': 1}
Changing that to "json=postData", removes the error as it properly encodes the json data into the request.
Hope this helps!
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com