# Retrieve running A/B tests

A single page may have multiple A/B tests active for it at the same time. This means that the page has a version for every combination of variants between the A/B tests. As every new version of the page is essentially a new entry you need to cache, using only the **running** or **active** A/B tests for a certain page reduces the amount of entries we need to cache, as the **non-active** ones aren't relevant.

## Request

Retrieving all the running A/B tests can be done via the following **GET** request to FHR:

`${base_url}/config/running/ab-tests`

Where `${base_url}` will be provided to you by the **technical consultant** appointed to you. This URL is different then the one used for **FHR** **queries**, though the same authentication credentials can be used.

### Regex Compatibility

The default RegExes found in the response are compatible with Java. In order to get RegExes compatible with a certain language you will need to add the header **X-Request-Language** with the language you want as the value.

{% tabs %}
{% tab title="Java" %}
X-Request-Language: java
{% endtab %}

{% tab title="Node.js" %}
X-Request-Language: nodejs
{% endtab %}

{% tab title="PHP" %}
X-Request-Language: php
{% endtab %}
{% endtabs %}

## Response

If your request is successful you would receive a **JSON** response like the following:

{% tabs %}
{% tab title="Response type" %}

```javascript
[
    {
      "id": String,
      "variations":[
         {
            "id": String,
            "weight":int
         }
      ],
      "filters": Map<String, List<String>>
    }
]
```

{% endtab %}

{% tab title="Example" %}

```javascript
[
    {
      "id": "318ccefa-bb47-4589-945d-ccc0c4f32280",
      "variations":[
         {
            "id": "06c26226-25bc-4054-b622-62fcbe4db3fd",
            "weight":50
         },
         {
            "id": "4f4bdc48-a586-4670-985b-b8de7d028773",
            "weight":50
         },
      ],
      "filters": {
         "fh_location": ["//catalog01/en_GB/color>{black}.*"],
      }
    },
    {
      "id": "bc616167-c12a-4277-9de3-e37ba66e2dd9",
      "variations":[
         {
            "id": "d541195a-b2e4-4135-8fee-58d335a0dc43",
            "weight":30
         },
         {
            "id": "e014178b-3ce5-404d-960f-d6edc30ed790",
            "weight":30
         },
         {
            "id": "cd84c34e-a58c-43b7-bf7d-3ccb90ed3fcc",
            "weight":40
         },
      ],
      "filters": {
         "fh_location": ["//catalog01/en_GB/.*spotlight>{new}.*"],
      }
    }
]
```

{% endtab %}
{% endtabs %}

The response will be a list of objects, each populated with:

* `id` - the id of the A/B test.
* `variations` - a list of objects consisting of:
  * `id` - the id of the variation.
  * `weight` - the weight distribution for the given variation (percentage).
* `filters` - an object or map where:
  * **key** is a property used when making the **FHR query** - most notably **fh\_location**
  * **value** is a list of RegEx strings used to filter out pages that don't have the given A/B test active on them

## Caching

Running A/B tests are relatively static, they only get updated when you add or amend an A/B test and publish the changes in **Merchandising Studio.** Because of this, the **running AB tests response** is highly cacheable. In order to ensure your service is both performant and up to date we suggest refreshing the **running AB tests response** every 5 minutes.

{% hint style="info" %}
Everything mentioned in this section is also covered via the **SDK.**
{% endhint %}

Once you have the **running A/B tests** you can move onto filtering.

{% content-ref url="filter-out-irrelevant-a-b-tests" %}
[filter-out-irrelevant-a-b-tests](https://crownpeak.gitbook.io/product-discovery/a-b-testing-for-fhr/integration-steps-for-a-caching-solution/manual-a-b-tests-integration/filter-out-irrelevant-a-b-tests)
{% endcontent-ref %}
