> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get rule

> Get a rule by its ID.

export const Legacy = ({title, href}) => {
  return <Note>

    This page documents an earlier version of the API client.
    For the latest version, see <a href={href}>{title}</a>.

    </Note>;
};

<Legacy title="Retrieve a rule" href="/doc/libraries/sdk/methods/search/get-rule" />

**Required ACL:** `settings`

To find the `objectID` for rules, use the [`searchRules`](/doc/libraries/sdk/v1/methods/search-rules) method.

## Examples

<CodeGroup>
  ```cs C# theme={"system"}
  Rule rule = index.GetRule("ruleID");

  // Asynchronous
  Rule rule = await index.GetRuleAsync("");
  ```

  ```go Go theme={"system"}
  rule, err := i.GetRule("ruleID")
  ```

  ```java Java theme={"system"}
  Rule rule = index.getRule("ruleID");

  // Async version
  CompletableFuture<Rule> rule = index.getRuleAsync("ruleID");
  ```

  ```js JavaScript theme={"system"}
  // Retrieve a Rule by its unique ID.
  index.getRule('ruleID').then(rule => {
    console.log(rule);
  });
  ```

  ```kotlin Kotlin theme={"system"}
  index.getRule(ObjectID("ruleID"))
  ```

  ```php PHP theme={"system"}
  $rule = $index->getRule('ruleID');
  ```

  ```python Python theme={"system"}
  # Retrieve a Rule by its unique ID.
  index.get_rule('ruleID')
  ```

  ```ruby Ruby theme={"system"}
  # Retrieve a Rule by its unique ID.
  index.get_rule('ruleID')
  ```

  ```scala Scala theme={"system"}
  val synonymRule: Future[Rule] = client.execute {
    get rule "ruleID" from "index_name"
  }
  ```

  ```swift Swift theme={"system"}
  index.getRule(withID: "ruleID") { result in
    if case .success(let response) = result {
      print("Response: \(response)")
    }
  }
  ```
</CodeGroup>

## Parameters

<ParamField body="objectID" type="string" required>
  The ID of the rule to retrieve.
</ParamField>

## Response

<ResponseField name="condition" type="list">
  [Condition](/doc/libraries/sdk/v1/methods/save-rule#param-conditions) of the rule.
</ResponseField>

<ResponseField name="consequence" type="list">
  [Consequence](/doc/libraries/sdk/v1/methods/save-rule#param-consequence) of the rule.
</ResponseField>

<ResponseField name="objectID" type="string">
  objectID of the Rule.
</ResponseField>

### Response as JSON

This section shows the JSON response returned by the API.
Each API client wraps this response in language-specific objects, so the structure may vary.
To view the response, use the `getLogs` method.
Don't rely on the order of properties—JSON objects don't preserve key order.

```jsonc JSON icon=braces theme={"system"}
{
  "objectID": "a-rule-id",
  "conditions": [{
    "pattern": "smartphone",
    "anchoring": "contains"
  }],
  "consequence": {
    "params": {
      "filters": "category = 1"
    }
  }
}
```
