# A/B Testing API for Reels and Videos



This document shows you how to create an A/B test for reels and videos published on a Facebook Page.

You can run up to 50 tests at once with a minimum of 2 posts and a maximum of 4 posts per test.

## Before You Start

You need the following:

* The ID for the Facebook Page where the test is being conducted
* A Page access token requested from a user who can perform the `CREATE_CONTENT` task on the Page
* The user must grant your app the following permissions using Facebook Login:
    * `pages_manage_engagement`
    * `pages_show_list`
    * `pages_manage_posts`
    * `pages_read_engagement`
    * `pages_read_user_content`
* The IDs for the reels or videos, in draft status, that you want to compare
    * The reels or videos must be uploaded to Meta servers but not yet published

### Limitations

* An A/B test can only be created on Facebook Pages
* A reel or video that has already been published can not be used in an A/B test
* A reel or video cannot be used in multiple A/B tests

## Create an A/B Test

To create an A/B test, send a `POST` request to the `/`***`PAGE`***`/ab_tests` endpoint, where ***`PAGE`*** is the ID for the Facebook Page, and include the following parameters:

_Required_

* `control_video_id` – the ID for the video that, in the event of a tie, will be selected as the winning video
* `description` – the description for your experiment
* `experiment_video_ids` – the IDs for the videos you are comparing
* `name` – the name for your experiment
* `optimization_goal` – the goal of your experiment must be one of the following:

* `AVG_TIME_WATCHED`
* `COMMENTS`
* `IMPRESSIONS`

* `IMPRESSIONS_UNIQUE`
* `LINK_CLICKS`
* `REACTIONS`

* `REELS_PLAYS`
* `SHARES`
* `VIDEO_VIEWS_60S`

_Optional_

* `duration` – the length of time, in seconds, to run the test
    * minimum duration is 30 minutes (1800 seconds)
    * maximum duration is 1 week (604800 seconds)
* `scheduled_experiment_timestamp` – the UNIX timestamp for the time to start the test,
    * default to the time you create the test

### Example Request

_Formatted for readability. Replace bold, italics values, such as **`PAGE`**, with your values._

```curl
curl -X POST &quot;https://graph.facebook.com/v25.0/YOUR_PAGE_ID/ab_tests&quot;
     -H &quot;Content-type: application/json&quot;
     -d &#039;&#123;
           &quot;name&quot;: &quot;YOUR_TEST_NAME&quot;,
           &quot;description&quot;: &quot;YOUR_TEST_DESCRIPTION&quot;,
           &quot;optimization_goal&quot;: &quot;YOUR_OPTIMIZATION_GOAL&quot;,
           &quot;experiment_video_ids&quot;: [YOUR_EXPERIMENTAL_VIDEO_ID_1, YOUR_EXPERIMENTAL_VIDEO_ID_2],
           &quot;control_video_id&quot;: YOUR_EXPERIMENTAL_VIDEO_ID_1_AS_CONTROL
,           &quot;duration&quot;: 1800,
&#125;&#039;
```

On success your app will receive a JSON response with the ID for your A/B test.

```json
&#123;
  &quot;id&quot;: &quot;AB_TEST_ID&quot;
&#125;
```

## Get A/B Test Results

You can get data about an A/B test during the experiment or after it has concluded.

### For a specific test

To get data about a specific A/B test, send a `GET` request to the ***`/AB_TEST_ID`*** enpoint where ***`AB_TEST_ID`*** is the ID for the test you are interested in.

```json
curl -i -X GET &quot;https://graph.facebook.com/AB_TEST_ID&quot;
```

On success your app will receive a JSON response with details about the experiment such as the name, goal, IDs for the videos, published status, videos insights for each test video, and a declaration for which video performed the best. In the example here, EXPERIMENTAL_VIDEO_ID_1 performed the best.

