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

# Batch action to multiple compositions

> Adds, updates, or deletes compositions with a single API request.

**Required ACL:** `editSettings`

## Usage

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

  // Call the API
  var response = await client.MultipleBatchAsync(
    new BatchParams
    {
      Requests = new List<MultipleBatchRequest>
      {
        new MultipleBatchRequest
        {
          Action = Enum.Parse<Action>("Upsert"),
          Body = new BatchCompositionAction(
            new Composition
            {
              ObjectID = "my-compo",
              Name = "my composition",
              Behavior = new CompositionBehavior(
                new CompositionInjectionBehavior
                {
                  Injection = new Injection
                  {
                    Main = new InjectionMain
                    {
                      Source = new InjectionMainSource(
                        new InjectionMainSearchSource
                        {
                          Search = new MainSearch { Index = "foo" },
                        }
                      ),
                    },
                    InjectedItems = new List<InjectionInjectedItem>
                    {
                      new InjectionInjectedItem
                      {
                        Key = "my-unique-injected-item-key",
                        Source = new InjectedItemSource(
                          new InjectedItemSearchSource
                          {
                            Search = new InjectedItemSearch { Index = "foo" },
                          }
                        ),
                        Position = 2,
                        Length = 1,
                      },
                    },
                    Deduplication = new Deduplication
                    {
                      Positioning = Enum.Parse<DedupPositioning>("Highest"),
                    },
                  },
                }
              ),
            }
          ),
        },
      },
    }
  );

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

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

  // Call the API
  final response = await client.multipleBatch(
    batchParams: BatchParams(
      requests: [
        MultipleBatchRequest(
          action: Action.fromJson("upsert"),
          body: Composition(
            objectID: "my-compo",
            name: "my composition",
            behavior: CompositionInjectionBehavior(
              injection: Injection(
                main: InjectionMain(
                  source: InjectionMainSearchSource(
                    search: MainSearch(
                      index: "foo",
                    ),
                  ),
                ),
                injectedItems: [
                  InjectionInjectedItem(
                    key: "my-unique-injected-item-key",
                    source: InjectedItemSearchSource(
                      search: InjectedItemSearch(
                        index: "foo",
                      ),
                    ),
                    position: 2,
                    length: 1,
                  ),
                ],
                deduplication: Deduplication(
                  positioning: DedupPositioning.fromJson("highest"),
                ),
              ),
            ),
          ),
        ),
      ],
    ),
  );

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

  ```go Go theme={"system"}
  // Initialize the client
  client, err := composition.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.MultipleBatch(client.NewApiMultipleBatchRequest(

    composition.NewEmptyBatchParams().SetRequests(
      []composition.MultipleBatchRequest{
        *composition.NewEmptyMultipleBatchRequest().SetAction(composition.Action("upsert")).SetBody(composition.CompositionAsBatchCompositionAction(
          composition.NewEmptyComposition().SetObjectID("my-compo").SetName("my composition").SetBehavior(composition.CompositionInjectionBehaviorAsCompositionBehavior(
            composition.NewEmptyCompositionInjectionBehavior().SetInjection(
              composition.NewEmptyInjection().SetMain(
                composition.NewEmptyInjectionMain().SetSource(composition.InjectionMainSearchSourceAsInjectionMainSource(
                  composition.NewEmptyInjectionMainSearchSource().SetSearch(
                    composition.NewEmptyMainSearch().SetIndex("foo"))))).SetInjectedItems(
                []composition.InjectionInjectedItem{*composition.NewEmptyInjectionInjectedItem().SetKey("my-unique-injected-item-key").SetSource(composition.InjectedItemSearchSourceAsInjectedItemSource(
                  composition.NewEmptyInjectedItemSearchSource().SetSearch(
                    composition.NewEmptyInjectedItemSearch().SetIndex("foo")))).SetPosition(2).SetLength(1)}).SetDeduplication(
                composition.NewEmptyDeduplication().SetPositioning(composition.DedupPositioning("highest")))))))),
      }),
  ))
  if err != nil {
    // handle the eventual error
    panic(err)
  }


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

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

  // Call the API
  MultipleBatchResponse response = client.multipleBatch(
    new BatchParams().setRequests(
      Arrays.asList(
        new MultipleBatchRequest().setAction(Action.UPSERT).setBody(
          new Composition()
            .setObjectID("my-compo")
            .setName("my composition")
            .setBehavior(
              new CompositionInjectionBehavior().setInjection(
                new Injection()
                  .setMain(new InjectionMain().setSource(new InjectionMainSearchSource().setSearch(new MainSearch().setIndex("foo"))))
                  .setInjectedItems(
                    Arrays.asList(
                      new InjectionInjectedItem()
                        .setKey("my-unique-injected-item-key")
                        .setSource(new InjectedItemSearchSource().setSearch(new InjectedItemSearch().setIndex("foo")))
                        .setPosition(2)
                        .setLength(1)
                    )
                  )
                  .setDeduplication(new Deduplication().setPositioning(DedupPositioning.HIGHEST))
              )
            )
        )
      )
    )
  );

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

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

  // Call the API
  const response = await client.multipleBatch({
    requests: [
      {
        action: 'upsert',
        body: {
          objectID: 'my-compo',
          name: 'my composition',
          behavior: {
            injection: {
              main: { source: { search: { index: 'foo' } } },
              injectedItems: [
                { key: 'my-unique-injected-item-key', source: { search: { index: 'foo' } }, position: 2, length: 1 },
              ],
              deduplication: { positioning: 'highest' },
            },
          },
        },
      },
    ],
  });


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

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

  // Call the API
  var response =
    client.multipleBatch(
      batchParams =
        BatchParams(
          requests =
            listOf(
              MultipleBatchRequest(
                action = Action.entries.first { it.value == "upsert" },
                body =
                  Composition(
                    objectID = "foo",
                    name = "my first composition",
                    behavior =
                      CompositionInjectionBehavior(
                        injection =
                          Injection(
                            main =
                              InjectionMain(
                                source =
                                  InjectionMainSearchSource(search = MainSearch(index = "bar"))
                              )
                          )
                      ),
                  ),
              ),
              MultipleBatchRequest(
                action = Action.entries.first { it.value == "delete" },
                body = DeleteCompositionAction(objectID = "baz"),
              ),
            )
        )
    )


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

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

  // Call the API
  $response = $client->multipleBatch(
      ['requests' => [
          ['action' => 'upsert',
              'body' => ['objectID' => 'my-compo',
                  'name' => 'my composition',
                  'behavior' => ['injection' => ['main' => ['source' => ['search' => ['index' => 'foo',
                  ],
                  ],
                  ],
                      'injectedItems' => [
                          ['key' => 'my-unique-injected-item-key',
                              'source' => ['search' => ['index' => 'foo',
                              ],
                              ],
                              'position' => 2,
                              'length' => 1,
                          ],
                      ],
                      'deduplication' => ['positioning' => 'highest',
                      ],
                  ],
                  ],
              ],
          ],
      ],
      ],
  );


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

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

  # Call the API
  response = client.multiple_batch(
      batch_params={
          "requests": [
              {
                  "action": "upsert",
                  "body": {
                      "objectID": "my-compo",
                      "name": "my composition",
                      "behavior": {
                          "injection": {
                              "main": {
                                  "source": {
                                      "search": {
                                          "index": "foo",
                                      },
                                  },
                              },
                              "injectedItems": [
                                  {
                                      "key": "my-unique-injected-item-key",
                                      "source": {
                                          "search": {
                                              "index": "foo",
                                          },
                                      },
                                      "position": 2,
                                      "length": 1,
                                  },
                              ],
                              "deduplication": {
                                  "positioning": "highest",
                              },
                          },
                      },
                  },
              },
          ],
      },
  )


  # print the response
  print(response)
  ```

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

  # Call the API
  response = client.multiple_batch(
    Algolia::Composition::BatchParams.new(
      requests: [
        Algolia::Composition::MultipleBatchRequest.new(
          action: "upsert",
          body: Algolia::Composition::Composition.new(
            algolia_object_id: "my-compo",
            name: "my composition",
            behavior: Algolia::Composition::CompositionInjectionBehavior.new(
              injection: Algolia::Composition::Injection.new(
                main: Algolia::Composition::InjectionMain.new(
                  source: Algolia::Composition::InjectionMainSearchSource.new(
                    search: Algolia::Composition::MainSearch.new(index: "foo")
                  )
                ),
                injected_items: [
                  Algolia::Composition::InjectionInjectedItem.new(
                    key: "my-unique-injected-item-key",
                    source: Algolia::Composition::InjectedItemSearchSource.new(
                      search: Algolia::Composition::InjectedItemSearch.new(index: "foo")
                    ),
                    position: 2,
                    length: 1
                  )
                ],
                deduplication: Algolia::Composition::Deduplication.new(positioning: "highest")
              )
            )
          )
        )
      ]
    )
  )


  # print the response
  puts(response)
  ```

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

  // Call the API
  val response = Await.result(
    client.multipleBatch(
      batchParams = BatchParams(
        requests = Seq(
          MultipleBatchRequest(
            action = Action.withName("upsert"),
            body = Composition(
              objectID = "my-compo",
              name = "my composition",
              behavior = CompositionInjectionBehavior(
                injection = Injection(
                  main = InjectionMain(
                    source = Some(
                      InjectionMainSearchSource(
                        search = MainSearch(
                          index = "foo"
                        )
                      )
                    )
                  ),
                  injectedItems = Some(
                    Seq(
                      InjectionInjectedItem(
                        key = "my-unique-injected-item-key",
                        source = InjectedItemSearchSource(
                          search = InjectedItemSearch(
                            index = "foo"
                          )
                        ),
                        position = 2,
                        length = 1
                      )
                    )
                  ),
                  deduplication = Some(
                    Deduplication(
                      positioning = DedupPositioning.withName("highest")
                    )
                  )
                )
              )
            )
          )
        )
      )
    ),
    Duration(100, "sec")
  )

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

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

  // Call the API
  let response = try await client
      .multipleBatch(batchParams: CompositionBatchParams(requests: [CompositionMultipleBatchRequest(
          action: CompositionAction.upsert,
          body: BatchCompositionAction.composition(Composition(
              objectID: "my-compo",
              name: "my composition",
              behavior: CompositionBehavior
                  .compositionInjectionBehavior(CompositionInjectionBehavior(injection: Injection(
                      main: InjectionMain(source: InjectionMainSource
                          .injectionMainSearchSource(
                              InjectionMainSearchSource(search: MainSearch(index: "foo"))
                          )),
                      injectedItems: [InjectionInjectedItem(
                          key: "my-unique-injected-item-key",
                          source: InjectedItemSource
                              .injectedItemSearchSource(
                                  InjectedItemSearchSource(search: InjectedItemSearch(index: "foo"))
                              ),
                          position: 2,
                          length: 1
                      )],
                      deduplication: Deduplication(positioning: DedupPositioning.highest)
                  )))
          ))
      )]))

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

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