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

# Create or update a batch of Recommend Rules

> Create or update a batch of Recommend Rules

**Required ACL:** `editSettings`

Each Recommend Rule is created or updated, depending on whether a Recommend Rule with the same `objectID` already exists.
You may also specify `true` for `clearExistingRules`, in which case the batch will atomically replace all the existing Recommend Rules.

Recommend Rules are similar to Search Rules, except that the conditions and consequences apply to a [source item](/doc/guides/algolia-recommend/overview/#recommend-models) instead of a query. The main differences are the following:

* Conditions `pattern` and `anchoring` are unavailable.
* Condition `filters` triggers if the source item matches the specified filters.
* Condition `filters` accepts numeric filters.
* Consequence `params` only covers filtering parameters.
* Consequence `automaticFacetFilters` doesn't require a facet value placeholder (it tries to match the data source item's attributes instead).

## Usage

<CodeGroup>
  ```cs C# theme={"system"}
  // Initialize the client
  var client = new RecommendClient(
    new RecommendConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
  );

  // Call the API
  var response = await client.BatchRecommendRulesAsync(
    "<YOUR_INDEX_NAME>",
    Enum.Parse<RecommendModels>("RelatedProducts")
  );

  // print the response
  Console.WriteLine(response);
  ```

  ```dart Dart theme={"system"}
  // Initialize the client
  final client = RecommendClient(
      appId: 'ALGOLIA_APPLICATION_ID', apiKey: 'ALGOLIA_API_KEY');

  // Call the API
  final response = await client.batchRecommendRules(
    indexName: "<YOUR_INDEX_NAME>",
    model: RecommendModels.fromJson("related-products"),
  );

  // print the response
  print(response);
  ```

  ```go Go theme={"system"}
  // Initialize the client
  client, err := recommend.NewClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
  if err != nil {
    // The client can fail to initialize if you pass an invalid parameter.
    panic(err)
  }

  // Call the API
  response, err := client.BatchRecommendRules(client.NewApiBatchRecommendRulesRequest(
    "<YOUR_INDEX_NAME>", recommend.RecommendModels("related-products")))
  if err != nil {
    // handle the eventual error
    panic(err)
  }


  // print the response
  print(response)
  ```

  ```java Java theme={"system"}
  // Initialize the client
  RecommendClient client = new RecommendClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");

  // Call the API
  RecommendUpdatedAtResponse response = client.batchRecommendRules("<YOUR_INDEX_NAME>", RecommendModels.RELATED_PRODUCTS);

  // print the response
  System.out.println(response);
  ```

  ```js JavaScript theme={"system"}
  // Initialize the client
  const client = algoliasearch('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY').initRecommend();

  // Call the API
  const response = await client.batchRecommendRules({ indexName: 'indexName', model: 'related-products' });


  // print the response
  console.log(response);
  ```

  ```kotlin Kotlin theme={"system"}
  // Initialize the client
  val client = RecommendClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")

  // Call the API
  var response =
    client.batchRecommendRules(
      indexName = "<YOUR_INDEX_NAME>",
      model = RecommendModels.entries.first { it.value == "related-products" },
    )


  // print the response
  println(response)
  ```

  ```php PHP theme={"system"}
  // Initialize the client
  $client = RecommendClient::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');

  // Call the API
  $response = $client->batchRecommendRules(
      '<YOUR_INDEX_NAME>',
      'related-products',
  );


  // print the response
  var_dump($response);
  ```

  ```python Python theme={"system"}
  # Initialize the client
  # In an asynchronous context, you can use RecommendClient instead, which exposes the exact same methods.
  client = RecommendClientSync("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")

  # Call the API
  response = client.batch_recommend_rules(
      index_name="<YOUR_INDEX_NAME>",
      model="related-products",
  )


  # print the response
  print(response)
  ```

  ```ruby Ruby theme={"system"}
  # Initialize the client
  client = Algolia::RecommendClient.create("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")

  # Call the API
  response = client.batch_recommend_rules("<YOUR_INDEX_NAME>", "related-products")


  # print the response
  puts(response)
  ```

  ```scala Scala theme={"system"}
  // Initialize the client
  val client = RecommendClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")

  // Call the API
  val response = Await.result(
    client.batchRecommendRules(
      indexName = "<YOUR_INDEX_NAME>",
      model = RecommendModels.withName("related-products")
    ),
    Duration(100, "sec")
  )

  // print the response
  println(response)
  ```

  ```swift Swift theme={"system"}
  // Initialize the client
  let client = try RecommendClient(appID: "ALGOLIA_APPLICATION_ID", apiKey: "ALGOLIA_API_KEY")

  // Call the API
  let response = try await client.batchRecommendRules(
      indexName: "<YOUR_INDEX_NAME>",
      model: RecommendModels.relatedProducts
  )

  // print the response
  print(response)
  ```
</CodeGroup>

<Card icon="folder-code" horizontal="true" title="See the full API reference" arrow="true" href="/doc/rest-api/recommend/batch-recommend-rules">
  For more details about input parameters
  and response fields.
</Card>
