cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.

Create iRule REST error: Found invalid JSON body in the request

NetworkingSometimes
Nimbostratus
Nimbostratus

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)

 

1 ACCEPTED SOLUTION

JRahm
Community Manager
Community Manager

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. 🙂

View solution in original post

3 REPLIES 3

JRahm
Community Manager
Community Manager

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. 🙂

Must be something weird with me doing it through Windows command line.  I tried a few different code editors as well as retyping the command manually to ensure I was not copy-pasting a bad character.  I still kept getting the same error.

Your post was helpful though, that told me I was at least passing the correct info.  I ended up writing a small c# program that would create the iRule for me using the REST API and it works great.

Thank you! 

been a while since I danced with C#...nice!