> For the complete documentation index, see [llms.txt](https://docs.wproofreader.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wproofreader.com/api-reference/style-guide-api/actions/add-rule-addrule.md).

# Add rule (addrule)

Create a new style guide rule.

### Request

Use the shared HTTP API endpoint and request formats.

See [HTTP API Overview](/api-reference/overview.md).

#### Parameters

| Parameter         | Type      | Required | Default       | Notes                                                            |
| ----------------- | --------- | -------- | ------------- | ---------------------------------------------------------------- |
| `cmd`             | string    | Yes      | `style_guide` | Command name.                                                    |
| `action`          | string    | Yes      | `addrule`     | Action name.                                                     |
| `collection`      | string    | Yes      |               | A name of the collection in which rules are stored.              |
| `lang`            | string    | No       | `common`      | Language scope to create the rule in (example: `en_US` or `en`). |
| `patterns`        | string\[] | Yes      |               | Patterns to match.                                               |
| `suggestions`     | string\[] | No       | \[]           | Replacement suggestions.                                         |
| `state`           | boolean   | No       | `true`        | Enables/disables the rule.                                       |
| `context_include` | string\[] | No       | \[]           | Matches only when one of these contexts exists.                  |
| `context_exclude` | string\[] | No       | \[]           | Skips matches when one of these contexts exists.                 |
| `description`     | string    | No       |               | Message shown to the user.                                       |

{% hint style="info" %}
You can’t choose a rule ID.

The rule ID is generated as a hash of `patterns` + `context_include`. If `patterns` or `context_include` changes later, the rule will get a new ID.
{% endhint %}

### Behavior

* Creates a new rule in the target style guide file.
* Returns the created rule in `result`.

### Response

Single rule object containing its rule ID is returned.

See [Response schema](/api-reference/style-guide-api/response-schema.md).

### Errors

See

* [Errors](/api-reference/style-guide-api/errors.md#addrule-errors).
* [Validation & limits](/api-reference/style-guide-api/validation-and-limits.md)

### Examples

{% tabs %}
{% tab title="Example (JSON body)" %}

<details>

<summary>Request URL (on-premises)</summary>

{% code overflow="wrap" %}

```
http(s)://server_entry_point/?cmd=style_guide&access_key=<your-access-key>&collection=style guide&lang=en_US&action=addrule&patterns=["webspellchecker"]&suggestions=["WebSpellChecker"]
```

{% endcode %}

</details>

<details>

<summary>Request URL (Cloud)</summary>

{% code overflow="wrap" %}

```
https://svc.webspellchecker.net/api?cmd=style_guide&access_key=<your-access-key>&serviceid=<your-service-id>&collection=style guide&lang=en_US&action=addrule&patterns=["webspellchecker"]&suggestions=["WebSpellChecker"]
```

{% endcode %}

</details>

<details>

<summary>Request CURL (on-premises)</summary>

{% code overflow="wrap" %}

```bash
curl -G "http(s)://server_entry_point" \
  --data-urlencode 'cmd=style_guide' \
  --data-urlencode 'access_key=<your-access-key>' \
  --data-urlencode 'collection=style guide' \
  --data-urlencode 'lang=en_US' \
  --data-urlencode 'action=addrule' \
  --data-urlencode 'patterns=["webspellchecker"]' \
  --data-urlencode 'suggestions=["WebSpellChecker"]'
```

{% endcode %}

</details>

<details>

<summary>Request CURL (Cloud)</summary>

{% code overflow="wrap" %}

```bash
curl -G "https://svc.webspellchecker.net/api" \
  --data-urlencode 'cmd=style_guide' \
  --data-urlencode 'access_key=<your-access-key>' \
  --data-urlencode 'serviceid=<your-service-id>' \
  --data-urlencode 'collection=style guide' \
  --data-urlencode 'lang=en_US' \
  --data-urlencode 'action=addrule' \
  --data-urlencode 'patterns=["webspellchecker"]' \
  --data-urlencode 'suggestions=["WebSpellChecker"]'
```

{% endcode %}

</details>

***

<details>

<summary>Response</summary>

{% code overflow="wrap" %}

```json
{
    "message": "Rule added.",
    "result": [
        {
            "state": true,
            "language": "en_US",
            "id": {
                "category": "STYLE_GUIDE",
                "collection": "style guide",
                "rule": "STYLE_5933619761905272220"
            },
            "patterns": [
                "webspellchecker"
            ],
            "suggestions": [
                "WebSpellChecker"
            ],
            "description": "",
            "context_include": [],
            "context_exclude": []
        }
    ]
}
```

{% endcode %}

</details>
{% endtab %}

{% tab title="Example (XML body)" %}

<details>

<summary>Request URL (on-premises)</summary>

{% code overflow="wrap" %}

```
http(s)://server_entry_point/?cmd=style_guide&access_key=<your-access-key>&collection=style guide&lang=en_US&action=addrule&patterns=["webspellchecker"]&suggestions=["WebSpellChecker"]&format=xml
```

{% endcode %}

</details>

<details>

<summary>Request URL (Cloud)</summary>

{% code overflow="wrap" %}

```
https://svc.webspellchecker.net/api?cmd=style_guide&access_key=<your-access-key>&serviceid=<your-service-id>&collection=style guide&lang=en_US&action=addrule&patterns=["webspellchecker"]&suggestions=["WebSpellChecker"]&format=xml
```

{% endcode %}

</details>

<details>

<summary>Request CURL (on-premises)</summary>

{% code overflow="wrap" %}

```bash
curl -G "http(s)://server_entry_point" \
  --data-urlencode 'cmd=style_guide' \
  --data-urlencode 'access_key=<your-access-key>' \
  --data-urlencode 'collection=style guide' \
  --data-urlencode 'lang=en_US' \
  --data-urlencode 'action=addrule' \
  --data-urlencode 'patterns=["webspellchecker"]' \
  --data-urlencode 'suggestions=["WebSpellChecker"]' \
  --data-urlencode 'format=xml'
```

{% endcode %}

</details>

<details>

<summary>Request CURL (Cloud)</summary>

{% code overflow="wrap" %}

```bash
curl -G "https://svc.webspellchecker.net/api" \
  --data-urlencode 'cmd=style_guide' \
  --data-urlencode 'access_key=<your-access-key>' \
  --data-urlencode 'serviceid=<your-service-id>' \
  --data-urlencode 'collection=style guide' \
  --data-urlencode 'lang=en_US' \
  --data-urlencode 'action=addrule' \
  --data-urlencode 'patterns=["webspellchecker"]' \
  --data-urlencode 'suggestions=["WebSpellChecker"]' \
  --data-urlencode 'format=xml'
```

{% endcode %}

</details>

***

<details>

<summary>Response</summary>

{% code overflow="wrap" %}

```xml
<message>Rule added.</message>

<result>
	<rule>
		<state>true</state>
		<language>en_US</language>
		<id>
			<category>STYLE_GUIDE</category>
			<collection>style guide</collection>
			<rule>STYLE_5933619761905272220</rule>
		</id>
		<patterns>
			<patterns>webspellchecker</patterns>
		</patterns>
		<suggestions>
			<suggestions>WebSpellChecker</suggestions>
		</suggestions>
		<description/>
		<context_include/>
		<context_exclude/>
	</rule>
</result>
```

{% endcode %}

</details>
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.wproofreader.com/api-reference/style-guide-api/actions/add-rule-addrule.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
