> This page is for Applications Protection.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.humansecurity.com/llms.txt.

# Update field by rule ID

PATCH https://console.humansecurity.com/api/v2/botDefender/customRules/{ruleId}
Content-Type: application/json

Update specified custom fields for a rule based on the rule's ID.


Reference: https://docs.humansecurity.com/applications/reference/update-field-by-rule-id

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Servers

- `https://console.humansecurity.com/api` (Version 1 of the API, default)
- `https://console.humansecurity.com/api` (Version 2 of the API)

## Request

### Path parameters

- `ruleId` (string, required) — The ID for the rule. You can get this from the [get custom rules](/applications/reference/get-custom-rules) endpoint or from the Portal's Policy Settings.

### Body (application/json)

This endpoint expects an updateCustomRule.

- `ruleId` (string, optional)
- `priority` (integer, optional) — Range from 0 (the highest priority) to the number of rules minus 1 (the lowest priority). For example, if there are 10 rules, then the 0th rule is the highest priority while the 9th rule is the lowest priority. By default, the priority will be set to the lowest priority.
- `name` (string, optional)
- `description` (string, optional)
- `conditions` (UpdateCustomRuleConditions, optional) — A nested object with **exactly** two levels.
- `actions` (list of enum, optional)
  - Allowed values: `allow`, `blockWithChallenge`, `hardBlock`
- `status` (enum, optional)
  - Allowed values: `active`, `paused`

## Response

### 200

Success

- `result` (boolean, optional)
- `message` (string, optional)
- `content` (customRule, optional)

## Types

### UpdateCustomRuleConditions

A nested object with **exactly** two levels.

- `operator` (enum, optional)
  - Allowed values: `$or`, `$and`
- `children` (list of UpdateCustomRuleConditionsChildrenItems, optional)

### customRule

- `name` (string, required)
- `conditions` (CustomRuleConditions, required) — A nested object with **exactly** two levels.
- `actions` (list of enum, required)
  - Allowed values: `allow`, `blockWithChallenge`, `hardBlock`
- `status` (enum, required)
  - Allowed values: `active`, `paused`
- `ruleId` (string, optional)
- `priority` (integer, optional, default: the value corresponding to the lowest priority rule.) — API returns rules between 0 (the highest priority) and the number of rules minus 1 (the lowest priority). This corresponds to the console's rules between 1 (the highest priority) and the number of rules. For example, if there are 10 rules, then in the API, the 0th rule is the highest priority while the 9th rule is the lowest priority. This 0th rule corresponds to the 1st rule in the console. Based on this example, the default value would be 9.
- `description` (string, optional)

### UpdateCustomRuleConditionsChildrenItems

- `operator` (enum, optional)
  - Allowed values: `$or`, `$and`
- `children` (list of UpdateCustomRuleConditionsChildrenItemsChildrenItems, optional)

### CustomRuleConditions

A nested object with **exactly** two levels.

- `operator` (enum, optional)
  - Allowed values: `$or`, `$and`
- `children` (list of CustomRuleConditionsChildrenItems, optional)

### UpdateCustomRuleConditionsChildrenItemsChildrenItems

- `operator` (enum, optional) — The operator to filter with. See [this article](/applications/reference/custom-rule-operators-and-conditions) for details on how to implement.
  - Allowed values: `$eq`, `$contains`, `$startsWith`, `$endsWith`, `$re`, `$notEndsWith`, `$ne`, `$in`, `$notIn`, `$exists`, `$notExists`
- `conditionType` (enum, optional) — The condition to filter by. See [this article](/applications/reference/custom-rule-operators-and-conditions) for details on how to implement.
  - Allowed values: `userAgent`, `domain`, `socketIps`, `socketIpASN`, `path`, `queryParam`, `header`, `httpMethod`, `deviceType`, `country`, `customParam`
- `value` (UpdateCustomRuleConditionsChildrenItemsChildrenItemsValue, optional) — The value(s) to match based on the operator. Not required with exists or notExists, but required otherwise. See [this article](/applications/reference/custom-rule-operators-and-conditions) for details on how to implement.
- `fieldOption` (UpdateCustomRuleConditionsChildrenItemsChildrenItemsFieldOption, optional) — The name of the field. Only required when using a `queryParam`, `header`, or `customParam` condition. See [this article](/applications/reference/custom-rule-operators-and-conditions) for details on how to implement.

### CustomRuleConditionsChildrenItems

