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",
    Behavior = new CompositionBehavior(
      new CompositionMultifeedBehavior
      {
        Multifeed = new Multifeed
        {
          Feeds = new Dictionary<string, FeedInjection>
          {
            {
              "products",
              new FeedInjection
              {
                Injection = new Injection
                {
                  Main = new InjectionMain
                  {
                    Source = new InjectionMainSource(
                      new InjectionMainSearchSource
                      {
                        Search = new MainSearch
                        {
                          Index = "products",
                          Params = new MainInjectionQueryParameters { HitsPerPage = 12 },
                        },
                      }
                    ),
                  },
                  InjectedItems = new List<InjectionInjectedItem>
                  {
                    new InjectionInjectedItem
                    {
                      Key = "featured-products",
                      Source = new InjectedItemSource(
                        new InjectedItemSearchSource
                        {
                          Search = new InjectedItemSearch
                          {
                            Index = "products",
                            Params = new BaseInjectionQueryParameters
                            {
                              Filters = "featured:true",
                            },
                          },
                        }
                      ),
                      Position = 0,
                      Length = 2,
                    },
                  },
                },
              }
            },
            {
              "articles",
              new FeedInjection
              {
                Injection = new Injection
                {
                  Main = new InjectionMain
                  {
                    Source = new InjectionMainSource(
                      new InjectionMainSearchSource
                      {
                        Search = new MainSearch
                        {
                          Index = "articles",
                          Params = new MainInjectionQueryParameters
                          {
                            HitsPerPage = 5,
                            AttributesToRetrieve = new List<string>
                            {
                              "title",
                              "excerpt",
                              "publishedAt",
                            },
                          },
                        },
                      }
                    ),
                  },
                  InjectedItems = new List<InjectionInjectedItem>
                  {
                    new InjectionInjectedItem
                    {
                      Key = "editorial-picks",
                      Source = new InjectedItemSource(
                        new InjectedItemSearchSource
                        {
                          Search = new InjectedItemSearch
                          {
                            Index = "articles",
                            Params = new BaseInjectionQueryParameters
                            {
                              Filters = "editorial_pick:true",
                            },
                          },
                        }
                      ),
                      Position = 0,
                      Length = 1,
                    },
                  },
                },
              }
            },
            {
              "videos",
              new FeedInjection
              {
                Injection = new Injection
                {
                  Main = new InjectionMain
                  {
                    Source = new InjectionMainSource(
                      new InjectionMainSearchSource
                      {
                        Search = new MainSearch
                        {
                          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 April 23, 2026