```json
&#123;
  &quot;id&quot;: YOUR_AB_TEST_ID,
  &quot;name&quot;: &quot;YOUR_AB_TEST_NAME&quot;,
  &quot;description&quot;: &quot;YOUR_AB_TEST_DESCRIPTION&quot;,
  &quot;optimization_goal&quot;: &quot;REELS_PLAYS&quot;,
  &quot;experiment_video_ids&quot;: [YOUR_EXPERIMENTAL_VIDEO_ID_1, YOUR_EXPERIMENTAL_VIDEO_ID_2],
  &quot;control_video_id&quot;: VIDEO_ID_1_AS_CONTROL,
  &quot;publish_status&quot;: &quot;LIVE&quot;,
  &quot;creation_time&quot;: &quot;1686665092&quot;,
  &quot;updated_time&quot;: &quot;1686665092&quot;,
  &quot;scheduled_experiment_timestamp&quot;: &quot;1686665092&quot;,
  &quot;test_insights&quot;: &#123;
      &quot;timestamp&quot;: &quot;1686665092&quot;,
      &quot;videos&quot;: &#123;
          YOUR_EXPERIMENTAL_VIDEO_ID_1: &#123;
              &quot;plays&quot;: 10,
              &quot;impressions&quot;: 1,
              &quot;fan_impressions&quot;: 1,
              &quot;link_clicks&quot;: 1,
              &quot;comments&quot;: 1,
              &quot;shares&quot;: 1,
              &quot;reactions&quot;: 1,
              &quot;video_views_60s&quot;: 1,
              &quot;video_views_3s&quot;: 1,
              &quot;video_views_15s&quot;: 1,
              &quot;avg_video_views&quot;: 1,
              &quot;video_views&quot;: 1,
              &quot;instream_ads_earnings&quot;: 1,
              &quot;avg_time_watched&quot;: 1,
              &quot;video_retention_graph&quot;: &#123;
                  &quot;0&quot;: 1,
                  &quot;1&quot;: 1,
                  &quot;2&quot;: 0.5,
                  &quot;3&quot;: 0.2
              &#125;
          &#125;
          YOUR_EXPERIMENTAL_VIDEO_ID_2: &#123;
              &quot;plays&quot;: 5,
              &quot;impressions&quot;: 1,
              &quot;fan_impressions&quot;: 1,
              &quot;link_clicks&quot;: 1,
              &quot;comments&quot;: 0,
              &quot;shares&quot;: 0,
              &quot;reactions&quot;: 1,
              &quot;video_views_60s&quot;: 1,
              &quot;video_views_3s&quot;: 1,
              &quot;video_views_15s&quot;: 1,
              &quot;avg_video_views&quot;: 1,
              &quot;video_views&quot;: 1,
              &quot;instream_ads_earnings&quot;: 0,
              &quot;avg_time_watched&quot;: 1,
              &quot;video_retention_graph&quot;: &#123;
                  &quot;0&quot;: 1,
                  &quot;1&quot;: 1,
                  &quot;2&quot;: 0.5,
                  &quot;3&quot;: 0.2
              &#125;
          &#125;
      &#125;,
      &quot;declared_winning_video&quot;: YOUR_EXPERIMENTAL_VIDEO_ID_1,
  &#125;
&#125;
```

### For All Tests on a Page

To get a list of all A/B tests conducted on your Facebook Page, send a `GET` request to the `/***PAGE***/ab_tests` endpoint where ***`PAGE`*** is the ID for the Page you are interested in. Add the `since` and `unti` parameters to get data for tests run during a specific time period.

**Note:** When using the `since` and `until` parameters in your `GET` request, the date for `until` must be a date after the date for `since`. For example, if `since` is 2023-01-31, `until` must be after 2023-01-31. You can use both parameters, or one or the other. Date formats can be any of the following:

* `today`, `yesterday`

* Epoch timestamps (`1676057525`)

* dd mmm yyyy (`31 jan 2023`) or dd-mm-yyyy (`31-1-2023`)

```curl
curl -X GET &quot;https://graph.facebook.com/v25.0/PAGE/ab_tests&quot;
```

On success your app receives a JSON response with an array of test objects.

```json
&#123;
  &quot;data&quot;: [
  ... &#123;AB_TEST_RESPONSE_OBJECT_1&#125;,
  ... &#123;AB_TEST_RESPONSE_OBJECT_2&#125;,
  ... &#123;AB_TEST_RESPONSE_OBJECT_3&#125;
  ],
  &quot;cursors&quot;: &#123;
    &quot;before&quot;:&quot;QVFIUkxLWWtMb3BSQV91aF81NkN4c1RYczJZAQ0NQOHpQ&quot;,
    &quot;after&quot;:&quot;QVFIUkxLWWtMb3BSQV91aF81NkN4c1RYczJZAQ0NQOH&quot;
  &#125;
&#125;
```

## Delete an A/B test

You can delete an A/B test once it has concluded.

To delete an A/B test, send a `DELETE` request to the `AB_TEST_ID` endpoint where ID is the ID for the A/B test you want to delete.

```curl
curl -X DELETE &quot;https://graph.facebook.com/v25.0/AB_TEST_ID&quot;
```

Note that the posts in the A/B test will not be deleted.

## References

| Endpoint | Description |
| --- | --- |
| `/page/ab_tests` | Create and read A/B tests for a specific Facebook Page |
| `/AB_TEST_ID` | A specific A/B test |

## More Resources

- [Graph API Overview](https://developers.facebook.com/docs/graph-api/overview)

– Learn more about the Graph API from Meta

- [Facebook Login](https://developers.facebook.com/documentation/facebook-login) – Learn how to implement Facebook Login to ask for permissions from a person

- [Facebook Page Tasks](https://developers.facebook.com/documentation/pages-api/overview#tasks) – Learn more about the tasks a person can perform on a Facebook Page

- [Page Access Tokens](https://developers.facebook.com/documentation/facebook-login/guides/access-tokens#pagetokens) – Learn more about Page access tokens and securing API calls

- [Paginated Results](https://developers.facebook.com/docs/graph-api/results) – Learn more about paginated results returned via the Graph API

- [Permissions](https://developers.facebook.com/docs/permissions) – Learn about permissions needed to access API endpoints

- [Upload a Video](https://developers.facebook.com/documentation/video-api/getting-started) – Learn how to upload videos to the Meta servers