- `operator` (enum, optional)
  - Allowed values: `$or`, `$and`
- `children` (list of CustomRuleConditionsChildrenItemsChildrenItems, optional)

### UpdateCustomRuleConditionsChildrenItemsChildrenItemsValue

The value(s) to match based on the operator. Not required with exists or notExists, but required otherwise. See [this article](/applications/reference/custom-rule-operators-and-conditions) for details on how to implement.

### UpdateCustomRuleConditionsChildrenItemsChildrenItemsFieldOption

The name of the field. Only required when using a `queryParam`, `header`, or `customParam` condition. See [this article](/applications/reference/custom-rule-operators-and-conditions) for details on how to implement.

### CustomRuleConditionsChildrenItemsChildrenItems

- `operator` (enum, optional) — The operator to filter with. See [this article](/applications/reference/custom-rule-operators-and-conditions) for details on how to implement.
  - Allowed values: `$eq`, `$contains`, `$startsWith`, `$endsWith`, `$re`, `$notEndsWith`, `$ne`, `$in`, `$notIn`, `$exists`, `$notExists`
- `conditionType` (enum, optional) — The condition to filter by. See [this article](/applications/reference/custom-rule-operators-and-conditions) for details on how to implement.
  - Allowed values: `userAgent`, `domain`, `socketIps`, `socketIpASN`, `path`, `queryParam`, `header`, `httpMethod`, `deviceType`, `country`, `customParam`
- `value` (CustomRuleConditionsChildrenItemsChildrenItemsValue, optional) — The value(s) to match based on the operator. Not required with exists or notExists, but required otherwise. See [this article](/applications/reference/custom-rule-operators-and-conditions) for details on how to implement.
- `fieldOption` (CustomRuleConditionsChildrenItemsChildrenItemsFieldOption, optional) — The name of the field. Only required when using a `queryParam`, `header`, or `customParam` condition. See [this article](/applications/reference/custom-rule-operators-and-conditions) for details on how to implement.

### CustomRuleConditionsChildrenItemsChildrenItemsValue

The value(s) to match based on the operator. Not required with exists or notExists, but required otherwise. See [this article](/applications/reference/custom-rule-operators-and-conditions) for details on how to implement.

### CustomRuleConditionsChildrenItemsChildrenItemsFieldOption

The name of the field. Only required when using a `queryParam`, `header`, or `customParam` condition. See [this article](/applications/reference/custom-rule-operators-and-conditions) for details on how to implement.

## Examples

**Request**

```json
{}
```

**Response**

```json
{
  "result": true,
  "message": "success",
  "content": {
    "name": "string",
    "conditions": {
      "operator": "$or",
      "children": [
        {
          "operator": "$or",
          "children": [
            {
              "operator": "$eq",
              "conditionType": "userAgent",
              "value": "string",
              "fieldOption": "string"
            }
          ]
        }
      ]
    },
    "actions": [
      "allow"
    ],
    "status": "active",
    "ruleId": "a747610a-e1d6-4e50-bc60-04c8787ac7b8",
    "priority": 1,
    "description": "string"
  }
}
```

**SDK Code**

```python
import requests

url = "https://console.humansecurity.com/api/v2/botDefender/customRules/a747610a-e1d6-4e50-bc60-04c8787ac7b8"

payload = {}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.patch(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://console.humansecurity.com/api/v2/botDefender/customRules/a747610a-e1d6-4e50-bc60-04c8787ac7b8';
const options = {
  method: 'PATCH',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://console.humansecurity.com/api/v2/botDefender/customRules/a747610a-e1d6-4e50-bc60-04c8787ac7b8"

	payload := strings.NewReader("{}")

	req, _ := http.NewRequest("PATCH", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://console.humansecurity.com/api/v2/botDefender/customRules/a747610a-e1d6-4e50-bc60-04c8787ac7b8")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.patch("https://console.humansecurity.com/api/v2/botDefender/customRules/a747610a-e1d6-4e50-bc60-04c8787ac7b8")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://console.humansecurity.com/api/v2/botDefender/customRules/a747610a-e1d6-4e50-bc60-04c8787ac7b8', [
  'body' => '{}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://console.humansecurity.com/api/v2/botDefender/customRules/a747610a-e1d6-4e50-bc60-04c8787ac7b8");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://console.humansecurity.com/api/v2/botDefender/customRules/a747610a-e1d6-4e50-bc60-04c8787ac7b8")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PATCH"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```