Forum Discussion

timbo_8_2_29918's avatar
Icon for Nimbostratus rankNimbostratus
Sep 12, 2018

Rest APi Update iRule

Hi There


I have been researching this all day and cannot seem to get a solution. I am trying to "Update" an iRUle using the Rest API. Im using powershell and am getting the below error:


Invoke-RestMethod : {"code":400,"message":"incomplete command","errorStack":[],"apiError":26214401}


here is my code:


$body = @{apiAnonymous = 'Redirect Traffic to 2 pools based on the URI
               when HTTP_REQUEST {

                       if {[string tolower [HTTP::uri]] contains "/1111/"} {
                            pool A
                       } else {
                       pool B
               '} | ConvertTo-Json

Invoke-RestMethod -Method PATCH -Uri "" -Credential $mycreds -body $body -ContentType "application/json"

The only information i can find on this suggests that i delete my iRule and create a new one.... i would like to try and avoid this if i can.


Regards Tim


2 Replies

  • Most likely due to the special characters not escaped properly (depending on where you run) or LF (0x0A) not written in the literal \n (0x5C 0x6E) in a JSON body. The following curl request worked for me.

     cat sat
      "apiAnonymous":" this is a test\n
    when CLIENT_ACCEPTED {\n
      log local0. \"Hello World\"\n
     curl -sku admin:admin https:///mgmt/tm/ltm/rule/satoshi -X PATCH -H "Content-Type: application/json" -d@sat
        "apiAnonymous": " this is a test\nwhen CLIENT_ACCEPTED {\n  log local0. \"Hello World\"\n}",
        "fullPath": "satoshi",
        "generation": 986,
        "kind": "tm:ltm:rule:rulestate",
        "name": "satoshi",
        "selfLink": "https://localhost/mgmt/tm/ltm/rule/satoshi?ver=13.1.0"