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

# Schedule an A/B test

> Schedule an A/B test to be started at a later time.

**Required ACL:** `editSettings`

## Usage

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

  // Call the API
  var response = await client.ScheduleABTestAsync(
    new ScheduleABTestsRequest
    {
      EndAt = "2022-12-31T00:00:00.000Z",
      ScheduledAt = "2022-11-31T00:00:00.000Z",
      Name = "myABTest",
      Metrics = new List<CreateMetric> { new CreateMetric { Name = "myMetric" } },
      Variants = new List<AddABTestsVariant>
      {
        new AddABTestsVariant(new AbTestsVariant { Index = "AB_TEST_1", TrafficPercentage = 30 }),
        new AddABTestsVariant(new AbTestsVariant { Index = "AB_TEST_2", TrafficPercentage = 50 }),
      },
    }
  );

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

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

  // Call the API
  final response = await client.scheduleABTest(
    scheduleABTestsRequest: ScheduleABTestsRequest(
      endAt: "2022-12-31T00:00:00.000Z",
      scheduledAt: "2022-11-31T00:00:00.000Z",
      name: "myABTest",
      metrics: [
        CreateMetric(
          name: "myMetric",
        ),
      ],
      variants: [
        AbTestsVariant(
          index: "AB_TEST_1",
          trafficPercentage: 30,
        ),
        AbTestsVariant(
          index: "AB_TEST_2",
          trafficPercentage: 50,
        ),
      ],
    ),
  );

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

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

  // Call the API
  response, err := client.ScheduleABTest(client.NewApiScheduleABTestRequest(
    abtestingV3.NewEmptyScheduleABTestsRequest().
      SetEndAt("2022-12-31T00:00:00.000Z").
      SetScheduledAt("2022-11-31T00:00:00.000Z").
      SetName("myABTest").
      SetMetrics(
        []abtestingV3.CreateMetric{*abtestingV3.NewEmptyCreateMetric().SetName("myMetric")}).
      SetVariants(
        []abtestingV3.AddABTestsVariant{*abtestingV3.AbTestsVariantAsAddABTestsVariant(
          abtestingV3.NewEmptyAbTestsVariant().SetIndex("AB_TEST_1").SetTrafficPercentage(30)), *abtestingV3.AbTestsVariantAsAddABTestsVariant(
          abtestingV3.NewEmptyAbTestsVariant().SetIndex("AB_TEST_2").SetTrafficPercentage(50))}),
  ))
  if err != nil {
    // handle the eventual error
    panic(err)
  }


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

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

  // Call the API
  ScheduleABTestResponse response = client.scheduleABTest(
    new ScheduleABTestsRequest()
      .setEndAt("2022-12-31T00:00:00.000Z")
      .setScheduledAt("2022-11-31T00:00:00.000Z")
      .setName("myABTest")
      .setMetrics(Arrays.asList(new CreateMetric().setName("myMetric")))
      .setVariants(
        Arrays.asList(
          new AbTestsVariant().setIndex("AB_TEST_1").setTrafficPercentage(30),
          new AbTestsVariant().setIndex("AB_TEST_2").setTrafficPercentage(50)
        )
      )
  );

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

  ```js JavaScript theme={"system"}
  // Initialize the client
  // Replace 'us' with your Algolia Application Region
  const client = algoliasearch('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY').initAbtestingV3({ region: 'us' });

  // Call the API
  const response = await client.scheduleABTest({
    endAt: '2022-12-31T00:00:00.000Z',
    scheduledAt: '2022-11-31T00:00:00.000Z',
    name: 'myABTest',
    metrics: [{ name: 'myMetric' }],
    variants: [
      { index: 'AB_TEST_1', trafficPercentage: 30 },
      { index: 'AB_TEST_2', trafficPercentage: 50 },
    ],
  });


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

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

  // Call the API
  var response =
    client.scheduleABTest(
      scheduleABTestsRequest =
        ScheduleABTestsRequest(
          endAt = "2022-12-31T00:00:00.000Z",
          scheduledAt = "2022-11-31T00:00:00.000Z",
          name = "myABTest",
          metrics = listOf(CreateMetric(name = "myMetric")),
          variants =
            listOf(
              AbTestsVariant(index = "AB_TEST_1", trafficPercentage = 30),
              AbTestsVariant(index = "AB_TEST_2", trafficPercentage = 50),
            ),
        )
    )


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

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

  // Call the API
  $response = $client->scheduleABTest(
      ['endAt' => '2022-12-31T00:00:00.000Z',
          'scheduledAt' => '2022-11-31T00:00:00.000Z',
          'name' => 'myABTest',
          'metrics' => [
              ['name' => 'myMetric',
              ],
          ],
          'variants' => [
              ['index' => 'AB_TEST_1',
                  'trafficPercentage' => 30,
              ],

              ['index' => 'AB_TEST_2',
                  'trafficPercentage' => 50,
              ],
          ],
      ],
  );


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

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

  # Call the API
  response = client.schedule_ab_test(
      schedule_ab_tests_request={
          "endAt": "2022-12-31T00:00:00.000Z",
          "scheduledAt": "2022-11-31T00:00:00.000Z",
          "name": "myABTest",
          "metrics": [
              {
                  "name": "myMetric",
              },
          ],
          "variants": [
              {
                  "index": "AB_TEST_1",
                  "trafficPercentage": 30,
              },
              {
                  "index": "AB_TEST_2",
                  "trafficPercentage": 50,
              },
          ],
      },
  )


  # print the response
  print(response)
  ```

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

  # Call the API
  response = client.schedule_ab_test(
    Algolia::AbtestingV3::ScheduleABTestsRequest.new(
      end_at: "2022-12-31T00:00:00.000Z",
      scheduled_at: "2022-11-31T00:00:00.000Z",
      name: "myABTest",
      metrics: [Algolia::AbtestingV3::CreateMetric.new(name: "myMetric")],
      variants: [
        Algolia::AbtestingV3::AbTestsVariant.new(index: "AB_TEST_1", traffic_percentage: 30),
        Algolia::AbtestingV3::AbTestsVariant.new(index: "AB_TEST_2", traffic_percentage: 50)
      ]
    )
  )


  # print the response
  puts(response)
  ```

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

  // Call the API
  val response = Await.result(
    client.scheduleABTest(
      scheduleABTestsRequest = ScheduleABTestsRequest(
        endAt = "2022-12-31T00:00:00.000Z",
        scheduledAt = "2022-11-31T00:00:00.000Z",
        name = "myABTest",
        metrics = Seq(
          CreateMetric(
            name = "myMetric"
          )
        ),
        variants = Seq(
          AbTestsVariant(
            index = "AB_TEST_1",
            trafficPercentage = 30
          ),
          AbTestsVariant(
            index = "AB_TEST_2",
            trafficPercentage = 50
          )
        )
      )
    ),
    Duration(100, "sec")
  )

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

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

  // Call the API
  let response = try await client.scheduleABTest(scheduleABTestsRequest: AbtestingV3ScheduleABTestsRequest(
      name: "myABTest",
      variants: [
          AbtestingV3AddABTestsVariant.abtestingV3AbTestsVariant(AbtestingV3AbTestsVariant(
              index: "AB_TEST_1",
              trafficPercentage: 30
          )),
          AbtestingV3AddABTestsVariant.abtestingV3AbTestsVariant(AbtestingV3AbTestsVariant(
              index: "AB_TEST_2",
              trafficPercentage: 50
          )),
      ],
      metrics: [CreateMetric(name: "myMetric")],
      scheduledAt: "2022-11-31T00:00:00.000Z",
      endAt: "2022-12-31T00:00:00.000Z"
  ))

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

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