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.PutCompositionAsync(
  "my-compo",
  new Composition
  {
    ObjectID = "my-compo",
    Name = "my composition",
    SortingStrategy = new Dictionary<string, string>
    {
      { "Price-asc", "products-low-to-high" },
      { "Price-desc", "products-high-to-low" },
    },
    Behavior = new CompositionBehavior(
      new CompositionMultifeedBehavior
      {
        Multifeed = new Multifeed
        {
          Feeds = new Dictionary<string, FeedInjection>
          {
            {
              "products",
              new FeedInjection
              {
                Injection = new Injection
                {
                  Main = new Main
                  {
                    Source = new CompositionSource
                    {
                      Search = new CompositionSourceSearch
                      {
                        Index = "products",
                        Params = new MainInjectionQueryParameters { HitsPerPage = 12 },
                      },
                    },
                  },
                  InjectedItems = new List<InjectedItem>
                  {
                    new InjectedItem
                    {
                      Key = "featured-products",
                      Source = new InjectedItemSource(
                        new SearchSource
                        {
                          Search = new Algolia.Search.Models.Composition.Search
                          {
                            Index = "products",
                            Params = new BaseInjectionQueryParameters
                            {
                              Filters = "featured:true",
                            },
                          },
                        }
                      ),
                      Position = 0,
                      Length = 2,
                    },
                  },
                },
              }
            },
            {
              "articles",
              new FeedInjection
              {
                Injection = new Injection
                {
                  Main = new Main
                  {
                    Source = new CompositionSource
                    {
                      Search = new CompositionSourceSearch
                      {
                        Index = "articles",
                        Params = new MainInjectionQueryParameters
                        {
                          HitsPerPage = 5,
                          AttributesToRetrieve = new List<string>
                          {
                            "title",
                            "excerpt",
                            "publishedAt",
                          },
                        },
                      },
                    },
                  },
                  InjectedItems = new List<InjectedItem>
                  {
                    new InjectedItem
                    {
                      Key = "editorial-picks",
                      Source = new InjectedItemSource(
                        new SearchSource
                        {
                          Search = new Algolia.Search.Models.Composition.Search
                          {
                            Index = "articles",
                            Params = new BaseInjectionQueryParameters
                            {
                              Filters = "editorial_pick:true",
                            },
                          },
                        }
                      ),
                      Position = 0,
                      Length = 1,
                    },
                  },
                },
              }
            },
            {
              "videos",
              new FeedInjection
              {
                Injection = new Injection
                {
                  Main = new Main
                  {
                    Source = new CompositionSource
                    {
                      Search = new CompositionSourceSearch
                      {
                        Index = "videos",
                        Params = new MainInjectionQueryParameters
                        {
                          HitsPerPage = 3,
                          AttributesToRetrieve = new List<string>
                          {
                            "title",
                            "thumbnail",
                            "duration",
                          },
                        },
                      },
                    },
                  },
                },
              }
            },
          },
          FeedsOrder = new List<string> { "products", "articles", "videos" },
        },
      }
    ),
  }
);

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

See the full API reference

For more details about input parameters and response fields.
Last modified on February 24, 2026