Create iRule REST error: Found invalid JSON body in the request
Greetings,
I saw a few other forums posts about the same error but I was not able to figure out what is wrong with the command below:
curl -sku admin:admin -H "Content-Type: application/json" -X POST https://sampleF5name.test.com/mgmt/tm/ltm/rule -d '{"name":"f5RESTSampleRule", "apiAnonymous":"when CLIENT_ACCEPTED {\n node 172.28.0.41 \n}" }'
I changed the admin credentials and F5 name to post here.
When I run the following command, I get the following back:
{
"code": 400,
"message": "Found invalid JSON body in the request.",
"errorStack": [],
"apiError": 1
}
I ran my JSON through a JSON validator and there were no issues with it so my assumption is that I am passing something to the F5 that is not valid but I am not sure what it is. We already have a few rules like this setup but they were created through the UI.
Any help would be greatly appreciated! I assume im missing something simple here.
BIG-IP v15.1.5 (Build 0.0.10)
I posted your curl command in as is (except for the BIG-IP hostname swap) and it worked just fine:
jrahm % curl -sku admin:admin -H "Content-Type: application/json" -X POST https://ltm3.test.local/mgmt/tm/ltm/rule -d '{"name":"f5RESTSampleRule", "apiAnonymous":"when CLIENT_ACCEPTED {\n node 172.28.0.41 \n}" }' {"kind":"tm:ltm:rule:rulestate","name":"f5RESTSampleRule","partition":"Common","fullPath":"/Common/f5RESTSampleRule","generation":1585,"selfLink":"https://localhost/mgmt/tm/ltm/rule/~Common~f5RESTSampleRule?ver=15.1.2.1","apiAnonymous":"when CLIENT_ACCEPTED {\n node 172.28.0.41 \n}"}
Could be mangled smartquotes or something? Try copying from vs code or vi and not any text editor that "helps" with formatting. 🙂