Forum Discussion
API RESTful - Creation a new rule by curl
Hi people, i'm trying to create a rule and define it, by API restful v11.5.3 with this sintax:
curl -k -u admin:pass-H "Content-Type: application/json" -X POST https://IP/mgmt/tm/ltm/rule -d '{ "name" : "Rule_CICCIODINONNAPAPERA", "apiAnonymous" : "when HTTP_REQUEST { if { [HTTP::uri] starts_with "/portalCiccio" } { use pool dinonnapapera } elseif { [HTTP::uri] starts_with "/scriptCiccio" } { use pool dinonnapapera } else { TCP::close } }" }'
but i get this error back
{"code":400,"message":"Found invalid JSON body in the request.","errorStack":[]}
I can't see why and where i wrong... Can someone help me please?
Thanks at all
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 } }" }'
- VernonWellsEmployee
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 } }" }'
- frapes_247370Nimbostratus
thanks
- Marga_Garrido_9Nimbostratus
I am working to create an automated system, would it be possible for you to give more examples like this or some link where to find them?
Thank you very much!
- VernonWellsEmployee
I'd recommend considering a system like Ansible which includes BIG-IP Modules. Having said that, the documentation repository for BIG-IP iControl is also DevCentral, including both articles and API documentation.
- Georgi__Joe__StAltostratus
Actually ansible is still not supporting many things. For instance you can gather fact about irules :).
Currently I am working on a project which utilize ansible and I am using it as a shell of uri calls. Because you can do only simple tasks with it like add node to pool and etc, but you cant manage irules or assign ASM policy to virtual server.
Ansible modules still need a lot of development. BUT it is really nice that someone is already working on it :).
- Greg_JewettCirrus
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