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

# Apply a variant's captured settings to the control index

> Applies the captured settings of the given variant to the control index.

The settings must first be captured with the `saveVariantSettings` operation. To revert previously applied settings on the control index, use this operation with the control variant (variant 1).

Settings can be applied up to 14 days after the A/B test ends, and reverted up to 15 days after. Later requests return `400`.

Each set of captured settings can only be applied once, and settings that were reverted can't be applied again. Both cases return `400`.

The control index must not be in use by an active A/B test. Otherwise, the request returns `422`.

**Required ACL:** `analytics`, `editSettings`


## OpenAPI

````yaml specs/abtesting-v3.yml post /3/abtests/{id}/settings/{variantId}/apply
openapi: 3.1.0
info:
  title: A/B Testing API
  summary: >-
    The Algolia A/B Testing API lets you manage your Algolia A/B tests to
    optimize your search experience
  description: >
    ## Base URLs


    Base URLs for the A/B testing API:


    - `https://analytics.us.algolia.com`

    - `https://analytics.de.algolia.com`

    - `https://analytics.algolia.com` (routes requests to the closest of the
    above servers, based on your geographical location)


    Use the URL that matches your [analytics
    region](https://dashboard.algolia.com/account/infrastructure/analytics).


    **All requests must use HTTPS.**


    ## Availability and authentication


    Access to the A/B testing API is available as part of the [Premium or
    Elevate plans](https://www.algolia.com/pricing).


    Add these headers to authenticate requests:


    - `x-algolia-application-id`. Your Algolia application ID.

    - `x-algolia-api-key`. An API key with the necessary permissions to make the
    request.
      The required access control list (ACL) to make a request is listed in each endpoint's reference.

    You can find your application ID and API key in the [Algolia
    dashboard](https://dashboard.algolia.com/account/api-keys).


    ## Rate limits


    You can make up to **100 requests per minute per app** to the A/B testing
    API.

    The response includes headers with information about the limits.


    ## Parameters


    Query parameters must be
    [URL-encoded](https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding).

    Non-ASCII characters must be UTF-8 encoded.

    Plus characters (`+`) are interpreted as spaces.


    ## Response status and errors


    The A/B testing API returns JSON responses.

    Since JSON doesn't guarantee any specific ordering, don't rely on the order
    of attributes in the API response.


    Successful responses return `2xx` statuses. Client errors return `4xx`
    statuses. Server errors return `5xx` statuses.

    Error responses have a `message` property with more information.


    ## Version


    The current version of the A/B Testing API is version 3, indicated by the
    `/3/` in each endpoint's URL.
  version: 3.0.0
servers:
  - url: https://analytics.{region}.algolia.com
    variables:
      region:
        enum:
          - us
          - de
        default: us
  - url: https://analytics.algolia.com
security:
  - appId: []
    apiKey: []
tags:
  - name: abtest
    x-displayName: A/B testing
    description: >
      Manage A/B tests.


      A/B tests are configurations one or more indices, usually your production
      index and an index with different settings that you want to test.
externalDocs:
  url: https://www.algolia.com/doc/guides/ab-testing/what-is-ab-testing
  description: A/B testing.
paths:
  /3/abtests/{id}/settings/{variantId}/apply:
    post:
      tags:
        - abtest
      summary: Apply a variant's captured settings to the control index
      description: >
        Applies the captured settings of the given variant to the control index.


        The settings must first be captured with the `saveVariantSettings`
        operation. To revert previously applied settings on the control index,
        use this operation with the control variant (variant 1).


        Settings can be applied up to 14 days after the A/B test ends, and
        reverted up to 15 days after. Later requests return `400`.


        Each set of captured settings can only be applied once, and settings
        that were reverted can't be applied again. Both cases return `400`.


        The control index must not be in use by an active A/B test. Otherwise,
        the request returns `422`.
      operationId: applyVariantSettings
      parameters:
        - $ref: '#/components/parameters/ID'
        - $ref: '#/components/parameters/VariantID'
      responses:
        '200':
          description: OK
          headers:
            x-ratelimit-limit:
              $ref: '#/components/headers/x-ratelimit-limit'
            x-ratelimit-remaining:
              $ref: '#/components/headers/x-ratelimit-remaining'
            x-ratelimit-reset:
              $ref: '#/components/headers/x-ratelimit-reset'
        '400':
          $ref: '#/components/responses/BadRequest'
        '402':
          $ref: '#/components/responses/FeatureNotEnabled'
        '403':
          $ref: '#/components/responses/MethodNotAllowed'
        '404':
          description: A/B test, variant, or index not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorBase'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
      x-codeSamples:
        - lang: csharp
          label: C#
          source: |-
            // Initialize the client
            var client = new AbtestingV3Client(
              new AbtestingV3Config(
                "ALGOLIA_APPLICATION_ID",
                "ALGOLIA_API_KEY",
                "ALGOLIA_APPLICATION_REGION"
              )
            );

            // Call the API
            await client.ApplyVariantSettingsAsync(42, 2);
        - lang: dart
          label: Dart
          source: |-
            // Initialize the client
            final client = AbtestingV3Client(
                appId: 'ALGOLIA_APPLICATION_ID',
                apiKey: 'ALGOLIA_API_KEY',
                region: 'ALGOLIA_APPLICATION_REGION');

            // Call the API
            await client.applyVariantSettings(
              id: 42,
              variantId: 2,
            );
        - lang: go
          label: Go
          source: >-
            // 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

            err =
            client.ApplyVariantSettings(client.NewApiApplyVariantSettingsRequest(
              42, 2))
            if err != nil {
              // handle the eventual error
              panic(err)
            }
        - lang: java
          label: Java
          source: >-
            // Initialize the client

            AbtestingV3Client client = new
            AbtestingV3Client("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY",
            "ALGOLIA_APPLICATION_REGION");


            // Call the API

            client.applyVariantSettings(42, 2);
        - lang: javascript
          label: JavaScript
          source: >-
            // 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

            await client.applyVariantSettings({ id: 42, variantId: 2 });
        - lang: kotlin
          label: Kotlin
          source: |-
            // Initialize the client
            val client =
              AbtestingV3Client(
                appId = "ALGOLIA_APPLICATION_ID",
                apiKey = "ALGOLIA_API_KEY",
                region = "ALGOLIA_APPLICATION_REGION",
              )

            // Call the API
            client.applyVariantSettings(id = 42, variantId = 2)
        - lang: php
          label: PHP
          source: >-
            // Initialize the client

            $client = AbtestingV3Client::create('ALGOLIA_APPLICATION_ID',
            'ALGOLIA_API_KEY', 'ALGOLIA_APPLICATION_REGION');


            // Call the API

            $client->applyVariantSettings(
                42,
                2,
            );
        - lang: python
          label: Python
          source: >-
            # 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

            client.apply_variant_settings(
                id=42,
                variant_id=2,
            )
        - lang: ruby
          label: Ruby
          source: >-
            # Initialize the client

            client = Algolia::AbtestingV3Client.create("ALGOLIA_APPLICATION_ID",
            "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION")


            # Call the API

            client.apply_variant_settings(42, 2)
        - lang: scala
          label: Scala
          source: |-
            // Initialize the client
            val client = AbtestingV3Client(
              appId = "ALGOLIA_APPLICATION_ID",
              apiKey = "ALGOLIA_API_KEY",
              region = Option("ALGOLIA_APPLICATION_REGION")
            )

            // Call the API
            Await.result(
              client.applyVariantSettings(
                id = 42,
                variantId = 2
              ),
              Duration(100, "sec")
            )
        - lang: swift
          label: Swift
          source: >-
            // Initialize the client

            let client = try AbtestingV3Client(appID: "ALGOLIA_APPLICATION_ID",
            apiKey: "ALGOLIA_API_KEY", region: .us)


            // Call the API

            try await client.applyVariantSettings(id: 42, variantId: 2)
        - lang: cURL
          label: curl
          source: |-
            curl --request POST \
              --url https://analytics.us.algolia.com/3/abtests/224/settings/2/apply \
              --header 'x-algolia-api-key: ALGOLIA_API_KEY' \
              --header 'x-algolia-application-id: ALGOLIA_APPLICATION_ID'
components:
  parameters:
    ID:
      in: path
      name: id
      description: Unique A/B test identifier.
      required: true
      schema:
        $ref: '#/components/schemas/abTestID'
    VariantID:
      in: path
      name: variantId
      description: One-based index of the A/B test variant. The control is variant 1.
      required: true
      schema:
        type: integer
        minimum: 1
        example: 2
  headers:
    x-ratelimit-limit:
      description: Number of allowed requests per one minute.
      example: 100
      schema:
        type: integer
    x-ratelimit-remaining:
      description: Number of remaining requests in the current period.
      example: 99
      schema:
        type: integer
    x-ratelimit-reset:
      description: >-
        Timestamp when the rate limit will reset, measured in seconds since the
        Unix epoch.
      example: 1710682486
      schema:
        type: integer
  responses:
    BadRequest:
      description: Bad request or request arguments.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBase'
    FeatureNotEnabled:
      description: This feature is not enabled on your Algolia account.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBase'
    MethodNotAllowed:
      description: Method not allowed with this API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBase'
    UnprocessableEntity:
      description: Unprocessable Entity.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBase'
  schemas:
    ErrorBase:
      description: Error.
      type: object
      x-keep-model: true
      additionalProperties: true
      properties:
        message:
          type: string
          example: Invalid Application-Id or API-Key
    abTestID:
      type: integer
      description: Unique A/B test identifier.
      example: 224
  securitySchemes:
    appId:
      type: apiKey
      in: header
      name: x-algolia-application-id
      description: Your Algolia application ID.
    apiKey:
      type: apiKey
      in: header
      name: x-algolia-api-key
      description: >
        Your Algolia API key with the necessary permissions to make the request.

        Permissions are controlled through access control lists (ACL) and access
        restrictions.

        The required ACL to make a request is listed in each endpoint's
        reference.

````