Skip to main content
Required ACL: editSettings

Usage

// Initialize the client
var client = new CompositionClient(
  new CompositionConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
);

// Call the API
var response = await client.SaveRulesAsync(
  "my-compo",
  new CompositionRulesBatchParams
  {
    Requests = new List<RulesMultipleBatchRequest>
    {
      new RulesMultipleBatchRequest
      {
        Action = Enum.Parse<Action>("Upsert"),
        Body = new RulesBatchCompositionAction(
          new CompositionRule
          {
            ObjectID = "rule-with-deduplication",
            Description = "my description",
            Enabled = true,
            Conditions = new List<Condition>
            {
              new Condition
              {
                Anchoring = Enum.Parse<Anchoring>("Contains"),
                Pattern = "harry",
              },
              new Condition { SortBy = "price-low-to-high" },
            },
            Consequence = new CompositionRuleConsequence
            {
              Behavior = new CompositionBehavior(
                new CompositionInjectionBehavior
                {
                  Injection = new Injection
                  {
                    Main = new InjectionMain
                    {
                      Source = new InjectionMainSource(
                        new InjectionMainSearchSource
                        {
                          Search = new MainSearch { Index = "my-index" },
                        }
                      ),
                    },
                    InjectedItems = new List<InjectionInjectedItem>
                    {
                      new InjectionInjectedItem
                      {
                        Key = "my-unique-injected-item-key",
                        Source = new InjectedItemSource(
                          new InjectedItemSearchSource
                          {
                            Search = new InjectedItemSearch { Index = "my-index" },
                          }
                        ),
                        Position = 0,
                        Length = 3,
                      },
                    },
                    Deduplication = new Deduplication
                    {
                      Positioning = Enum.Parse<DedupPositioning>("HighestInjected"),
                    },
                  },
                }
              ),
            },
          }
        ),
      },
    },
  }
);

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

See the full API reference

For more details about input parameters and response fields.
Last modified on April 23, 2026