# Rest APi Update iRule

**URL:** <https://community.f5.com/t/rest-api-update-irule/25183>\
**Category:** Technical Forums\
**Tags:** icontrolrest, irules, operations, devops\
**Created:** [September 12, 2018, 3:22pm UTC](https://community.f5.com/t/rest-api-update-irule/25183 "2018-09-12T15:22:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![timbo\_8\_2\_29918](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@timbo\_8\_2\_29918](https://community.f5.com/u/timbo_8_2_29918)\
**Post date:** [September 12, 2018, 3:22pm UTC](https://community.f5.com/t/rest-api-update-irule/25183/1 "2018-09-12T15:22:39Z")

</div>

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:

```tcl
$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 "https://1.1.1.1/mgmt/tm/ltm/rule/~Partition~coolirule" -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

---

<div class="post-metadata">

**Author:** ![Satoshi\_Toyosa1](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@Satoshi\_Toyosa1](https://community.f5.com/u/Satoshi_Toyosa1)\
**Post date:** [September 19, 2018, 10:36pm UTC](https://community.f5.com/t/rest-api-update-irule/25183/2 "2018-09-19T22:36:36Z")

</div>

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.

```tcl
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"
}

```

---

<div class="post-metadata">

**Author:** ![Anjuli\_L](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/anjuli_l/32/20599_2.png) [@Anjuli\_L](https://community.f5.com/u/Anjuli_L)\
**Post date:** [February 6, 2020, 4:34pm UTC](https://community.f5.com/t/rest-api-update-irule/25183/3 "2020-02-06T16:34:56Z")

</div>

For information about updating iRules from the REST API, refer to [K11799414: Managing iRules using the iControl REST API](https://support.f5.com/csp/article/K11799414).
